/[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.70
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.70 2007/04/17 09:16:22 ali_bush 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
36# ----------------------------------------------------------------------------- 36# -----------------------------------------------------------------------------
37 37
38# Make sure we use java-config-2 38# Make sure we use java-config-2
39export WANT_JAVA_CONFIG="2" 39export WANT_JAVA_CONFIG="2"
40 40
41# 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# -----------------------------------------------------------------------------
42JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1" 66JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1"
43 67
44# ----------------------------------------------------------------------------- 68# -----------------------------------------------------------------------------
45# @variable-internal JAVA_PKG_E_DEPEND 69# @variable-internal JAVA_PKG_E_DEPEND
46# 70#
47# This is a convience variable to be used from the other java eclasses. This is 71# This is a convience variable to be used from the other java eclasses. This is
48# the version of java-config we want to use. We also need a recent version 72# the version of java-config we want to use. We also need a recent version
49# portage, that includes phase hooks. 73# portage, that includes phase hooks.
50# ----------------------------------------------------------------------------- 74# -----------------------------------------------------------------------------
51JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 ${JAVA_PKG_PORTAGE_DEP}" 75JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.31 ${JAVA_PKG_PORTAGE_DEP}"
52 76
53# ----------------------------------------------------------------------------- 77# -----------------------------------------------------------------------------
54# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 78# @variable-external JAVA_PKG_ALLOW_VM_CHANGE
55# @variable-default yes 79# @variable-default yes
56# 80#
130# @note This should only be used internally or for testing. 154# @note This should only be used internally or for testing.
131# @example Use jikes and javac, in that order 155# @example Use jikes and javac, in that order
132# JAVA_PKG_FORCE_COMPILER="jikes javac" 156# JAVA_PKG_FORCE_COMPILER="jikes javac"
133# ----------------------------------------------------------------------------- 157# -----------------------------------------------------------------------------
134 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
135# TODO document me 173# TODO document me
136JAVA_PKG_QA_VIOLATIONS=0 174JAVA_PKG_QA_VIOLATIONS=0
137 175
138# ----------------------------------------------------------------------------- 176# -----------------------------------------------------------------------------
139# @section-end variables 177# @section-end variables
146# 184#
147# 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
148# libraries, etc. 186# libraries, etc.
149# ----------------------------------------------------------------------------- 187# -----------------------------------------------------------------------------
150 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}
151 222
152# ----------------------------------------------------------------------------- 223# -----------------------------------------------------------------------------
153# @ebuild-function java-pkg_dojar 224# @ebuild-function java-pkg_dojar
154# 225#
155# Installs any number of jars. 226# Installs any number of jars.
174 # Create JARDEST if it doesn't exist 245 # Create JARDEST if it doesn't exist
175 dodir ${JAVA_PKG_JARDEST} 246 dodir ${JAVA_PKG_JARDEST}
176 247
177 local jar 248 local jar
178 # for each jar 249 # for each jar
179 for jar in "$@"; do 250 for jar in "${@}"; do
180 local jar_basename=$(basename "${jar}") 251 local jar_basename=$(basename "${jar}")
181 252
182 java-pkg_check-versioned-jar ${jar_basename} 253 java-pkg_check-versioned-jar ${jar_basename}
183 254
184 # check if it exists 255 # check if it exists
185 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
186 # install it into JARDEST if it's a non-symlink 264 # install it into JARDEST if it's a non-symlink
187 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
188 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 269 INSDESTTREE="${JAVA_PKG_JARDEST}" \
189 doins "${jar}" || die "failed to install ${jar}" 270 doins "${jar}" || die "failed to install ${jar}"
190 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 271 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
191 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}" 272 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}"
192 # make a symlink to the original jar if it's symlink 273 # make a symlink to the original jar if it's symlink
203 284
204 java-pkg_do_write_ 285 java-pkg_do_write_
205} 286}
206 287
207 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}
208 302
209# ------------------------------------------------------------------------------ 303# ------------------------------------------------------------------------------
210# @ebuild-function java-pkg_regjar 304# @ebuild-function java-pkg_regjar
211# 305#
212# Records an already installed jar in the package.env 306# Records an already installed jar in the package.env
243 [[ ${#} -lt 1 ]] && die "at least one argument needed" 337 [[ ${#} -lt 1 ]] && die "at least one argument needed"
244 338
245 java-pkg_init_paths_ 339 java-pkg_init_paths_
246 340
247 local jar jar_dir jar_file 341 local jar jar_dir jar_file
248 for jar in "$@"; do 342 for jar in "${@}"; do
249 # TODO use java-pkg_check-versioned-jar 343 # TODO use java-pkg_check-versioned-jar
250 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
251 # 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:
252 # imagine such call: 352 # imagine such call:
253 # java-pkg_regjar ${D}/opt/java/*.jar 353 # java-pkg_regjar ${D}/opt/java/*.jar
254 # such call will fall into this case (-e ${jar}) and will 354 # such call will fall into this case (-e ${jar}) and will
255 # record paths with ${D} in package.env 355 # record paths with ${D} in package.env
256 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 356 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 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
260 die "${jar} does not exist" 363 die "${jar} does not exist"
261 fi 364 fi
262 done 365 done
263 366
264 java-pkg_do_write_ 367 java-pkg_do_write_
265} 368}
266
267 369
268# ------------------------------------------------------------------------------ 370# ------------------------------------------------------------------------------
269# @ebuild-function java-pkg_newjar 371# @ebuild-function java-pkg_newjar
270# 372#
271# Installs a jar with a new name 373# Installs a jar with a new name
282 local original_jar="${1}" 384 local original_jar="${1}"
283 local new_jar="${2:-${PN}.jar}" 385 local new_jar="${2:-${PN}.jar}"
284 local new_jar_dest="${T}/${new_jar}" 386 local new_jar_dest="${T}/${new_jar}"
285 387
286 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 388 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
287 [[ ! -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!"
288 391
289 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}"
290 cp "${original_jar}" "${new_jar_dest}" \ 393 cp "${original_jar}" "${new_jar_dest}" \
291 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 394 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
292 java-pkg_dojar "${new_jar_dest}" 395 java-pkg_dojar "${new_jar_dest}"
341 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 444 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
342 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 445 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
343 # otherwise make a symlink to the symlink's origin 446 # otherwise make a symlink to the symlink's origin
344 else 447 else
345 # TODO use dosym 448 # TODO use dosym
449 ln -s "$(readlink "${lib}")" \
346 ln -s "$(readlink "${lib}")" "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")" 450 "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")"
347 debug-print "${lib} is a symlink, linking accordanly" 451 debug-print "${lib} is a symlink, linking accordanly"
348 fi 452 fi
349 # otherwise die 453 # otherwise die
350 else 454 else
351 die "${lib} does not exist" 455 die "${lib} does not exist"
492# FIXME apparently this fails if you give it an empty directories 596# FIXME apparently this fails if you give it an empty directories
493java-pkg_dosrc() { 597java-pkg_dosrc() {
494 debug-print-function ${FUNCNAME} $* 598 debug-print-function ${FUNCNAME} $*
495 599
496 [ ${#} -lt 1 ] && die "At least one argument needed" 600 [ ${#} -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 601
501 java-pkg_check-phase install 602 java-pkg_check-phase install
502 603
503 [[ ${#} -lt 1 ]] && die "At least one argument needed" 604 [[ ${#} -lt 1 ]] && die "At least one argument needed"
605
606 if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
607 local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
608 if is-java-strict; then
609 eerror "${msg}"
610 die "${msg}"
611 else
612 echo "${msg}"
613 echo "Please report this to http://bugs.gentoo.org."
614 fi
615 fi
504 616
505 java-pkg_init_paths_ 617 java-pkg_init_paths_
506 618
507 local zip_name="${PN}-src.zip" 619 local zip_name="${PN}-src.zip"
508 local zip_path="${T}/${zip_name}" 620 local zip_path="${T}/${zip_name}"
509 local dir 621 local dir
510 for dir in ${@}; do 622 for dir in "${@}"; do
511 local dir_parent=$(dirname "${dir}") 623 local dir_parent=$(dirname "${dir}")
512 local dir_name=$(basename "${dir}") 624 local dir_name=$(basename "${dir}")
513 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 625 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
514 zip -q -r ${zip_path} ${dir_name} -i '*.java' 626 zip -q -r ${zip_path} ${dir_name} -i '*.java'
515 local result=$? 627 local result=$?
540# @param $1 - filename of launcher to create 652# @param $1 - filename of launcher to create
541# @param $2 - options, as follows: 653# @param $2 - options, as follows:
542# --main the.main.class.too.start 654# --main the.main.class.too.start
543# --jar /the/jar/too/launch.jar or just <name>.jar 655# --jar /the/jar/too/launch.jar or just <name>.jar
544# --java_args 'Extra arguments to pass to java' 656# --java_args 'Extra arguments to pass to java'
545# --pkg_args 'Extra arguments too pass to the package' 657# --pkg_args 'Extra arguments to pass to the package'
546# --pwd 658# --pwd Directory the launcher changes to before executing java
547# -into 659# -into Directory to install the launcher to, instead of /usr/bin
548# -pre 660# -pre Prepend contents of this file to the launcher
549# ------------------------------------------------------------------------------ 661# ------------------------------------------------------------------------------
550java-pkg_dolauncher() { 662java-pkg_dolauncher() {
551 debug-print-function ${FUNCNAME} $* 663 debug-print-function ${FUNCNAME} $*
552 664
553 java-pkg_check-phase install 665 java-pkg_check-phase install
565 local var_tmp="${T}/launcher_variables_tmp" 677 local var_tmp="${T}/launcher_variables_tmp"
566 local target_dir pre 678 local target_dir pre
567 679
568 # Process the other the rest of the arguments 680 # Process the other the rest of the arguments
569 while [[ -n "${1}" && -n "${2}" ]]; do 681 while [[ -n "${1}" && -n "${2}" ]]; do
570 local var=${1} value=${2} 682 local var="${1}" value="${2}"
571 if [[ "${var:0:2}" == "--" ]]; then 683 if [[ "${var:0:2}" == "--" ]]; then
572 local var=${var:2} 684 local var=${var:2}
573 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}" 685 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
574 local gjl_${var}="${value}" 686 local gjl_${var}="${value}"
575 elif [[ "${var}" == "-into" ]]; then 687 elif [[ "${var}" == "-into" ]]; then
594 fi 706 fi
595 fi 707 fi
596 708
597 # Write the actual script 709 # Write the actual script
598 echo "#!/bin/bash" > "${target}" 710 echo "#!/bin/bash" > "${target}"
599 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 711 if [[ -n "${pre}" ]]; then
712 if [[ -f "${pre}" ]]; then
713 cat "${pre}" >> "${target}"
714 else
715 die "-pre specified file '${pre}' does not exist"
716 fi
717 fi
600 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 718 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
601 cat "${var_tmp}" >> "${target}" 719 cat "${var_tmp}" >> "${target}"
602 rm -f "${var_tmp}" 720 rm -f "${var_tmp}"
603 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 721 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
604 722
696# Example: get a specific jar from xerces slot 2, and name it diffrently 814# 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 815# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
698# Example: get junit.jar which is needed only for building 816# Example: get junit.jar which is needed only for building
699# java-pkg_jar-from --build-only junit junit.jar 817# java-pkg_jar-from --build-only junit junit.jar
700# 818#
701# @param $1 - (optional) "--build-only" makes the jar(s) not added into 819# @param $opt
702# package.env DEPEND line. 820# --build-only - makes the jar(s) not added into package.env DEPEND line.
821# (assumed automatically when called inside src_test)
822# --with-dependencies - get jars also from requested package's dependencies
823# transitively.
824# --into $dir - symlink jar(s) into $dir (must exist) instead of .
703# @param $1 - Package to get jars from. 825# @param $1 - Package to get jars from.
704# @param $2 - jar from package. If not specified, all jars will be used. 826# @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 827# @param $3 - When a single jar is specified, destination filename of the
706# symlink. Defaults to the name of the jar. 828# symlink. Defaults to the name of the jar.
707# ------------------------------------------------------------------------------ 829# ------------------------------------------------------------------------------
708# TODO could probably be cleaned up a little 830# TODO could probably be cleaned up a little
709java-pkg_jar-from() { 831java-pkg_jar-from() {
710 debug-print-function ${FUNCNAME} $* 832 debug-print-function ${FUNCNAME} $*
711 833
712 local build_only="" 834 local build_only=""
835 local destdir="."
836 local deep=""
713 837
838 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true"
839
840 while [[ "${1}" == --* ]]; do
714 if [[ "${1}" = "--build-only" ]]; then 841 if [[ "${1}" = "--build-only" ]]; then
715 build_only="true" 842 build_only="true"
843 elif [[ "${1}" = "--with-dependencies" ]]; then
844 deep="--with-dependencies"
845 elif [[ "${1}" = "--into" ]]; then
846 destdir="${2}"
847 shift
848 else
849 die "java-pkg_jar-from called with unknown parameter: ${1}"
850 fi
716 shift 851 shift
717 fi 852 done
718 853
719 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 854 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
720 855
721 [[ -z ${target_pkg} ]] && die "Must specify a package" 856 [[ -z ${target_pkg} ]] && die "Must specify a package"
722 857
723 # default destjar to the target jar 858 # default destjar to the target jar
724 [[ -z "${destjar}" ]] && destjar="${target_jar}" 859 [[ -z "${destjar}" ]] && destjar="${target_jar}"
725 860
726 local error_msg="There was a problem getting the classpath for ${target_pkg}." 861 local error_msg="There was a problem getting the classpath for ${target_pkg}."
727 local classpath 862 local classpath
728 classpath="$(java-config --classpath=${target_pkg})" 863 classpath="$(java-config ${deep} --classpath=${target_pkg})"
729 [[ $? != 0 ]] && die ${error_msg} 864 [[ $? != 0 ]] && die ${error_msg}
865
866 java-pkg_ensure-dep "${build_only}" "${target_pkg}"
867
868 pushd ${destdir} > /dev/null \
869 || die "failed to change directory to ${destdir}"
870
871 # When we have commas this functions is called to bring jars from multiple
872 # packages. This affects recording of dependencencies because that syntax uses :
873 # if we don't change them to : gjl and java-config -d -p break
874 if [[ ${target_pkg} = *,* ]]; then
875 build_only="true"
876 java-pkg_record-jar_ ${target_pkg//,/:}
877 fi
730 878
731 local jar 879 local jar
732 for jar in ${classpath//:/ }; do 880 for jar in ${classpath//:/ }; do
733 local jar_name=$(basename "${jar}") 881 local jar_name=$(basename "${jar}")
734 if [[ ! -f "${jar}" ]] ; then 882 if [[ ! -f "${jar}" ]] ; then
745 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 893 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
746 [[ -f "${destjar}" ]] && rm "${destjar}" 894 [[ -f "${destjar}" ]] && rm "${destjar}"
747 ln -snf "${jar}" "${destjar}" \ 895 ln -snf "${jar}" "${destjar}" \
748 || die "Failed to make symlink from ${jar} to ${destjar}" 896 || die "Failed to make symlink from ${jar} to ${destjar}"
749 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}" 897 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
898 popd > /dev/null
750 return 0 899 return 0
751 fi 900 fi
752 done 901 done
902 popd > /dev/null
753 # if no target was specified, we're ok 903 # if no target was specified, we're ok
754 if [[ -z "${target_jar}" ]] ; then 904 if [[ -z "${target_jar}" ]] ; then
755 return 0 905 return 0
756 # otherwise, die bitterly 906 # otherwise, die bitterly
757 else 907 else
781# Example: Get the classpath for xerces-2 and xalan, 931# Example: Get the classpath for xerces-2 and xalan,
782# java-pkg_getjars xerces-2,xalan 932# java-pkg_getjars xerces-2,xalan
783# Example Return: 933# Example Return:
784# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 934# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
785# 935#
786# @param $1 - (optional) "--build-only" makes the jar(s) not added into 936# @param $opt
787# package.env DEPEND line. 937# --build-only - makes the jar(s) not added into package.env DEPEND line.
938# (assumed automatically when called inside src_test)
939# --with-dependencies - get jars also from requested package's dependencies
940# transitively.
788# @param $2 - list of packages to get jars from 941# @param $1 - list of packages to get jars from
789# (passed to java-config --classpath) 942# (passed to java-config --classpath)
790# ------------------------------------------------------------------------------ 943# ------------------------------------------------------------------------------
791java-pkg_getjars() { 944java-pkg_getjars() {
792 debug-print-function ${FUNCNAME} $* 945 debug-print-function ${FUNCNAME} $*
793 946
794 [[ ${#} -lt 1 || ${#} -gt 2 ]] && die "${FUNCNAME} takes only one or two arguments" 947 local build_only=""
948 local deep=""
795 949
950 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true"
951
952 while [[ "${1}" == --* ]]; do
796 if [[ "${1}" = "--build-only" ]]; then 953 if [[ "${1}" = "--build-only" ]]; then
797 local build_only="true" 954 build_only="true"
955 elif [[ "${1}" = "--with-dependencies" ]]; then
956 deep="--with-dependencies"
957 else
958 die "java-pkg_jar-from called with unknown parameter: ${1}"
959 fi
798 shift 960 shift
799 fi 961 done
962
963 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
964
800 965
801 local classpath pkgs="${1}" 966 local classpath pkgs="${1}"
802 jars="$(java-config --classpath=${pkgs})" 967 jars="$(java-config ${deep} --classpath=${pkgs})"
803 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed" 968 [[ $? != 0 || -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed"
804 debug-print "${pkgs}:${jars}" 969 debug-print "${pkgs}:${jars}"
970
971 for pkg in "${pkgs//,/ }"; do
972 java-pkg_ensure-dep "${build_only}" "${pkg}"
973 done
805 974
806 if [[ -z "${classpath}" ]]; then 975 if [[ -z "${classpath}" ]]; then
807 classpath="${jars}" 976 classpath="${jars}"
808 else 977 else
809 classpath="${classpath}:${jars}" 978 classpath="${classpath}:${jars}"
834# @example 1003# @example
835# java-pkg_getjar xerces-2 xml-apis.jar 1004# java-pkg_getjar xerces-2 xml-apis.jar
836# @example-return 1005# @example-return
837# /usr/share/xerces-2/lib/xml-apis.jar 1006# /usr/share/xerces-2/lib/xml-apis.jar
838# 1007#
839# @param $1 - (optional) "--build-only" makes the jar not added into 1008# @param $opt
840# package.env DEPEND line. 1009# --build-only - makes the jar not added into package.env DEPEND line.
841# @param $1 - package to use 1010# @param $1 - package to use
842# @param $2 - jar to get 1011# @param $2 - jar to get
843# ------------------------------------------------------------------------------ 1012# ------------------------------------------------------------------------------
844java-pkg_getjar() { 1013java-pkg_getjar() {
845 debug-print-function ${FUNCNAME} $* 1014 debug-print-function ${FUNCNAME} $*
846 1015
847 local build_only="" 1016 local build_only=""
848 1017
1018 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true"
1019
1020 while [[ "${1}" == --* ]]; do
849 if [[ "${1}" = "--build-only" ]]; then 1021 if [[ "${1}" = "--build-only" ]]; then
850 build_only="true" 1022 build_only="true"
1023 else
1024 die "java-pkg_jar-from called with unknown parameter: ${1}"
1025 fi
851 shift 1026 shift
852 fi 1027 done
1028
1029 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
853 1030
854 local pkg="${1}" target_jar="${2}" jar 1031 local pkg="${1}" target_jar="${2}" jar
855 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 1032 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
856 [[ -z ${target_jar} ]] && die "Must specify jar to get" 1033 [[ -z ${target_jar} ]] && die "Must specify jar to get"
857 1034
858 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?" 1035 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
859 local classpath 1036 local classpath
860 classpath=$(java-config --classpath=${pkg}) 1037 classpath=$(java-config --classpath=${pkg})
861 [[ $? != 0 ]] && die ${error_msg} 1038 [[ $? != 0 ]] && die ${error_msg}
1039
1040 java-pkg_ensure-dep "${build_only}" "${pkg}"
862 1041
863 for jar in ${classpath//:/ }; do 1042 for jar in ${classpath//:/ }; do
864 if [[ ! -f "${jar}" ]] ; then 1043 if [[ ! -f "${jar}" ]] ; then
865 die "Installation problem with jar ${jar} in ${pkg} - is it installed?" 1044 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
866 fi 1045 fi
999# 1178#
1000# export DEPEND="${DEPEND} ${depstr}" 1179# export DEPEND="${DEPEND} ${depstr}"
1001# export RDEPEND="${RDEPEND} ${depstr}" 1180# export RDEPEND="${RDEPEND} ${depstr}"
1002#} 1181#}
1003 1182
1183# ------------------------------------------------------------------------------
1184# @ebuild-function java-pkg_find-normal-jars
1185#
1186# Find the files with suffix .jar file in the given directory or $WORKDIR
1187#
1188# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1189# ------------------------------------------------------------------------------
1190java-pkg_find-normal-jars() {
1191 local dir=$1
1192 [[ "${dir}" ]] || dir="${WORKDIR}"
1193 local found
1194 for jar in $(find "${dir}" -name "*.jar" -type f); do
1195 echo "${jar}"
1196 found="true"
1197 done
1198 [[ "${found}" ]]
1199 return $?
1200}
1201
1202# ------------------------------------------------------------------------------
1203# @ebuild-function java-pkg_ensure-no-bundled-jars
1204#
1205# 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 1206# This function should be called after WORKDIR has been populated with symlink
1005# TODO document 1207# to system jar files or bundled jars removed.
1208# ------------------------------------------------------------------------------
1006java-pkg_ensure-no-bundled-jars() { 1209java-pkg_ensure-no-bundled-jars() {
1007 debug-print-function ${FUNCNAME} $* 1210 debug-print-function ${FUNCNAME} $*
1008 pushd ${WORKDIR} >/dev/null 2>/dev/null
1009 1211
1010 local bundled_jars=$(find . -name "*.jar" -type f) 1212 local bundled_jars=$(java-pkg_find-normal-jars)
1011 if [[ -n ${bundled_jars} ]]; then 1213 if [[ -n ${bundled_jars} ]]; then
1012 echo "Bundled jars found:" 1214 echo "Bundled jars found:"
1013 local jar 1215 local jar
1014 for jar in ${bundled_jars}; do 1216 for jar in ${bundled_jars}; do
1015 echo $(pwd)${jar/./} 1217 echo $(pwd)${jar/./}
1016 done 1218 done
1017 die "Bundled jars found!" 1219 die "Bundled jars found!"
1018
1019 fi 1220 fi
1020 popd >/dev/null 2>/dev/null
1021} 1221}
1022 1222
1023# ------------------------------------------------------------------------------ 1223# ------------------------------------------------------------------------------
1024# @internal-function java-pkg_ensure-vm-version-sufficient 1224# @internal-function java-pkg_ensure-vm-version-sufficient
1025# 1225#
1174# @ebuild-function java-pkg_get-target 1374# @ebuild-function java-pkg_get-target
1175# 1375#
1176# Determines what target version should be used, for passing to -target. 1376# 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 1377# If you don't care about lower versions, you can set _WANT_TARGET to the
1178# version of your JDK. 1378# 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# 1379#
1183# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1380# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1184# ------------------------------------------------------------------------------ 1381# ------------------------------------------------------------------------------
1185java-pkg_get-target() { 1382java-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}")} 1383 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1199} 1384}
1200 1385
1201java-pkg_get-javac() { 1386java-pkg_get-javac() {
1202 debug-print-function ${FUNCNAME} $* 1387 debug-print-function ${FUNCNAME} $*
1203 1388
1292 die "No GCJ support found!" 1477 die "No GCJ support found!"
1293 fi 1478 fi
1294} 1479}
1295 1480
1296java-pkg_ensure-test() { 1481java-pkg_ensure-test() {
1297 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} && ! use test; then 1482 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \
1483 && hasq test ${IUSE} && ! use test;
1484 then
1298 eerror "You specified FEATURES=test, but USE=test is needed" 1485 eerror "You specified FEATURES=test, but USE=test is needed"
1299 eerror "to pull in the additional dependencies for testing" 1486 eerror "to pull in the additional dependencies for testing"
1300 die "Need USE=test enabled" 1487 die "Need USE=test enabled"
1301 fi 1488 fi
1302} 1489}
1303 1490
1304# ------------------------------------------------------------------------------ 1491# ------------------------------------------------------------------------------
1492# @ebuild-function java-pkg_register-ant-task
1493#
1494# Register this package as ant task, so that ant will load it when no specific
1495# ANT_TASKS are specified. Note that even without this registering, all packages
1496# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1497# packages, but can be also used by other ebuilds that used to symlink their
1498# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1499# compatibility.
1500#
1501# @param --version x.y Register only for ant version x.y (otherwise for any ant
1502# version). Used by the ant-* packages to prevent loading of mismatched
1503# ant-core ant tasks after core was updated, before the tasks are updated,
1504# without a need for blockers.
1505# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1506# ------------------------------------------------------------------------------
1507java-pkg_register-ant-task() {
1508 local TASKS_DIR="tasks"
1509
1510 # check for --version x.y parameters
1511 while [[ -n "${1}" && -n "${2}" ]]; do
1512 local var="${1#--}"
1513 local val="${2}"
1514 if [[ "${var}" == "version" ]]; then
1515 TASKS_DIR="tasks-${val}"
1516 else
1517 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1518 fi
1519 shift 2
1520 done
1521
1522 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1523
1524 dodir /usr/share/ant/${TASKS_DIR}
1525 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1526}
1527
1528# ------------------------------------------------------------------------------
1529# @internal-function java-pkg_ant-tasks-from-deps
1530#
1531# Function to determine ANT_TASKS from DEPEND variable for backwards
1532# compatibility with ebuilds that don't set ANT_TASKS before calling eant() or
1533# WANT_ANT_TASKS before inheriting java-pkg-2. If the DEPEND string contains
1534# "dev-java/ant" or "dev-java/ant-tasks", then it returns "all", otherwise
1535# "none". It's not smart enough to cope with USE flag depends but that shouldn't
1536# be a problem, the worst it can do is activace all tasks when not needed.
1537# Note that this is called only with JAVA_PKG_STRICT=1, to find ebuilds with
1538# insufficient dependencies, otherwise all available tasks are used for
1539# backwards compatilbility.
1540#
1541# @return "all" or "none"
1542# ------------------------------------------------------------------------------
1543java-pkg_ant-tasks-from-deps() {
1544 local found_ant found_ant_tasks
1545
1546 for dep in ${DEPEND}
1547 do
1548 local ant="$(awk '/(dev-java\/ant)/ { if (match($1, "(dev-java/ant)((-[0-9])+|$)", m)) print m[1] }' <<< ${dep})"
1549 [[ "${ant}" == "dev-java/ant" ]] && found_ant=true
1550 [[ "${dep}" == *"ant-tasks"* ]] && found_ant_tasks=true
1551 done
1552
1553 if [[ -n "${found_ant}" || -n "${found_ant_tasks}" ]]; then
1554 java-pkg_announce-qa-violation "The ebuild DEPENDS on deprecated ant or ant-tasks"
1555 echo "all"
1556 else
1557 # ebuild doesn't set ANT_TASKS and doesn't depend on ant-tasks or ant
1558 # so we deactivate all tasks that may be installed
1559 echo "none"
1560 fi
1561}
1562
1563# ------------------------------------------------------------------------------
1564# @internal-function java-pkg_ant-tasks-depend
1565#
1566# Translates the WANT_ANT_TASKS variable into valid dependencies.
1567# ------------------------------------------------------------------------------
1568java-pkg_ant-tasks-depend() {
1569 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1570
1571 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1572 local DEP=""
1573 for i in ${WANT_ANT_TASKS}
1574 do
1575 if [[ ${i} != ant-* ]]; then
1576 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1577 return 1
1578 fi
1579 DEP="${DEP}dev-java/${i} "
1580 done
1581 echo ${DEP}
1582 return 0
1583 else
1584 return 0
1585 fi
1586}
1587
1588# ------------------------------------------------------------------------------
1305# @section-end helper 1589# @section-end helper
1306# ------------------------------------------------------------------------------ 1590# ------------------------------------------------------------------------------
1307 1591
1308# ------------------------------------------------------------------------------ 1592# ------------------------------------------------------------------------------
1309# @section-begin build 1593# @section-begin build
1315 1599
1316# ------------------------------------------------------------------------------ 1600# ------------------------------------------------------------------------------
1317# @ebuild-function eant 1601# @ebuild-function eant
1318# 1602#
1319# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1603# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1320# compiler. 1604# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1321# 1605# variables:
1606# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1607# gentoo.classpath property. Be sure to call
1608# java-ant_rewrite-classpath in src_unpack.
1609# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1322# ------------------------------------------------------------------------------ 1610# ------------------------------------------------------------------------------
1323eant() { 1611eant() {
1324 debug-print-function ${FUNCNAME} $* 1612 debug-print-function ${FUNCNAME} $*
1325 1613
1326 # FIXME get this working 1614 # FIXME get this working
1327# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then 1615# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then
1328# java-pkg_announce-qa-violation \ 1616# java-pkg_announce-qa-violation \
1329# "Using eant, but not depending on dev-java/ant or dev-java/ant-core" 1617# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1330# fi 1618# fi
1331 1619
1332 local antflags 1620 if ! hasq java-ant-2 ${INHERITED} && is-java-strict; then
1621 local msg="You should inherit java-ant-2 when using eant"
1622 java-pkg_announce-qa-violation ${msg}
1623 die ${msg}
1624 fi
1625
1626 local antflags="-Dnoget=true -Dmaven.mode.offline=true"
1627
1333 java-pkg_init-compiler_ 1628 java-pkg_init-compiler_
1334 local compiler="${GENTOO_COMPILER}" 1629 local compiler="${GENTOO_COMPILER}"
1335 1630
1336 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1631 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1337 1632
1339 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1634 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1340 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1635 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1341 fi 1636 fi
1342 1637
1343 if [[ ${compiler} != "javac" ]]; then 1638 if [[ ${compiler} != "javac" ]]; then
1344 antflags="-Dbuild.compiler=${build_compiler}" 1639 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1345 # Figure out any extra stuff to put on the classpath for compilers aside 1640 # Figure out any extra stuff to put on the classpath for compilers aside
1346 # from javac 1641 # from javac
1347 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to 1642 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1348 # java-config -p 1643 # java-config -p
1349 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1644 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 1650 if is-java-strict; then
1356 einfo "Disabling system classpath for ant" 1651 einfo "Disabling system classpath for ant"
1357 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1652 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1358 fi 1653 fi
1359 1654
1360 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1655 for arg in "${@}"; do
1361 antflags="${antflags} -debug" 1656 if [[ ${arg} = -lib ]]; then
1657 if is-java-strict; then
1658 eerror "You should not use the -lib argument to eant because it will fail"
1659 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1660 eerror "or ant properties to make dependencies available."
1661 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1662 eerror "split ant (>=dev-java/ant-core-1.7)."
1663 die "eant -lib is deprecated/forbidden"
1664 else
1665 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1666 echo "more info."
1667 fi
1668 fi
1669 done
1670
1671 if has_version ">=dev-java/ant-core-1.7.0"; then
1672 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1673 ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}"
1674
1675 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1676 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1677
1678 if is-java-strict; then
1679 # if ant-tasks were not set by ebuild or forced, try to determine them from depends
1680 if [[ -z "${ANT_TASKS}" ]]; then
1681 ANT_TASKS="$(java-pkg_ant-tasks-from-deps)"
1682 fi
1683 else
1684 # if ant-tasks is not set by ebuild or forced, activate all of them
1685 ANT_TASKS="${ANT_TASKS:-all}"
1686 fi
1687
1688 # at this point, ANT_TASKS should be "all", "none" or explicit list
1689 if [[ "${ANT_TASKS}" == "all" ]]; then
1690 einfo "Using all available ANT_TASKS"
1691 elif [[ "${ANT_TASKS}" == "none" ]]; then
1692 einfo "Disabling all optional ANT_TASKS"
1693 else
1694 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1695 fi
1696
1697 export ANT_TASKS
1698 fi
1699
1700 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1701 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1702
1703 local gcp="${EANT_GENTOO_CLASSPATH}"
1704
1705 if [[ ${EBUILD_PHASE} = "test" ]]; then
1706 antflags="${antflags} -DJunit.present=true"
1707 [[ ${gcp} && ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1708 fi
1709
1710 local cp
1711
1712 for atom in ${gcp}; do
1713 cp="${cp}:$(java-pkg_getjars ${atom})"
1714 done
1715
1716 if [[ ${cp} ]]; then
1717 # It seems ant does not like single quotes around ${cp}
1718 antflags="${antflags} -Dgentoo.classpath=\"${cp#:}\""
1362 fi 1719 fi
1363 1720
1364 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1721 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1722 debug-print "Calling ant: ${antflags} ${@}"
1365 ant ${antflags} "${@}" || die "eant failed" 1723 ant ${antflags} "${@}" || die "eant failed"
1366 1724
1367} 1725}
1368 1726
1369# ------------------------------------------------------------------------------ 1727# ------------------------------------------------------------------------------
1440# ------------------------------------------------------------------------------ 1798# ------------------------------------------------------------------------------
1441use_doc() { 1799use_doc() {
1442 use doc && echo ${@:-javadoc} 1800 use doc && echo ${@:-javadoc}
1443} 1801}
1444 1802
1803
1445# ------------------------------------------------------------------------------ 1804# ------------------------------------------------------------------------------
1446# @section-end build 1805# @section-end build
1447# ------------------------------------------------------------------------------ 1806# ------------------------------------------------------------------------------
1448 1807
1449# ------------------------------------------------------------------------------ 1808# ------------------------------------------------------------------------------
1467# 1826#
1468# ----------------------------------------------------------------------------- 1827# -----------------------------------------------------------------------------
1469java-pkg_init() { 1828java-pkg_init() {
1470 unset JAVAC 1829 unset JAVAC
1471 unset JAVA_HOME 1830 unset JAVA_HOME
1831
1832 # People do all kinds of weird things.
1833 # http://forums.gentoo.org/viewtopic-p-3943166.html
1834 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
1835 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
1836 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
1837 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
1838 ewarn "sun-jdk vms and and as such break configure scripts that"
1839 ewarn "use it (for example app-office/openoffice) so we filter it out."
1840 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
1841 ewarn "make.conf for example) to silence this warning or"
1842 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
1843 fi
1844
1845 if [[ -z ${accept} ]]; then
1846 unset _JAVA_OPTIONS
1847 # phase hooks make this run many times without this
1848 I_WANT_GLOBAL_JAVA_OPTIONS="true"
1849 fi
1850
1472 java-pkg_init_paths_ 1851 java-pkg_init_paths_
1473 java-pkg_switch-vm 1852 java-pkg_switch-vm
1474 PATH=${JAVA_HOME}/bin:${PATH} 1853 PATH=${JAVA_HOME}/bin:${PATH}
1475 1854
1476 # TODO we will probably want to set JAVAC and JAVACFLAGS 1855 # TODO we will probably want to set JAVAC and JAVACFLAGS
1481 # When users have crazy classpaths some packages can fail to compile. 1860 # When users have crazy classpaths some packages can fail to compile.
1482 # and everything should work with empty CLASSPATH. 1861 # and everything should work with empty CLASSPATH.
1483 # This also helps prevent unexpected dependencies on random things 1862 # This also helps prevent unexpected dependencies on random things
1484 # from the CLASSPATH. 1863 # from the CLASSPATH.
1485 unset CLASSPATH 1864 unset CLASSPATH
1865
1866 # Unset external ANT_ stuff
1867 unset ANT_TASKS
1868 unset ANT_OPTS
1486} 1869}
1487 1870
1488# ------------------------------------------------------------------------------ 1871# ------------------------------------------------------------------------------
1489# @function-internal java-pkg-init-compiler_ 1872# @function-internal java-pkg-init-compiler_
1490# 1873#
1832# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 2215# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1833# verify that the current VM is sufficient. 2216# verify that the current VM is sufficient.
1834# Setup the environment for the VM being used. 2217# Setup the environment for the VM being used.
1835# ------------------------------------------------------------------------------ 2218# ------------------------------------------------------------------------------
1836java-pkg_switch-vm() { 2219java-pkg_switch-vm() {
2220 debug-print-function ${FUNCNAME} $*
2221
1837 if java-pkg_needs-vm; then 2222 if java-pkg_needs-vm; then
1838 # Use the VM specified by JAVA_PKG_FORCE_VM 2223 # Use the VM specified by JAVA_PKG_FORCE_VM
1839 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then 2224 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1840 # If you're forcing the VM, I hope you know what your doing... 2225 # If you're forcing the VM, I hope you know what your doing...
2226 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1841 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 2227 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1842 # if we're allowed to switch the vm... 2228 # if we're allowed to switch the vm...
1843 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 2229 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}" 2230 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1845 if [[ -n ${JAVA_PKG_VNEED} ]]; then 2231 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1925 einfo "Classes" 2311 einfo "Classes"
1926 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR}," 2312 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1927 fi 2313 fi
1928} 2314}
1929 2315
1930# TODO document 2316# ------------------------------------------------------------------------------
2317# @internal-function java-pkg_verify-classes
2318#
1931# Verify that the classes were compiled for the right source / target 2319# Verify that the classes were compiled for the right source / target. Dies if
2320# not.
2321# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2322# ------------------------------------------------------------------------------
1932java-pkg_verify-classes() { 2323java-pkg_verify-classes() {
1933 ebegin "Verifying java class versions"
1934 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 2324 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1935 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 2325 local target=$(java-pkg_get-target)
2326 local result
2327 local log="${T}/class-version-verify.log"
2328 if [[ -n "${1}" ]]; then
2329 class-version-verify.py -v -t ${target} "${1}" > "${log}"
1936 result=$? 2330 result=$?
1937 eend ${result}
1938 if [[ ${result} == 0 ]]; then
1939 einfo "All good"
1940 else 2331 else
1941 ewarn "Possible problem" 2332 ebegin "Verifying java class versions (target: ${target})"
1942 die "Bad class files found" 2333 class-version-verify.py -v -t ${target} -r "${D}" > "${log}"
2334 result=$?
2335 eend ${result}
2336 fi
2337 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2338 if [[ ${result} != 0 ]]; then
2339 eerror "Incorrect bytecode version found"
2340 [[ -n "${1}" ]] && eerror "in file: ${1}"
2341 eerror "See ${log} for more details."
2342 die "Incorrect bytecode found"
2343 fi
2344}
2345
2346# ----------------------------------------------------------------------------
2347# @internal-function java-pkg_ensure-dep
2348# Check that a package being used in jarfrom, getjars and getjar is contained
2349# within DEPEND or RDEPEND.
2350# @param $1 - Is the package a runtime dependency
2351# @param $2 - Package name and slot.
2352
2353java-pkg_ensure-dep() {
2354 debug-print-function ${FUNCNAME} $*
2355
2356 local build_only="${1}"
2357 local target_pkg="${2}"
2358 local dev_error=""
2359
2360 local stripped_pkg=$(echo "${target_pkg}" | sed \
2361 's/-[0-9]*\(\.[0-9]\)*$//')
2362
2363 if [[ ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2364 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2365 dev_error="${dev_error} declared in DEPEND."
2366 if is-java-strict; then
2367 die "${dev_error}"
2368 else
2369 eerror "${dev_error}"
2370 einfo "Because you have this package installed the package will"
2371 einfo "build without problems, but please report this to"
2372 einfo "http://bugs.gentoo.org"
2373 fi
2374 fi
2375
2376 if [[ -z ${build_only} && ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2377 dev_error="The ebuild is attempting to use ${target_pkg},"
2378 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND."
2379 if is-java-strict; then
2380 die "${error}"
2381 else
2382 eerror "${dev_error}"
2383 einfo "Because you have this package installed the package will"
2384 einfo "build without problems, but please report this to"
2385 einfo "http://bugs.gentoo.org"
2386 fi
1943 fi 2387 fi
1944} 2388}
1945 2389
1946# ------------------------------------------------------------------------------ 2390# ------------------------------------------------------------------------------
1947# @section-end internal 2391# @section-end internal

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

  ViewVC Help
Powered by ViewVC 1.1.20