/[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.31 Revision 1.80
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.31 2006/12/03 18:41:25 betelgeuse Exp $ 9# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.80 2007/04/26 23:32:12 caster Exp $
10 10
11 11
12# ----------------------------------------------------------------------------- 12# -----------------------------------------------------------------------------
13# @eclass-begin 13# @eclass-begin
14# @eclass-shortdesc Java Utility eclass 14# @eclass-shortdesc Java Utility eclass
24# 24#
25# ----------------------------------------------------------------------------- 25# -----------------------------------------------------------------------------
26 26
27inherit eutils versionator multilib 27inherit eutils versionator multilib
28 28
29IUSE="elibc_FreeBSD"
30
29# ----------------------------------------------------------------------------- 31# -----------------------------------------------------------------------------
30# @section-begin variables 32# @section-begin variables
31# @section-title Variables 33# @section-title Variables
32# 34#
33# Summary of variables which control the behavior of building Java packges. 35# Summary of variables which control the behavior of building Java packges.
34# ----------------------------------------------------------------------------- 36# -----------------------------------------------------------------------------
35 37
36# Make sure we use java-config-2 38# Make sure we use java-config-2
37export WANT_JAVA_CONFIG="2" 39export WANT_JAVA_CONFIG="2"
38 40
39# TODO document 41# -----------------------------------------------------------------------------
42# @variable-external WANT_ANT_TASKS
43# @variable-default ""
44#
45# An $IFS separated list of ant tasks.
46# Ebuild can specify this variable before inheriting java-ant-2 eclass to
47# determine ANT_TASKS it needs. They will be automatically translated to
48# DEPEND variable and ANT_TASKS variable. JAVA_PKG_FORCE_ANT_TASKS can override
49# ANT_TASKS set by WANT_ANT_TASKS, but not the DEPEND due to caching.
50# Ebuilds that need to depend conditionally on certain tasks and specify them
51# differently for different eant calls can't use this simplified approach.
52# You also cannot specify version or anything else than ant-*.
53#
54# @example WANT_ANT_TASKS="ant-junit ant-trax"
55#
56# @seealso JAVA_PKG_FORCE_ANT_TASKS
57# -----------------------------------------------------------------------------
58#WANT_ANT_TASKS
59
60# -----------------------------------------------------------------------------
61# @variable-internal JAVA_PKG_PORTAGE_DEP
62#
63# The version of portage we need to function properly. At this moment it's
64# portage with phase hooks support.
65# -----------------------------------------------------------------------------
40JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1" 66JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1"
41 67
42# ----------------------------------------------------------------------------- 68# -----------------------------------------------------------------------------
43# @variable-internal JAVA_PKG_E_DEPEND 69# @variable-internal JAVA_PKG_E_DEPEND
44# 70#
45# 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
46# 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. We also need a recent version
47# portage, that includes phase hooks. 73# portage, that includes phase hooks.
48# ----------------------------------------------------------------------------- 74# -----------------------------------------------------------------------------
49JAVA_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.31 ${JAVA_PKG_PORTAGE_DEP}"
50 76
51# ----------------------------------------------------------------------------- 77# -----------------------------------------------------------------------------
52# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 78# @variable-external JAVA_PKG_ALLOW_VM_CHANGE
53# @variable-default yes 79# @variable-default yes
54# 80#
128# @note This should only be used internally or for testing. 154# @note This should only be used internally or for testing.
129# @example Use jikes and javac, in that order 155# @example Use jikes and javac, in that order
130# JAVA_PKG_FORCE_COMPILER="jikes javac" 156# JAVA_PKG_FORCE_COMPILER="jikes javac"
131# ----------------------------------------------------------------------------- 157# -----------------------------------------------------------------------------
132 158
159# -----------------------------------------------------------------------------
160# @variable-external JAVA_PKG_FORCE_ANT_TASKS
161#
162# An $IFS separated list of ant tasks. Can be set in environment before calling
163# emerge/ebuild to override variables set in ebuild, mainly for testing before
164# putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in
165# eant() call, not the dependencies specified in WANT_ANT_TASKS.
166#
167# @example JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \
168# ebuild foo.ebuild compile
169#
170# @seealso WANT_ANT_TASKS
171# -----------------------------------------------------------------------------
172
133# TODO document me 173# TODO document me
134JAVA_PKG_QA_VIOLATIONS=0 174JAVA_PKG_QA_VIOLATIONS=0
135 175
136# ----------------------------------------------------------------------------- 176# -----------------------------------------------------------------------------
137# @section-end variables 177# @section-end variables
144# 184#
145# These are used to install Java-related things, such as jars, Javadocs, JNI 185# These are used to install Java-related things, such as jars, Javadocs, JNI
146# libraries, etc. 186# libraries, etc.
147# ----------------------------------------------------------------------------- 187# -----------------------------------------------------------------------------
148 188
189# -----------------------------------------------------------------------------
190# @ebuild-function java-pkg_doexamples
191#
192# Installs given arguments to /usr/share/doc/${PF}/examples
193# If you give it only one parameter and it is a directory it will install
194# everything in that directory to the examples directory.
195#
196# @example
197# java-pkg_doexamples demo
198# java-pkg_doexamples demo/* examples/*
199#
200# @param $* - list of files to install
201# ------------------------------------------------------------------------------
202java-pkg_doexamples() {
203 debug-print-function ${FUNCNAME} $*
204
205 [[ ${#} -lt 1 ]] && die "At least one argument needed"
206
207 java-pkg_check-phase install
208
209 local dest=/usr/share/doc/${PF}/examples
210 if [[ ${#} = 1 && -d ${1} ]]; then
211 ( # dont want to pollute calling env
212 insinto "${dest}"
213 doins -r ${1}/*
214 ) || die "Installing examples failed"
215 else
216 ( # dont want to pollute calling env
217 insinto "${dest}"
218 doins -r "$@"
219 ) || die "Installing examples failed"
220 fi
221}
149 222
150# ----------------------------------------------------------------------------- 223# -----------------------------------------------------------------------------
151# @ebuild-function java-pkg_dojar 224# @ebuild-function java-pkg_dojar
152# 225#
153# Installs any number of jars. 226# Installs any number of jars.
172 # Create JARDEST if it doesn't exist 245 # Create JARDEST if it doesn't exist
173 dodir ${JAVA_PKG_JARDEST} 246 dodir ${JAVA_PKG_JARDEST}
174 247
175 local jar 248 local jar
176 # for each jar 249 # for each jar
177 for jar in "$@"; do 250 for jar in "${@}"; do
178 local jar_basename=$(basename "${jar}") 251 local jar_basename=$(basename "${jar}")
179 252
180 java-pkg_check-versioned-jar ${jar_basename} 253 java-pkg_check-versioned-jar ${jar_basename}
181 254
182 # check if it exists 255 # check if it exists
183 if [[ -e "${jar}" ]] ; then 256 if [[ -e "${jar}" ]] ; then
257 # Don't overwrite if jar has already been installed with the same
258 # name
259 local dest="${D}${JAVA_PKG_JARDEST}/${jar_basename}"
260 if [[ -e "${dest}" ]]; then
261 ewarn "Overwriting ${dest}"
262 fi
263
184 # install it into JARDEST if it's a non-symlink 264 # install it into JARDEST if it's a non-symlink
185 if [[ ! -L "${jar}" ]] ; then 265 if [[ ! -L "${jar}" ]] ; then
266 #but first check class version when in strict mode.
267 is-java-strict && java-pkg_verify-classes "${jar}"
268
186 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 269 INSDESTTREE="${JAVA_PKG_JARDEST}" \
187 doins "${jar}" || die "failed to install ${jar}" 270 doins "${jar}" || die "failed to install ${jar}"
188 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 271 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
189 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}" 272 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}"
190 # make a symlink to the original jar if it's symlink 273 # make a symlink to the original jar if it's symlink
201 284
202 java-pkg_do_write_ 285 java-pkg_do_write_
203} 286}
204 287
205 288
289# ------------------------------------------------------------------------------
290# @internal-function depend-java-query
291#
292# Wrapper for the depend-java-query binary to enable passing USE in env.
293# Using env variables keeps this eclass working with java-config versions that
294# do not handle use flags.
295# ------------------------------------------------------------------------------
296
297depend-java-query() {
298 # Used to have a which call here but it caused endless loops for some people
299 # that had some weird bashrc voodoo for which.
300 USE="${USE}" /usr/bin/depend-java-query "${@}"
301}
206 302
207# ------------------------------------------------------------------------------ 303# ------------------------------------------------------------------------------
208# @ebuild-function java-pkg_regjar 304# @ebuild-function java-pkg_regjar
209# 305#
210# Records an already installed jar in the package.env 306# Records an already installed jar in the package.env
241 [[ ${#} -lt 1 ]] && die "at least one argument needed" 337 [[ ${#} -lt 1 ]] && die "at least one argument needed"
242 338
243 java-pkg_init_paths_ 339 java-pkg_init_paths_
244 340
245 local jar jar_dir jar_file 341 local jar jar_dir jar_file
246 for jar in "$@"; do 342 for jar in "${@}"; do
247 # TODO use java-pkg_check-versioned-jar 343 # TODO use java-pkg_check-versioned-jar
248 if [[ -e "${jar}" ]]; then 344 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
345 [[ -d "${jar}" || -d "${D}${jar}" ]] \
346 && die "Called ${FUNCNAME} on a directory $*"
347
348 #check that class version correct when in strict mode
349 is-java-strict && java-pkg_verify-classes "${jar}"
350
249 # nelchael: we should strip ${D} in this case too, here's why: 351 # nelchael: we should strip ${D} in this case too, here's why:
250 # imagine such call: 352 # imagine such call:
251 # java-pkg_regjar ${D}/opt/java/*.jar 353 # java-pkg_regjar ${D}/opt/java/*.jar
252 # such call will fall into this case (-e ${jar}) and will 354 # such call will fall into this case (-e ${jar}) and will
253 # record paths with ${D} in package.env 355 # record paths with ${D} in package.env
254 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 356 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
255 elif [[ -e "${D}${jar}" ]]; then
256 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
257 else 357 else
358 if [[ ${jar} = *\** ]]; then
359 eerror "The argument ${jar} to ${FUNCNAME}"
360 eerror "has * in it. If you want it to glob in"
361 eerror '${D} add ${D} to the argument.'
362 fi
258 die "${jar} does not exist" 363 die "${jar} does not exist"
259 fi 364 fi
260 done 365 done
261 366
262 java-pkg_do_write_ 367 java-pkg_do_write_
263} 368}
264
265 369
266# ------------------------------------------------------------------------------ 370# ------------------------------------------------------------------------------
267# @ebuild-function java-pkg_newjar 371# @ebuild-function java-pkg_newjar
268# 372#
269# Installs a jar with a new name 373# Installs a jar with a new name
280 local original_jar="${1}" 384 local original_jar="${1}"
281 local new_jar="${2:-${PN}.jar}" 385 local new_jar="${2:-${PN}.jar}"
282 local new_jar_dest="${T}/${new_jar}" 386 local new_jar_dest="${T}/${new_jar}"
283 387
284 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 388 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
285 [[ ! -f ${original_jar} ]] && die "${original_jar} does not exist!" 389 [[ ! -f ${original_jar} ]] \
390 && die "${original_jar} does not exist or is not a file!"
286 391
287 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 392 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
288 cp "${original_jar}" "${new_jar_dest}" \ 393 cp "${original_jar}" "${new_jar_dest}" \
289 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 394 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
290 java-pkg_dojar "${new_jar_dest}" 395 java-pkg_dojar "${new_jar_dest}"
339 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 444 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
340 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 445 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
341 # otherwise make a symlink to the symlink's origin 446 # otherwise make a symlink to the symlink's origin
342 else 447 else
343 # TODO use dosym 448 # TODO use dosym
449 ln -s "$(readlink "${lib}")" \
344 ln -s "$(readlink "${lib}")" "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")" 450 "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")"
345 debug-print "${lib} is a symlink, linking accordanly" 451 debug-print "${lib} is a symlink, linking accordanly"
346 fi 452 fi
347 # otherwise die 453 # otherwise die
348 else 454 else
349 die "${lib} does not exist" 455 die "${lib} does not exist"
450# @example: 556# @example:
451# java-pkg_dojavadoc docs/api 557# java-pkg_dojavadoc docs/api
452# 558#
453# ------------------------------------------------------------------------------ 559# ------------------------------------------------------------------------------
454java-pkg_dojavadoc() { 560java-pkg_dojavadoc() {
561 debug-print-function ${FUNCNAME} $*
455 local dir="$1" 562 local dir="$1"
563
564 # QA checks
456 565
457 java-pkg_check-phase install 566 java-pkg_check-phase install
458 567
459 [[ -z "${dir}" ]] && die "Must specify a directory!" 568 [[ -z "${dir}" ]] && die "Must specify a directory!"
460 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!" 569 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!"
570 if [[ ! -e "${dir}/index.html" ]]; then
571 local msg="No index.html in javadoc directory"
572 ewarn "${msg}"
573 is-java-strict && die "${msg}"
574 fi
575
576 # Renaming to match our directory layout
461 577
462 local dir_to_install="${dir}" 578 local dir_to_install="${dir}"
463 if [[ "$(basename "${dir}")" != "api" ]]; then 579 if [[ "$(basename "${dir}")" != "api" ]]; then
464 dir_to_install="${T}/api" 580 dir_to_install="${T}/api"
465 # TODO use doins 581 # TODO use doins
466 cp -r "${dir}" "${dir_to_install}" || die "cp failed" 582 cp -r "${dir}" "${dir_to_install}" || die "cp failed"
467 fi 583 fi
584
585 # Actual installation
468 586
469 java-pkg_dohtml -r ${dir_to_install} 587 java-pkg_dohtml -r ${dir_to_install}
470} 588}
471 589
472# ------------------------------------------------------------------------------ 590# ------------------------------------------------------------------------------
490# FIXME apparently this fails if you give it an empty directories 608# FIXME apparently this fails if you give it an empty directories
491java-pkg_dosrc() { 609java-pkg_dosrc() {
492 debug-print-function ${FUNCNAME} $* 610 debug-print-function ${FUNCNAME} $*
493 611
494 [ ${#} -lt 1 ] && die "At least one argument needed" 612 [ ${#} -lt 1 ] && die "At least one argument needed"
495 if ! hasq source ${IUSE}; then
496 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
497 fi
498 613
499 java-pkg_check-phase install 614 java-pkg_check-phase install
500 615
501 [[ ${#} -lt 1 ]] && die "At least one argument needed" 616 [[ ${#} -lt 1 ]] && die "At least one argument needed"
617
618 if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
619 local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
620 if is-java-strict; then
621 eerror "${msg}"
622 die "${msg}"
623 else
624 echo "${msg}"
625 echo "Please report this to http://bugs.gentoo.org."
626 fi
627 fi
502 628
503 java-pkg_init_paths_ 629 java-pkg_init_paths_
504 630
505 local zip_name="${PN}-src.zip" 631 local zip_name="${PN}-src.zip"
506 local zip_path="${T}/${zip_name}" 632 local zip_path="${T}/${zip_name}"
507 local dir 633 local dir
508 for dir in ${@}; do 634 for dir in "${@}"; do
509 local dir_parent=$(dirname "${dir}") 635 local dir_parent=$(dirname "${dir}")
510 local dir_name=$(basename "${dir}") 636 local dir_name=$(basename "${dir}")
511 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 637 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
512 zip -q -r ${zip_path} ${dir_name} -i '*.java' 638 zip -q -r ${zip_path} ${dir_name} -i '*.java'
513 local result=$? 639 local result=$?
538# @param $1 - filename of launcher to create 664# @param $1 - filename of launcher to create
539# @param $2 - options, as follows: 665# @param $2 - options, as follows:
540# --main the.main.class.too.start 666# --main the.main.class.too.start
541# --jar /the/jar/too/launch.jar or just <name>.jar 667# --jar /the/jar/too/launch.jar or just <name>.jar
542# --java_args 'Extra arguments to pass to java' 668# --java_args 'Extra arguments to pass to java'
543# --pkg_args 'Extra arguments too pass to the package' 669# --pkg_args 'Extra arguments to pass to the package'
544# --pwd 670# --pwd Directory the launcher changes to before executing java
545# -into 671# -into Directory to install the launcher to, instead of /usr/bin
546# -pre 672# -pre Prepend contents of this file to the launcher
547# ------------------------------------------------------------------------------ 673# ------------------------------------------------------------------------------
548java-pkg_dolauncher() { 674java-pkg_dolauncher() {
549 debug-print-function ${FUNCNAME} $* 675 debug-print-function ${FUNCNAME} $*
550 676
551 java-pkg_check-phase install 677 java-pkg_check-phase install
563 local var_tmp="${T}/launcher_variables_tmp" 689 local var_tmp="${T}/launcher_variables_tmp"
564 local target_dir pre 690 local target_dir pre
565 691
566 # Process the other the rest of the arguments 692 # Process the other the rest of the arguments
567 while [[ -n "${1}" && -n "${2}" ]]; do 693 while [[ -n "${1}" && -n "${2}" ]]; do
568 local var=${1} value=${2} 694 local var="${1}" value="${2}"
569 if [[ "${var:0:2}" == "--" ]]; then 695 if [[ "${var:0:2}" == "--" ]]; then
570 local var=${var:2} 696 local var=${var:2}
571 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}" 697 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
572 local gjl_${var}="${value}" 698 local gjl_${var}="${value}"
573 elif [[ "${var}" == "-into" ]]; then 699 elif [[ "${var}" == "-into" ]]; then
592 fi 718 fi
593 fi 719 fi
594 720
595 # Write the actual script 721 # Write the actual script
596 echo "#!/bin/bash" > "${target}" 722 echo "#!/bin/bash" > "${target}"
597 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 723 if [[ -n "${pre}" ]]; then
724 if [[ -f "${pre}" ]]; then
725 cat "${pre}" >> "${target}"
726 else
727 die "-pre specified file '${pre}' does not exist"
728 fi
729 fi
598 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 730 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
599 cat "${var_tmp}" >> "${target}" 731 cat "${var_tmp}" >> "${target}"
600 rm -f "${var_tmp}" 732 rm -f "${var_tmp}"
601 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 733 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
602 734
694# Example: get a specific jar from xerces slot 2, and name it diffrently 826# Example: get a specific jar from xerces slot 2, and name it diffrently
695# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 827# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
696# Example: get junit.jar which is needed only for building 828# Example: get junit.jar which is needed only for building
697# java-pkg_jar-from --build-only junit junit.jar 829# java-pkg_jar-from --build-only junit junit.jar
698# 830#
699# @param $1 - (optional) "--build-only" makes the jar(s) not added into 831# @param $opt
700# package.env DEPEND line. 832# --build-only - makes the jar(s) not added into package.env DEPEND line.
701# @param $1 - Package to get jars from. 833# (assumed automatically when called inside src_test)
834# --with-dependencies - get jars also from requested package's dependencies
835# transitively.
836# --into $dir - symlink jar(s) into $dir (must exist) instead of .
837# @param $1 - Package to get jars from, or comma-separated list of packages in
838# case other parameters are not used.
702# @param $2 - jar from package. If not specified, all jars will be used. 839# @param $2 - jar from package. If not specified, all jars will be used.
703# @param $3 - When a single jar is specified, destination filename of the 840# @param $3 - When a single jar is specified, destination filename of the
704# symlink. Defaults to the name of the jar. 841# symlink. Defaults to the name of the jar.
705# ------------------------------------------------------------------------------ 842# ------------------------------------------------------------------------------
706# TODO could probably be cleaned up a little 843# TODO could probably be cleaned up a little
707java-pkg_jar-from() { 844java-pkg_jar-from() {
708 debug-print-function ${FUNCNAME} $* 845 debug-print-function ${FUNCNAME} $*
709 846
710 local build_only="" 847 local build_only=""
848 local destdir="."
849 local deep=""
711 850
851 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
852
853 while [[ "${1}" == --* ]]; do
712 if [[ "${1}" = "--build-only" ]]; then 854 if [[ "${1}" = "--build-only" ]]; then
713 build_only="true" 855 build_only="build"
856 elif [[ "${1}" = "--with-dependencies" ]]; then
857 deep="--with-dependencies"
858 elif [[ "${1}" = "--into" ]]; then
859 destdir="${2}"
860 shift
861 else
862 die "java-pkg_jar-from called with unknown parameter: ${1}"
863 fi
714 shift 864 shift
715 fi 865 done
716 866
717 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 867 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
718 868
719 [[ -z ${target_pkg} ]] && die "Must specify a package" 869 [[ -z ${target_pkg} ]] && die "Must specify a package"
720 870
721 # default destjar to the target jar 871 # default destjar to the target jar
722 [[ -z "${destjar}" ]] && destjar="${target_jar}" 872 [[ -z "${destjar}" ]] && destjar="${target_jar}"
723 873
724 local error_msg="There was a problem getting the classpath for ${target_pkg}." 874 local error_msg="There was a problem getting the classpath for ${target_pkg}."
725 local classpath 875 local classpath
726 classpath="$(java-config --classpath=${target_pkg})" 876 classpath="$(java-config ${deep} --classpath=${target_pkg})"
727 [[ $? != 0 ]] && die ${error_msg} 877 [[ $? != 0 ]] && die ${error_msg}
878
879 # When we have commas this functions is called to bring jars from multiple
880 # packages. This affects recording of dependencencies performed later
881 # which expects one package only, so we do it here.
882 if [[ ${target_pkg} = *,* ]]; then
883 for pkg in ${target_pkg//,/ }; do
884 java-pkg_ensure-dep "${build_only}" "${pkg}"
885 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
886 done
887 # setting this disables further record-jar_ calls later
888 build_only="build"
889 else
890 java-pkg_ensure-dep "${build_only}" "${target_pkg}"
891 fi
892
893 pushd ${destdir} > /dev/null \
894 || die "failed to change directory to ${destdir}"
728 895
729 local jar 896 local jar
730 for jar in ${classpath//:/ }; do 897 for jar in ${classpath//:/ }; do
731 local jar_name=$(basename "${jar}") 898 local jar_name=$(basename "${jar}")
732 if [[ ! -f "${jar}" ]] ; then 899 if [[ ! -f "${jar}" ]] ; then
743 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 910 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
744 [[ -f "${destjar}" ]] && rm "${destjar}" 911 [[ -f "${destjar}" ]] && rm "${destjar}"
745 ln -snf "${jar}" "${destjar}" \ 912 ln -snf "${jar}" "${destjar}" \
746 || die "Failed to make symlink from ${jar} to ${destjar}" 913 || die "Failed to make symlink from ${jar} to ${destjar}"
747 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}" 914 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
915 popd > /dev/null
748 return 0 916 return 0
749 fi 917 fi
750 done 918 done
919 popd > /dev/null
751 # if no target was specified, we're ok 920 # if no target was specified, we're ok
752 if [[ -z "${target_jar}" ]] ; then 921 if [[ -z "${target_jar}" ]] ; then
753 return 0 922 return 0
754 # otherwise, die bitterly 923 # otherwise, die bitterly
755 else 924 else
779# Example: Get the classpath for xerces-2 and xalan, 948# Example: Get the classpath for xerces-2 and xalan,
780# java-pkg_getjars xerces-2,xalan 949# java-pkg_getjars xerces-2,xalan
781# Example Return: 950# Example Return:
782# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 951# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
783# 952#
784# @param $1 - (optional) "--build-only" makes the jar(s) not added into 953# @param $opt
785# package.env DEPEND line. 954# --build-only - makes the jar(s) not added into package.env DEPEND line.
955# (assumed automatically when called inside src_test)
956# --with-dependencies - get jars also from requested package's dependencies
957# transitively.
786# @param $2 - list of packages to get jars from 958# @param $1 - list of packages to get jars from
787# (passed to java-config --classpath) 959# (passed to java-config --classpath)
788# ------------------------------------------------------------------------------ 960# ------------------------------------------------------------------------------
789java-pkg_getjars() { 961java-pkg_getjars() {
790 debug-print-function ${FUNCNAME} $* 962 debug-print-function ${FUNCNAME} $*
791 963
792 [[ ${#} -lt 1 || ${#} -gt 2 ]] && die "${FUNCNAME} takes only one or two arguments" 964 local build_only=""
965 local deep=""
793 966
967 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
968
969 while [[ "${1}" == --* ]]; do
794 if [[ "${1}" = "--build-only" ]]; then 970 if [[ "${1}" = "--build-only" ]]; then
795 local build_only="true" 971 build_only="build"
972 elif [[ "${1}" = "--with-dependencies" ]]; then
973 deep="--with-dependencies"
974 else
975 die "java-pkg_jar-from called with unknown parameter: ${1}"
976 fi
796 shift 977 shift
797 fi 978 done
979
980 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
981
798 982
799 local classpath pkgs="${1}" 983 local classpath pkgs="${1}"
800 jars="$(java-config --classpath=${pkgs})" 984 jars="$(java-config ${deep} --classpath=${pkgs})"
801 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed" 985 [[ $? != 0 || -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed"
802 debug-print "${pkgs}:${jars}" 986 debug-print "${pkgs}:${jars}"
987
988 for pkg in ${pkgs//,/ }; do
989 java-pkg_ensure-dep "${build_only}" "${pkg}"
990 done
803 991
804 if [[ -z "${classpath}" ]]; then 992 if [[ -z "${classpath}" ]]; then
805 classpath="${jars}" 993 classpath="${jars}"
806 else 994 else
807 classpath="${classpath}:${jars}" 995 classpath="${classpath}:${jars}"
808 fi 996 fi
809 997
810 # Only record jars that aren't build-only 998 # Only record jars that aren't build-only
811 if [[ -z "${build_only}" ]]; then 999 if [[ -z "${build_only}" ]]; then
812 oldifs="${IFS}"
813 IFS=","
814 for pkg in ${pkgs}; do 1000 for pkg in ${pkgs//:/ }; do
815 java-pkg_record-jar_ "${pkg}" 1001 java-pkg_record-jar_ "${pkg}"
816 done 1002 done
817 IFS="${oldifs}"
818 fi 1003 fi
819 1004
820 echo "${classpath}" 1005 echo "${classpath}"
821} 1006}
822 1007
832# @example 1017# @example
833# java-pkg_getjar xerces-2 xml-apis.jar 1018# java-pkg_getjar xerces-2 xml-apis.jar
834# @example-return 1019# @example-return
835# /usr/share/xerces-2/lib/xml-apis.jar 1020# /usr/share/xerces-2/lib/xml-apis.jar
836# 1021#
837# @param $1 - (optional) "--build-only" makes the jar not added into 1022# @param $opt
838# package.env DEPEND line. 1023# --build-only - makes the jar not added into package.env DEPEND line.
839# @param $1 - package to use 1024# @param $1 - package to use
840# @param $2 - jar to get 1025# @param $2 - jar to get
841# ------------------------------------------------------------------------------ 1026# ------------------------------------------------------------------------------
842java-pkg_getjar() { 1027java-pkg_getjar() {
843 debug-print-function ${FUNCNAME} $* 1028 debug-print-function ${FUNCNAME} $*
844 1029
845 local build_only="" 1030 local build_only=""
846 1031
1032 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1033
1034 while [[ "${1}" == --* ]]; do
847 if [[ "${1}" = "--build-only" ]]; then 1035 if [[ "${1}" = "--build-only" ]]; then
848 build_only="true" 1036 build_only="build"
1037 else
1038 die "java-pkg_jar-from called with unknown parameter: ${1}"
1039 fi
849 shift 1040 shift
850 fi 1041 done
1042
1043 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
851 1044
852 local pkg="${1}" target_jar="${2}" jar 1045 local pkg="${1}" target_jar="${2}" jar
853 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 1046 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
854 [[ -z ${target_jar} ]] && die "Must specify jar to get" 1047 [[ -z ${target_jar} ]] && die "Must specify jar to get"
855 1048
856 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?" 1049 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
857 local classpath 1050 local classpath
858 classpath=$(java-config --classpath=${pkg}) 1051 classpath=$(java-config --classpath=${pkg})
859 [[ $? != 0 ]] && die ${error_msg} 1052 [[ $? != 0 ]] && die ${error_msg}
1053
1054 java-pkg_ensure-dep "${build_only}" "${pkg}"
860 1055
861 for jar in ${classpath//:/ }; do 1056 for jar in ${classpath//:/ }; do
862 if [[ ! -f "${jar}" ]] ; then 1057 if [[ ! -f "${jar}" ]] ; then
863 die "Installation problem with jar ${jar} in ${pkg} - is it installed?" 1058 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
864 fi 1059 fi
871 fi 1066 fi
872 done 1067 done
873 1068
874 die "Could not find ${target_jar} in ${pkg}" 1069 die "Could not find ${target_jar} in ${pkg}"
875 return 1 1070 return 1
1071}
1072
1073# ------------------------------------------------------------------------------
1074# @ebuild-function java-pkg_register-dependency
1075#
1076# Registers runtime dependency on a package, list of packages, or a single jar
1077# from a package, into package.env DEPEND line. Can only be called in
1078# src_install phase.
1079# Intended for binary packages where you don't need to symlink the jars or get
1080# their classpath during build. As such, the dependencies only need to be
1081# specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1082# Get the classpath provided by any number of packages.
1083#
1084# @param $1 - comma-separated list of packages, or a single package
1085# @param $2 - if param $1 is a single package, optionally specify the jar
1086# to depend on
1087#
1088# Example: Record the dependency on whole xerces-2 and xalan,
1089# java-pkg_register-dependency xerces-2,xalan
1090# Example: Record the dependency on ant.jar from ant-core
1091# java-pkg_register-dependency ant-core ant.jar
1092#
1093# Note: Passing both list of packages as the first parameter AND specifying the
1094# jar as the second is not allowed and will cause the function to die. We assume
1095# that there's more chance one passes such combination as a mistake, than that
1096# there are more packages providing identically named jar without class
1097# collisions.
1098# ------------------------------------------------------------------------------
1099java-pkg_register-dependency() {
1100 debug-print-function ${FUNCNAME} $*
1101
1102 java-pkg_check-phase install
1103
1104 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1105
1106 local pkgs="${1}"
1107 local jar="${2}"
1108
1109 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1110
1111 if [[ -z "${jar}" ]]; then
1112 for pkg in ${pkgs//,/ }; do
1113 java-pkg_ensure-dep runtime "${pkg}"
1114 java-pkg_record-jar_ "${pkg}"
1115 done
1116 else
1117 [[ ${pkgs} == *,* ]] && \
1118 die "${FUNCNAME} called with both package list and jar name"
1119 java-pkg_ensure-dep runtime "${pkgs}"
1120 java-pkg_record-jar_ "${pkgs}" "${jar}"
1121 fi
1122
1123 java-pkg_do_write_
876} 1124}
877 1125
878# This function reads stdin, and based on that input, figures out how to 1126# This function reads stdin, and based on that input, figures out how to
879# populate jars from the filesystem. 1127# populate jars from the filesystem.
880# Need to figure out a good way of making use of this, ie be able to use a 1128# Need to figure out a good way of making use of this, ie be able to use a
997# 1245#
998# export DEPEND="${DEPEND} ${depstr}" 1246# export DEPEND="${DEPEND} ${depstr}"
999# export RDEPEND="${RDEPEND} ${depstr}" 1247# export RDEPEND="${RDEPEND} ${depstr}"
1000#} 1248#}
1001 1249
1250# ------------------------------------------------------------------------------
1251# @ebuild-function java-pkg_find-normal-jars
1252#
1253# Find the files with suffix .jar file in the given directory or $WORKDIR
1254#
1255# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1256# ------------------------------------------------------------------------------
1257java-pkg_find-normal-jars() {
1258 local dir=$1
1259 [[ "${dir}" ]] || dir="${WORKDIR}"
1260 local found
1261 for jar in $(find "${dir}" -name "*.jar" -type f); do
1262 echo "${jar}"
1263 found="true"
1264 done
1265 [[ "${found}" ]]
1266 return $?
1267}
1268
1269# ------------------------------------------------------------------------------
1270# @ebuild-function java-pkg_ensure-no-bundled-jars
1271#
1272# Try to locate bundled jar files in ${WORKDIR} and die if found.
1002# This should be used after S has been populated with symlinks to jars 1273# This function should be called after WORKDIR has been populated with symlink
1003# TODO document 1274# to system jar files or bundled jars removed.
1275# ------------------------------------------------------------------------------
1004java-pkg_ensure-no-bundled-jars() { 1276java-pkg_ensure-no-bundled-jars() {
1005 debug-print-function ${FUNCNAME} $* 1277 debug-print-function ${FUNCNAME} $*
1006 pushd ${WORKDIR} >/dev/null 2>/dev/null
1007 1278
1008 local bundled_jars=$(find . -name "*.jar" -type f) 1279 local bundled_jars=$(java-pkg_find-normal-jars)
1009 if [[ -n ${bundled_jars} ]]; then 1280 if [[ -n ${bundled_jars} ]]; then
1010 echo "Bundled jars found:" 1281 echo "Bundled jars found:"
1011 local jar 1282 local jar
1012 for jar in ${bundled_jars}; do 1283 for jar in ${bundled_jars}; do
1013 echo $(pwd)${jar/./} 1284 echo $(pwd)${jar/./}
1014 done 1285 done
1015 die "Bundled jars found!" 1286 die "Bundled jars found!"
1016
1017 fi 1287 fi
1018 popd >/dev/null 2>/dev/null
1019} 1288}
1020 1289
1021# ------------------------------------------------------------------------------ 1290# ------------------------------------------------------------------------------
1022# @internal-function java-pkg_ensure-vm-version-sufficient 1291# @internal-function java-pkg_ensure-vm-version-sufficient
1023# 1292#
1172# @ebuild-function java-pkg_get-target 1441# @ebuild-function java-pkg_get-target
1173# 1442#
1174# Determines what target version should be used, for passing to -target. 1443# Determines what target version should be used, for passing to -target.
1175# If you don't care about lower versions, you can set _WANT_TARGET to the 1444# If you don't care about lower versions, you can set _WANT_TARGET to the
1176# version of your JDK. 1445# version of your JDK.
1177# Remember doing this will mostly like cause things to break.
1178# Doesn't allow it to be lower then the one in depend.
1179# Doesn't allow it to be higher then the active vm.
1180# 1446#
1181# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1447# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1182# ------------------------------------------------------------------------------ 1448# ------------------------------------------------------------------------------
1183java-pkg_get-target() { 1449java-pkg_get-target() {
1184 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")
1185 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then
1186 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)"
1187 if version_is_at_least "${min}" "${JAVA_PKG_WANT_TARGET}" && version_is_at_least "${JAVA_PKG_WANT_TARGET}" "${max}"; then
1188 echo ${JAVA_PKG_WANT_TARGET}
1189 else
1190 echo ${min}
1191 fi
1192 else
1193 echo ${min}
1194 fi
1195
1196 #echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND}")} 1450 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1197} 1451}
1198 1452
1199java-pkg_get-javac() { 1453java-pkg_get-javac() {
1200 debug-print-function ${FUNCNAME} $* 1454 debug-print-function ${FUNCNAME} $*
1201 1455
1270 1524
1271# TODO document 1525# TODO document
1272java-pkg_get-jni-cflags() { 1526java-pkg_get-jni-cflags() {
1273 local flags="-I${JAVA_HOME}/include" 1527 local flags="-I${JAVA_HOME}/include"
1274 1528
1529 local platform="linux"
1530 use elibc_FreeBSD && platform="freebsd"
1531
1275 # TODO do a check that the directories are valid 1532 # TODO do a check that the directories are valid
1276 # TODO figure out how to cope with other things than linux...
1277 flags="${flags} -I${JAVA_HOME}/include/linux" 1533 flags="${flags} -I${JAVA_HOME}/include/${platform}"
1278 1534
1279 echo ${flags} 1535 echo ${flags}
1280} 1536}
1281 1537
1282java-pkg_ensure-gcj() { 1538java-pkg_ensure-gcj() {
1288 die "No GCJ support found!" 1544 die "No GCJ support found!"
1289 fi 1545 fi
1290} 1546}
1291 1547
1292java-pkg_ensure-test() { 1548java-pkg_ensure-test() {
1293 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} && ! use test; then 1549 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \
1550 && hasq test ${IUSE} && ! use test;
1551 then
1294 eerror "You specified FEATURES=test, but USE=test is needed" 1552 eerror "You specified FEATURES=test, but USE=test is needed"
1295 eerror "to pull in the additional dependencies for testing" 1553 eerror "to pull in the additional dependencies for testing"
1296 die "Need USE=test enabled" 1554 die "Need USE=test enabled"
1297 fi 1555 fi
1298} 1556}
1299 1557
1300# ------------------------------------------------------------------------------ 1558# ------------------------------------------------------------------------------
1559# @ebuild-function java-pkg_register-ant-task
1560#
1561# Register this package as ant task, so that ant will load it when no specific
1562# ANT_TASKS are specified. Note that even without this registering, all packages
1563# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1564# packages, but can be also used by other ebuilds that used to symlink their
1565# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1566# compatibility.
1567#
1568# @param --version x.y Register only for ant version x.y (otherwise for any ant
1569# version). Used by the ant-* packages to prevent loading of mismatched
1570# ant-core ant tasks after core was updated, before the tasks are updated,
1571# without a need for blockers.
1572# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1573# ------------------------------------------------------------------------------
1574java-pkg_register-ant-task() {
1575 local TASKS_DIR="tasks"
1576
1577 # check for --version x.y parameters
1578 while [[ -n "${1}" && -n "${2}" ]]; do
1579 local var="${1#--}"
1580 local val="${2}"
1581 if [[ "${var}" == "version" ]]; then
1582 TASKS_DIR="tasks-${val}"
1583 else
1584 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1585 fi
1586 shift 2
1587 done
1588
1589 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1590
1591 dodir /usr/share/ant/${TASKS_DIR}
1592 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1593}
1594
1595# ------------------------------------------------------------------------------
1596# @internal-function java-pkg_ant-tasks-from-deps
1597#
1598# Function to determine ANT_TASKS from DEPEND variable for backwards
1599# compatibility with ebuilds that don't set ANT_TASKS before calling eant() or
1600# WANT_ANT_TASKS before inheriting java-pkg-2. If the DEPEND string contains
1601# "dev-java/ant" or "dev-java/ant-tasks", then it returns "all", otherwise
1602# "none". It's not smart enough to cope with USE flag depends but that shouldn't
1603# be a problem, the worst it can do is activace all tasks when not needed.
1604# Note that this is called only with JAVA_PKG_STRICT=1, to find ebuilds with
1605# insufficient dependencies, otherwise all available tasks are used for
1606# backwards compatilbility.
1607#
1608# @return "all" or "none"
1609# ------------------------------------------------------------------------------
1610java-pkg_ant-tasks-from-deps() {
1611 local found_ant found_ant_tasks
1612
1613 for dep in ${DEPEND}
1614 do
1615 local ant="$(awk '/(dev-java\/ant)/ { if (match($1, "(dev-java/ant)((-[0-9])+|$)", m)) print m[1] }' <<< ${dep})"
1616 [[ "${ant}" == "dev-java/ant" ]] && found_ant=true
1617 [[ "${dep}" == *"ant-tasks"* ]] && found_ant_tasks=true
1618 done
1619
1620 if [[ -n "${found_ant}" || -n "${found_ant_tasks}" ]]; then
1621 java-pkg_announce-qa-violation "The ebuild DEPENDS on deprecated ant or ant-tasks"
1622 echo "all"
1623 else
1624 # ebuild doesn't set ANT_TASKS and doesn't depend on ant-tasks or ant
1625 # so we deactivate all tasks that may be installed
1626 echo "none"
1627 fi
1628}
1629
1630# ------------------------------------------------------------------------------
1631# @internal-function java-pkg_ant-tasks-depend
1632#
1633# Translates the WANT_ANT_TASKS variable into valid dependencies.
1634# ------------------------------------------------------------------------------
1635java-pkg_ant-tasks-depend() {
1636 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1637
1638 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1639 local DEP=""
1640 for i in ${WANT_ANT_TASKS}
1641 do
1642 if [[ ${i} != ant-* ]]; then
1643 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1644 return 1
1645 fi
1646 DEP="${DEP}dev-java/${i} "
1647 done
1648 echo ${DEP}
1649 return 0
1650 else
1651 return 0
1652 fi
1653}
1654
1655# ------------------------------------------------------------------------------
1301# @section-end helper 1656# @section-end helper
1302# ------------------------------------------------------------------------------ 1657# ------------------------------------------------------------------------------
1303 1658
1304# ------------------------------------------------------------------------------ 1659# ------------------------------------------------------------------------------
1305# @section-begin build 1660# @section-begin build
1311 1666
1312# ------------------------------------------------------------------------------ 1667# ------------------------------------------------------------------------------
1313# @ebuild-function eant 1668# @ebuild-function eant
1314# 1669#
1315# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1670# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1316# compiler. 1671# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1317# 1672# variables:
1673# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1674# gentoo.classpath property. Be sure to call
1675# java-ant_rewrite-classpath in src_unpack.
1676# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1318# ------------------------------------------------------------------------------ 1677# ------------------------------------------------------------------------------
1319eant() { 1678eant() {
1320 debug-print-function ${FUNCNAME} $* 1679 debug-print-function ${FUNCNAME} $*
1321 1680
1322 # FIXME get this working 1681 # FIXME get this working
1323# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then 1682# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then
1324# java-pkg_announce-qa-violation \ 1683# java-pkg_announce-qa-violation \
1325# "Using eant, but not depending on dev-java/ant or dev-java/ant-core" 1684# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1326# fi 1685# fi
1327 1686
1328 local antflags 1687 if ! hasq java-ant-2 ${INHERITED} && is-java-strict; then
1688 local msg="You should inherit java-ant-2 when using eant"
1689 java-pkg_announce-qa-violation ${msg}
1690 die ${msg}
1691 fi
1692
1693 local antflags="-Dnoget=true -Dmaven.mode.offline=true"
1694
1329 java-pkg_init-compiler_ 1695 java-pkg_init-compiler_
1330 local compiler="${GENTOO_COMPILER}" 1696 local compiler="${GENTOO_COMPILER}"
1331 1697
1332 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1698 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1333 1699
1335 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1701 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1336 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1702 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1337 fi 1703 fi
1338 1704
1339 if [[ ${compiler} != "javac" ]]; then 1705 if [[ ${compiler} != "javac" ]]; then
1340 antflags="-Dbuild.compiler=${build_compiler}" 1706 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1341 # Figure out any extra stuff to put on the classpath for compilers aside 1707 # Figure out any extra stuff to put on the classpath for compilers aside
1342 # from javac 1708 # from javac
1343 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to 1709 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1344 # java-config -p 1710 # java-config -p
1345 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1711 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})"
1351 if is-java-strict; then 1717 if is-java-strict; then
1352 einfo "Disabling system classpath for ant" 1718 einfo "Disabling system classpath for ant"
1353 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1719 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1354 fi 1720 fi
1355 1721
1356 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1722 for arg in "${@}"; do
1357 antflags="${antflags} -debug" 1723 if [[ ${arg} = -lib ]]; then
1724 if is-java-strict; then
1725 eerror "You should not use the -lib argument to eant because it will fail"
1726 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1727 eerror "or ant properties to make dependencies available."
1728 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1729 eerror "split ant (>=dev-java/ant-core-1.7)."
1730 die "eant -lib is deprecated/forbidden"
1731 else
1732 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1733 echo "more info."
1734 fi
1735 fi
1736 done
1737
1738 if has_version ">=dev-java/ant-core-1.7.0"; then
1739 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1740 ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}"
1741
1742 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1743 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1744
1745 if is-java-strict; then
1746 # if ant-tasks were not set by ebuild or forced, try to determine them from depends
1747 if [[ -z "${ANT_TASKS}" ]]; then
1748 ANT_TASKS="$(java-pkg_ant-tasks-from-deps)"
1749 fi
1750 else
1751 # if ant-tasks is not set by ebuild or forced, activate all of them
1752 ANT_TASKS="${ANT_TASKS:-all}"
1753 fi
1754
1755 # at this point, ANT_TASKS should be "all", "none" or explicit list
1756 if [[ "${ANT_TASKS}" == "all" ]]; then
1757 einfo "Using all available ANT_TASKS"
1758 elif [[ "${ANT_TASKS}" == "none" ]]; then
1759 einfo "Disabling all optional ANT_TASKS"
1760 else
1761 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1762 fi
1763
1764 export ANT_TASKS
1765 fi
1766
1767 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1768 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1769
1770 local gcp="${EANT_GENTOO_CLASSPATH}"
1771 local getjarsarg=""
1772
1773 if [[ ${EBUILD_PHASE} = "test" ]]; then
1774 antflags="${antflags} -DJunit.present=true"
1775 [[ ${gcp} && ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1776 getjarsarg="--with-dependencies"
1777 fi
1778
1779 local cp
1780
1781 for atom in ${gcp}; do
1782 cp="${cp}:$(java-pkg_getjars ${getjarsarg} ${atom})"
1783 done
1784
1785 if [[ ${cp} ]]; then
1786 # It seems ant does not like single quotes around ${cp}
1787 antflags="${antflags} -Dgentoo.classpath=\"${cp#:}\""
1358 fi 1788 fi
1359 1789
1360 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1790 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1791 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
1361 ant ${antflags} "${@}" || die "eant failed" 1792 ant ${antflags} "${@}" || die "eant failed"
1362
1363} 1793}
1364 1794
1365# ------------------------------------------------------------------------------ 1795# ------------------------------------------------------------------------------
1366# @ebuild-function ejavac 1796# @ebuild-function ejavac
1367# 1797#
1436# ------------------------------------------------------------------------------ 1866# ------------------------------------------------------------------------------
1437use_doc() { 1867use_doc() {
1438 use doc && echo ${@:-javadoc} 1868 use doc && echo ${@:-javadoc}
1439} 1869}
1440 1870
1871
1441# ------------------------------------------------------------------------------ 1872# ------------------------------------------------------------------------------
1442# @section-end build 1873# @section-end build
1443# ------------------------------------------------------------------------------ 1874# ------------------------------------------------------------------------------
1444 1875
1445# ------------------------------------------------------------------------------ 1876# ------------------------------------------------------------------------------
1463# 1894#
1464# ----------------------------------------------------------------------------- 1895# -----------------------------------------------------------------------------
1465java-pkg_init() { 1896java-pkg_init() {
1466 unset JAVAC 1897 unset JAVAC
1467 unset JAVA_HOME 1898 unset JAVA_HOME
1899
1900 # People do all kinds of weird things.
1901 # http://forums.gentoo.org/viewtopic-p-3943166.html
1902 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
1903 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
1904 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
1905 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
1906 ewarn "sun-jdk vms and and as such break configure scripts that"
1907 ewarn "use it (for example app-office/openoffice) so we filter it out."
1908 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
1909 ewarn "make.conf for example) to silence this warning or"
1910 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
1911 fi
1912
1913 if [[ -z ${accept} ]]; then
1914 unset _JAVA_OPTIONS
1915 # phase hooks make this run many times without this
1916 I_WANT_GLOBAL_JAVA_OPTIONS="true"
1917 fi
1918
1468 java-pkg_init_paths_ 1919 java-pkg_init_paths_
1469 java-pkg_switch-vm 1920 java-pkg_switch-vm
1470 PATH=${JAVA_HOME}/bin:${PATH} 1921 PATH=${JAVA_HOME}/bin:${PATH}
1471 1922
1472 # TODO we will probably want to set JAVAC and JAVACFLAGS 1923 # TODO we will probably want to set JAVAC and JAVACFLAGS
1477 # When users have crazy classpaths some packages can fail to compile. 1928 # When users have crazy classpaths some packages can fail to compile.
1478 # and everything should work with empty CLASSPATH. 1929 # and everything should work with empty CLASSPATH.
1479 # This also helps prevent unexpected dependencies on random things 1930 # This also helps prevent unexpected dependencies on random things
1480 # from the CLASSPATH. 1931 # from the CLASSPATH.
1481 unset CLASSPATH 1932 unset CLASSPATH
1933
1934 # Unset external ANT_ stuff
1935 unset ANT_TASKS
1936 unset ANT_OPTS
1482} 1937}
1483 1938
1484# ------------------------------------------------------------------------------ 1939# ------------------------------------------------------------------------------
1485# @function-internal java-pkg-init-compiler_ 1940# @function-internal java-pkg-init-compiler_
1486# 1941#
1828# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 2283# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1829# verify that the current VM is sufficient. 2284# verify that the current VM is sufficient.
1830# Setup the environment for the VM being used. 2285# Setup the environment for the VM being used.
1831# ------------------------------------------------------------------------------ 2286# ------------------------------------------------------------------------------
1832java-pkg_switch-vm() { 2287java-pkg_switch-vm() {
2288 debug-print-function ${FUNCNAME} $*
2289
1833 if java-pkg_needs-vm; then 2290 if java-pkg_needs-vm; then
1834 # Use the VM specified by JAVA_PKG_FORCE_VM 2291 # Use the VM specified by JAVA_PKG_FORCE_VM
1835 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then 2292 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1836 # If you're forcing the VM, I hope you know what your doing... 2293 # If you're forcing the VM, I hope you know what your doing...
2294 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1837 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 2295 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1838 # if we're allowed to switch the vm... 2296 # if we're allowed to switch the vm...
1839 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 2297 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1840 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}" 2298 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1841 if [[ -n ${JAVA_PKG_VNEED} ]]; then 2299 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1842 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2300 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1843 else 2301 else
1844 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2302 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1845 fi 2303 fi
1846 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then 2304 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
1847 eerror "Unable to determine VM for building from dependencies." 2305 eerror "Unable to determine VM for building from dependencies:"
1848 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}" 2306 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
1849 echo "VNEED: ${JAVA_PKG_VNEED}" 2307 echo "VNEED: ${JAVA_PKG_VNEED}"
2308 die "Failed to determine VM for building."
1850 else 2309 else
1851 export GENTOO_VM 2310 export GENTOO_VM
1852 fi 2311 fi
1853 # otherwise just make sure the current VM is sufficient 2312 # otherwise just make sure the current VM is sufficient
1854 else 2313 else
1920 einfo "Classes" 2379 einfo "Classes"
1921 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR}," 2380 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1922 fi 2381 fi
1923} 2382}
1924 2383
1925# TODO document 2384# ------------------------------------------------------------------------------
2385# @internal-function java-pkg_verify-classes
2386#
1926# Verify that the classes were compiled for the right source / target 2387# Verify that the classes were compiled for the right source / target. Dies if
2388# not.
2389# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2390# ------------------------------------------------------------------------------
1927java-pkg_verify-classes() { 2391java-pkg_verify-classes() {
1928 ebegin "Verifying java class versions"
1929 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 2392 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1930 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 2393 local target=$(java-pkg_get-target)
2394 local result
2395 local log="${T}/class-version-verify.log"
2396 if [[ -n "${1}" ]]; then
2397 class-version-verify.py -v -t ${target} "${1}" > "${log}"
1931 result=$? 2398 result=$?
1932 eend ${result}
1933 if [[ ${result} == 0 ]]; then
1934 einfo "All good"
1935 else 2399 else
1936 ewarn "Possible problem" 2400 ebegin "Verifying java class versions (target: ${target})"
1937 die "Bad class files found" 2401 class-version-verify.py -v -t ${target} -r "${D}" > "${log}"
2402 result=$?
2403 eend ${result}
2404 fi
2405 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2406 if [[ ${result} != 0 ]]; then
2407 eerror "Incorrect bytecode version found"
2408 [[ -n "${1}" ]] && eerror "in file: ${1}"
2409 eerror "See ${log} for more details."
2410 die "Incorrect bytecode found"
2411 fi
2412}
2413
2414# ----------------------------------------------------------------------------
2415# @internal-function java-pkg_ensure-dep
2416# Check that a package being used in jarfrom, getjars and getjar is contained
2417# within DEPEND or RDEPEND.
2418# @param $1 - empty - check both vars; "runtime" or "build" - check only
2419# RDEPEND, resp. DEPEND
2420# @param $2 - Package name and slot.
2421java-pkg_ensure-dep() {
2422 debug-print-function ${FUNCNAME} $*
2423
2424 local limit_to="${1}"
2425 local target_pkg="${2}"
2426 local dev_error=""
2427
2428 local stripped_pkg=$(echo "${target_pkg}" | sed \
2429 's/-[0-9]*\(\.[0-9]\)*$//')
2430
2431 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2432 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2433 dev_error="${dev_error} declared in DEPEND."
2434 if is-java-strict; then
2435 die "${dev_error}"
2436 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2437 eerror "${dev_error}"
2438 elog "Because you have this package installed the package will"
2439 elog "build without problems, but please report this to"
2440 elog "http://bugs.gentoo.org"
2441 fi
2442 fi
2443
2444 if [[ ${limit_to} != build && ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2445 dev_error="The ebuild is attempting to use ${target_pkg},"
2446 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND."
2447 if is-java-strict; then
2448 die "${dev_error}"
2449 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2450 eerror "${dev_error}"
2451 elog "The package will build without problems, but may fail to run"
2452 elog "if you don't have ${target_pkg} installed, so please report"
2453 elog "this to http://bugs.gentoo.org"
2454 fi
1938 fi 2455 fi
1939} 2456}
1940 2457
1941# ------------------------------------------------------------------------------ 2458# ------------------------------------------------------------------------------
1942# @section-end internal 2459# @section-end internal

Legend:
Removed from v.1.31  
changed lines
  Added in v.1.80

  ViewVC Help
Powered by ViewVC 1.1.20