/[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.43 Revision 1.127
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.43 2007/01/15 21:03:24 betelgeuse Exp $ 9# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.127 2009/05/19 21:23:32 caster Exp $
10
11 10
12# ----------------------------------------------------------------------------- 11# -----------------------------------------------------------------------------
13# @eclass-begin 12# @eclass-begin
14# @eclass-shortdesc Java Utility eclass 13# @eclass-shortdesc Java Utility eclass
15# @eclass-maintainer java@gentoo.org 14# @eclass-maintainer java@gentoo.org
36# ----------------------------------------------------------------------------- 35# -----------------------------------------------------------------------------
37 36
38# Make sure we use java-config-2 37# Make sure we use java-config-2
39export WANT_JAVA_CONFIG="2" 38export WANT_JAVA_CONFIG="2"
40 39
41# TODO document 40# -----------------------------------------------------------------------------
42JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1" 41# @variable-external WANT_ANT_TASKS
42# @variable-default ""
43#
44# An $IFS separated list of ant tasks.
45# Ebuild can specify this variable before inheriting java-ant-2 eclass to
46# determine ANT_TASKS it needs. They will be automatically translated to
47# DEPEND variable and ANT_TASKS variable. JAVA_PKG_FORCE_ANT_TASKS can override
48# ANT_TASKS set by WANT_ANT_TASKS, but not the DEPEND due to caching.
49# Ebuilds that need to depend conditionally on certain tasks and specify them
50# differently for different eant calls can't use this simplified approach.
51# You also cannot specify version or anything else than ant-*.
52#
53# @example WANT_ANT_TASKS="ant-junit ant-trax"
54#
55# @seealso JAVA_PKG_FORCE_ANT_TASKS
56# -----------------------------------------------------------------------------
57#WANT_ANT_TASKS
58
59# -----------------------------------------------------------------------------
60# @variable-internal JAVA_PKG_PORTAGE_DEP
61#
62# The version of portage we need to function properly. Previously it was
63# portage with phase hooks support but now we use a version with proper env
64# saving. For EAPI 2 we have new enough stuff so let's have cleaner deps.
65# -----------------------------------------------------------------------------
66hasq "${EAPI}" 0 1 && JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1.2.7"
43 67
44# ----------------------------------------------------------------------------- 68# -----------------------------------------------------------------------------
45# @variable-internal JAVA_PKG_E_DEPEND 69# @variable-internal JAVA_PKG_E_DEPEND
46# 70#
47# This is a convience variable to be used from the other java eclasses. This is 71# This is a convience variable to be used from the other java eclasses. This is
48# the version of java-config we want to use. We also need a recent version 72# the version of java-config we want to use. Usually the latest stable version
49# portage, that includes phase hooks. 73# so that ebuilds can use new features without depending on specific versions.
50# ----------------------------------------------------------------------------- 74# -----------------------------------------------------------------------------
51JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 ${JAVA_PKG_PORTAGE_DEP}" 75JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.1.6 ${JAVA_PKG_PORTAGE_DEP}"
76hasq source ${JAVA_PKG_IUSE} && JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} source? ( app-arch/zip )"
52 77
53# ----------------------------------------------------------------------------- 78# -----------------------------------------------------------------------------
54# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 79# @variable-external JAVA_PKG_ALLOW_VM_CHANGE
55# @variable-default yes 80# @variable-default yes
56# 81#
130# @note This should only be used internally or for testing. 155# @note This should only be used internally or for testing.
131# @example Use jikes and javac, in that order 156# @example Use jikes and javac, in that order
132# JAVA_PKG_FORCE_COMPILER="jikes javac" 157# JAVA_PKG_FORCE_COMPILER="jikes javac"
133# ----------------------------------------------------------------------------- 158# -----------------------------------------------------------------------------
134 159
160# -----------------------------------------------------------------------------
161# @variable-external JAVA_PKG_FORCE_ANT_TASKS
162#
163# An $IFS separated list of ant tasks. Can be set in environment before calling
164# emerge/ebuild to override variables set in ebuild, mainly for testing before
165# putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in
166# eant() call, not the dependencies specified in WANT_ANT_TASKS.
167#
168# @example JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \
169# ebuild foo.ebuild compile
170#
171# @seealso WANT_ANT_TASKS
172# -----------------------------------------------------------------------------
173
135# TODO document me 174# TODO document me
136JAVA_PKG_QA_VIOLATIONS=0 175JAVA_PKG_QA_VIOLATIONS=0
137 176
138# ----------------------------------------------------------------------------- 177# -----------------------------------------------------------------------------
139# @section-end variables 178# @section-end variables
146# 185#
147# These are used to install Java-related things, such as jars, Javadocs, JNI 186# These are used to install Java-related things, such as jars, Javadocs, JNI
148# libraries, etc. 187# libraries, etc.
149# ----------------------------------------------------------------------------- 188# -----------------------------------------------------------------------------
150 189
190# -----------------------------------------------------------------------------
191# @ebuild-function java-pkg_doexamples
192#
193# Installs given arguments to /usr/share/doc/${PF}/examples
194# If you give it only one parameter and it is a directory it will install
195# everything in that directory to the examples directory.
196#
197# @example
198# java-pkg_doexamples demo
199# java-pkg_doexamples demo/* examples/*
200#
201# @param --subdir - If the examples need a certain directory structure
202# @param $* - list of files to install
203# ------------------------------------------------------------------------------
204java-pkg_doexamples() {
205 debug-print-function ${FUNCNAME} $*
206
207 [[ ${#} -lt 1 ]] && die "At least one argument needed"
208
209 java-pkg_check-phase install
210
211 local dest=/usr/share/doc/${PF}/examples
212 if [[ ${1} == --subdir ]]; then
213 local dest=${dest}/${2}
214 dodir ${dest}
215 shift 2
216 fi
217
218 if [[ ${#} = 1 && -d ${1} ]]; then
219 ( # dont want to pollute calling env
220 insinto "${dest}"
221 doins -r ${1}/*
222 ) || die "Installing examples failed"
223 else
224 ( # dont want to pollute calling env
225 insinto "${dest}"
226 doins -r "$@"
227 ) || die "Installing examples failed"
228 fi
229}
151 230
152# ----------------------------------------------------------------------------- 231# -----------------------------------------------------------------------------
153# @ebuild-function java-pkg_dojar 232# @ebuild-function java-pkg_dojar
154# 233#
155# Installs any number of jars. 234# Installs any number of jars.
174 # Create JARDEST if it doesn't exist 253 # Create JARDEST if it doesn't exist
175 dodir ${JAVA_PKG_JARDEST} 254 dodir ${JAVA_PKG_JARDEST}
176 255
177 local jar 256 local jar
178 # for each jar 257 # for each jar
179 for jar in ${@}; do 258 for jar in "${@}"; do
180 local jar_basename=$(basename "${jar}") 259 local jar_basename=$(basename "${jar}")
181 260
182 java-pkg_check-versioned-jar ${jar_basename} 261 java-pkg_check-versioned-jar ${jar_basename}
183 262
184 # check if it exists 263 # check if it exists
190 ewarn "Overwriting ${dest}" 269 ewarn "Overwriting ${dest}"
191 fi 270 fi
192 271
193 # install it into JARDEST if it's a non-symlink 272 # install it into JARDEST if it's a non-symlink
194 if [[ ! -L "${jar}" ]] ; then 273 if [[ ! -L "${jar}" ]] ; then
274 #but first check class version when in strict mode.
275 is-java-strict && java-pkg_verify-classes "${jar}"
276
195 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 277 INSDESTTREE="${JAVA_PKG_JARDEST}" \
196 doins "${jar}" || die "failed to install ${jar}" 278 doins "${jar}" || die "failed to install ${jar}"
197 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 279 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
198 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}" 280 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}"
199 # make a symlink to the original jar if it's symlink 281 # make a symlink to the original jar if it's symlink
209 done 291 done
210 292
211 java-pkg_do_write_ 293 java-pkg_do_write_
212} 294}
213 295
214
215# ------------------------------------------------------------------------------ 296# ------------------------------------------------------------------------------
216# @internal-function depend-java-query 297# @internal-function depend-java-query
217# 298#
218# Wrapper for the depend-java-query binary to enable passing USE in env. 299# Wrapper for the depend-java-query binary to enable passing USE in env.
219# Using env variables keeps this eclass working with java-config versions that 300# Using env variables keeps this eclass working with java-config versions that
220# do not handle use flags. 301# do not handle use flags.
221# ------------------------------------------------------------------------------ 302# ------------------------------------------------------------------------------
222 303
223depend-java-query() { 304depend-java-query() {
305 # Used to have a which call here but it caused endless loops for some people
306 # that had some weird bashrc voodoo for which.
224 USE="${USE}" $(which depend-java-query) "${@}" 307 USE="${USE}" /usr/bin/depend-java-query "${@}"
225} 308}
226 309
227# ------------------------------------------------------------------------------ 310# ------------------------------------------------------------------------------
228# @ebuild-function java-pkg_regjar 311# @ebuild-function java-pkg_regjar
229# 312#
261 [[ ${#} -lt 1 ]] && die "at least one argument needed" 344 [[ ${#} -lt 1 ]] && die "at least one argument needed"
262 345
263 java-pkg_init_paths_ 346 java-pkg_init_paths_
264 347
265 local jar jar_dir jar_file 348 local jar jar_dir jar_file
266 for jar in ${@}; do 349 for jar in "${@}"; do
267 # TODO use java-pkg_check-versioned-jar 350 # TODO use java-pkg_check-versioned-jar
268 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then 351 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
269 [[ -d "${jar}" || -d "${D}${jar}" ]] \ 352 [[ -d "${jar}" || -d "${D}${jar}" ]] \
270 && die "Called ${FUNCNAME} on a directory $*" 353 && die "Called ${FUNCNAME} on a directory $*"
354
355 #check that class version correct when in strict mode
356 is-java-strict && java-pkg_verify-classes "${jar}"
357
271 # nelchael: we should strip ${D} in this case too, here's why: 358 # nelchael: we should strip ${D} in this case too, here's why:
272 # imagine such call: 359 # imagine such call:
273 # java-pkg_regjar ${D}/opt/java/*.jar 360 # java-pkg_regjar ${D}/opt/java/*.jar
274 # such call will fall into this case (-e ${jar}) and will 361 # such call will fall into this case (-e ${jar}) and will
275 # record paths with ${D} in package.env 362 # record paths with ${D} in package.env
276 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 363 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
277 else 364 else
365 if [[ ${jar} = *\** ]]; then
366 eerror "The argument ${jar} to ${FUNCNAME}"
367 eerror "has * in it. If you want it to glob in"
368 eerror '${D} add ${D} to the argument.'
369 fi
370 debug-print "${jar} or ${D}${jar} not found"
278 die "${jar} does not exist" 371 die "${jar} does not exist"
279 fi 372 fi
280 done 373 done
281 374
282 java-pkg_do_write_ 375 java-pkg_do_write_
299 local original_jar="${1}" 392 local original_jar="${1}"
300 local new_jar="${2:-${PN}.jar}" 393 local new_jar="${2:-${PN}.jar}"
301 local new_jar_dest="${T}/${new_jar}" 394 local new_jar_dest="${T}/${new_jar}"
302 395
303 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 396 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
304 [[ ! -f ${original_jar} ]] && die "${original_jar} does not exist!" 397 [[ ! -f ${original_jar} ]] \
398 && die "${original_jar} does not exist or is not a file!"
305 399
306 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 400 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
307 cp "${original_jar}" "${new_jar_dest}" \ 401 cp "${original_jar}" "${new_jar_dest}" \
308 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 402 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
309 java-pkg_dojar "${new_jar_dest}" 403 java-pkg_dojar "${new_jar_dest}"
336# @param $@ - JNI libraries to install 430# @param $@ - JNI libraries to install
337# ------------------------------------------------------------------------------ 431# ------------------------------------------------------------------------------
338java-pkg_doso() { 432java-pkg_doso() {
339 debug-print-function ${FUNCNAME} $* 433 debug-print-function ${FUNCNAME} $*
340 434
341 [[ ${#} -lt 1 ]] && "At least one argument required for ${FUNCNAME}"
342 java-pkg_check-phase install 435 java-pkg_check-phase install
343 436
344 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 437 [[ ${#} -lt 1 ]] && die "${FUNCNAME} requires at least one argument"
345 438
346 java-pkg_init_paths_ 439 java-pkg_init_paths_
347 440
348 local lib 441 local lib
349 # for each lib 442 # for each lib
352 if [[ -e "${lib}" ]] ; then 445 if [[ -e "${lib}" ]] ; then
353 # install if it isn't a symlink 446 # install if it isn't a symlink
354 if [[ ! -L "${lib}" ]] ; then 447 if [[ ! -L "${lib}" ]] ; then
355 INSDESTTREE="${JAVA_PKG_LIBDEST}" \ 448 INSDESTTREE="${JAVA_PKG_LIBDEST}" \
356 INSOPTIONS="${LIBOPTIONS}" \ 449 INSOPTIONS="${LIBOPTIONS}" \
357 doins "${lib}" || "failed to install ${lib}" 450 doins "${lib}" || die "failed to install ${lib}"
358 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 451 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
359 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 452 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
360 # otherwise make a symlink to the symlink's origin 453 # otherwise make a symlink to the symlink's origin
361 else 454 else
362 # TODO use dosym
363 ln -s "$(readlink "${lib}")" "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")" 455 dosym "$(readlink "${lib}")" "${JAVA_PKG_LIBDEST}/${lib##*/}"
364 debug-print "${lib} is a symlink, linking accordanly" 456 debug-print "${lib} is a symlink, linking accordantly"
365 fi 457 fi
366 # otherwise die 458 # otherwise die
367 else 459 else
368 die "${lib} does not exist" 460 die "${lib} does not exist"
369 fi 461 fi
385java-pkg_regso() { 477java-pkg_regso() {
386 debug-print-function ${FUNCNAME} $* 478 debug-print-function ${FUNCNAME} $*
387 479
388 java-pkg_check-phase install 480 java-pkg_check-phase install
389 481
390 [[ ${#} -lt 1 ]] && "at least one argument needed" 482 [[ ${#} -lt 1 ]] && die "${FUNCNAME} requires at least one argument"
391 483
392 java-pkg_init_paths_ 484 java-pkg_init_paths_
393 485
394 local lib target_dir 486 local lib target_dir
395 for lib in "$@" ; do 487 for lib in "$@" ; do
462# ------------------------------------------------------------------------------ 554# ------------------------------------------------------------------------------
463# @ebuild-function java-pkg_dojavadoc 555# @ebuild-function java-pkg_dojavadoc
464# 556#
465# Installs javadoc documentation. This should be controlled by the doc use flag. 557# Installs javadoc documentation. This should be controlled by the doc use flag.
466# 558#
559# @param $1: optional --symlink creates to symlink like this for html
560# documentation bundles.
467# @param $1: - The javadoc root directory. 561# @param $2: - The javadoc root directory.
468# 562#
469# @example: 563# @example:
470# java-pkg_dojavadoc docs/api 564# java-pkg_dojavadoc docs/api
565# java-pkg_dojavadoc --symlink apidocs docs/api
471# 566#
472# ------------------------------------------------------------------------------ 567# ------------------------------------------------------------------------------
473java-pkg_dojavadoc() { 568java-pkg_dojavadoc() {
569 debug-print-function ${FUNCNAME} $*
570
571 # For html documentation bundles that link to Javadoc
572 local symlink
573 if [[ ${1} = --symlink ]]; then
574 symlink=${2}
575 shift 2
576 fi
577
474 local dir="$1" 578 local dir="$1"
579 local dest=/usr/share/doc/${PF}/html
580
581 # QA checks
475 582
476 java-pkg_check-phase install 583 java-pkg_check-phase install
477 584
478 [[ -z "${dir}" ]] && die "Must specify a directory!" 585 [[ -z "${dir}" ]] && die "Must specify a directory!"
479 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!" 586 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!"
587 if [[ ! -e "${dir}/index.html" ]]; then
588 local msg="No index.html in javadoc directory"
589 ewarn "${msg}"
590 is-java-strict && die "${msg}"
591 fi
592
593 if [[ -e ${D}/${dest}/api ]]; then
594 eerror "${dest} already exists. Will not overwrite."
595 die "${dest}"
596 fi
597
598 # Renaming to match our directory layout
480 599
481 local dir_to_install="${dir}" 600 local dir_to_install="${dir}"
482 if [[ "$(basename "${dir}")" != "api" ]]; then 601 if [[ "$(basename "${dir}")" != "api" ]]; then
483 dir_to_install="${T}/api" 602 dir_to_install="${T}/api"
484 # TODO use doins 603 # TODO use doins
485 cp -r "${dir}" "${dir_to_install}" || die "cp failed" 604 cp -r "${dir}" "${dir_to_install}" || die "cp failed"
486 fi 605 fi
487 606
607 # Actual installation
608
488 java-pkg_dohtml -r ${dir_to_install} 609 java-pkg_dohtml -r "${dir_to_install}"
610
611 # Let's make a symlink to the directory we have everything else under
612 dosym ${dest}/api "${JAVA_PKG_SHAREPATH}/api" || die
613
614 if [[ ${symlink} ]]; then
615 debug-print "symlinking ${dest}/{api,${symlink}}"
616 dosym ${dest}/{api,${symlink}} || die
617 fi
489} 618}
490 619
491# ------------------------------------------------------------------------------ 620# ------------------------------------------------------------------------------
492# @ebuild-function java-pkg_dosrc 621# @ebuild-function java-pkg_dosrc
493# 622#
509# FIXME apparently this fails if you give it an empty directories 638# FIXME apparently this fails if you give it an empty directories
510java-pkg_dosrc() { 639java-pkg_dosrc() {
511 debug-print-function ${FUNCNAME} $* 640 debug-print-function ${FUNCNAME} $*
512 641
513 [ ${#} -lt 1 ] && die "At least one argument needed" 642 [ ${#} -lt 1 ] && die "At least one argument needed"
514 if ! hasq source ${IUSE}; then
515 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
516 fi
517 643
518 java-pkg_check-phase install 644 java-pkg_check-phase install
519 645
520 [[ ${#} -lt 1 ]] && die "At least one argument needed" 646 [[ ${#} -lt 1 ]] && die "At least one argument needed"
647
648 if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
649 local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
650 java-pkg_announce-qa-violation ${msg}
651 fi
521 652
522 java-pkg_init_paths_ 653 java-pkg_init_paths_
523 654
524 local zip_name="${PN}-src.zip" 655 local zip_name="${PN}-src.zip"
525 local zip_path="${T}/${zip_name}" 656 local zip_path="${T}/${zip_name}"
526 local dir 657 local dir
527 for dir in ${@}; do 658 for dir in "${@}"; do
528 local dir_parent=$(dirname "${dir}") 659 local dir_parent=$(dirname "${dir}")
529 local dir_name=$(basename "${dir}") 660 local dir_name=$(basename "${dir}")
530 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 661 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
531 zip -q -r ${zip_path} ${dir_name} -i '*.java' 662 zip -q -r ${zip_path} ${dir_name} -i '*.java'
532 local result=$? 663 local result=$?
719# Example: get a specific jar from xerces slot 2, and name it diffrently 850# Example: get a specific jar from xerces slot 2, and name it diffrently
720# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 851# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
721# Example: get junit.jar which is needed only for building 852# Example: get junit.jar which is needed only for building
722# java-pkg_jar-from --build-only junit junit.jar 853# java-pkg_jar-from --build-only junit junit.jar
723# 854#
724# @param $1 - (optional) "--build-only" makes the jar(s) not added into 855# @param $opt
725# package.env DEPEND line. 856# --build-only - makes the jar(s) not added into package.env DEPEND line.
726# @param $1 - Package to get jars from. 857# (assumed automatically when called inside src_test)
858# --with-dependencies - get jars also from requested package's dependencies
859# transitively.
860# --virtual - Packages passed to this function are to be handled as virtuals
861# and will not have individual jar dependencies recorded.
862# --into $dir - symlink jar(s) into $dir (must exist) instead of .
863# @param $1 - Package to get jars from, or comma-separated list of packages in
864# case other parameters are not used.
727# @param $2 - jar from package. If not specified, all jars will be used. 865# @param $2 - jar from package. If not specified, all jars will be used.
728# @param $3 - When a single jar is specified, destination filename of the 866# @param $3 - When a single jar is specified, destination filename of the
729# symlink. Defaults to the name of the jar. 867# symlink. Defaults to the name of the jar.
730# ------------------------------------------------------------------------------ 868# ------------------------------------------------------------------------------
731# TODO could probably be cleaned up a little 869# TODO could probably be cleaned up a little
732java-pkg_jar-from() { 870java-pkg_jar-from() {
733 debug-print-function ${FUNCNAME} $* 871 debug-print-function ${FUNCNAME} $*
734 872
735 local build_only="" 873 local build_only=""
874 local destdir="."
875 local deep=""
876 local virtual=""
736 877
878 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
879
880 while [[ "${1}" == --* ]]; do
737 if [[ "${1}" = "--build-only" ]]; then 881 if [[ "${1}" = "--build-only" ]]; then
738 build_only="true" 882 build_only="build"
883 elif [[ "${1}" = "--with-dependencies" ]]; then
884 deep="--with-dependencies"
885 elif [[ "${1}" = "--virtual" ]]; then
886 virtual="true"
887 elif [[ "${1}" = "--into" ]]; then
888 destdir="${2}"
889 shift
890 else
891 die "java-pkg_jar-from called with unknown parameter: ${1}"
892 fi
739 shift 893 shift
740 fi 894 done
741
742 if [[ "${1}" = "--with-dependencies" ]]; then
743 local deep="--with-dependencies"
744 shift
745 fi
746 895
747 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 896 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
748 897
749 [[ -z ${target_pkg} ]] && die "Must specify a package" 898 [[ -z ${target_pkg} ]] && die "Must specify a package"
899
900 if [[ "${EAPI}" == "1" ]]; then
901 target_pkg="${target_pkg//:/-}"
902 fi
750 903
751 # default destjar to the target jar 904 # default destjar to the target jar
752 [[ -z "${destjar}" ]] && destjar="${target_jar}" 905 [[ -z "${destjar}" ]] && destjar="${target_jar}"
753 906
754 local error_msg="There was a problem getting the classpath for ${target_pkg}." 907 local error_msg="There was a problem getting the classpath for ${target_pkg}."
755 local classpath 908 local classpath
756 classpath="$(java-config ${deep} --classpath=${target_pkg})" 909 classpath="$(java-config ${deep} --classpath=${target_pkg})"
757 [[ $? != 0 ]] && die ${error_msg} 910 [[ $? != 0 ]] && die ${error_msg}
911
912 # When we have commas this functions is called to bring jars from multiple
913 # packages. This affects recording of dependencencies performed later
914 # which expects one package only, so we do it here.
915 if [[ ${target_pkg} = *,* ]]; then
916 for pkg in ${target_pkg//,/ }; do
917 java-pkg_ensure-dep "${build_only}" "${pkg}"
918 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
919 done
920 # setting this disables further record-jar_ calls later
921 build_only="build"
922 else
923 java-pkg_ensure-dep "${build_only}" "${target_pkg}"
924 fi
925
926 # Record the entire virtual as a dependency so that
927 # no jars are missed.
928 if [[ -z "${build_only}" && -n "${virtual}" ]]; then
929 java-pkg_record-jar_ "${target_pkg}"
930 # setting this disables further record-jars_ calls later
931 build_only="build"
932 fi
933
934 pushd ${destdir} > /dev/null \
935 || die "failed to change directory to ${destdir}"
758 936
759 local jar 937 local jar
760 for jar in ${classpath//:/ }; do 938 for jar in ${classpath//:/ }; do
761 local jar_name=$(basename "${jar}") 939 local jar_name=$(basename "${jar}")
762 if [[ ! -f "${jar}" ]] ; then 940 if [[ ! -f "${jar}" ]] ; then
773 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 951 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
774 [[ -f "${destjar}" ]] && rm "${destjar}" 952 [[ -f "${destjar}" ]] && rm "${destjar}"
775 ln -snf "${jar}" "${destjar}" \ 953 ln -snf "${jar}" "${destjar}" \
776 || die "Failed to make symlink from ${jar} to ${destjar}" 954 || die "Failed to make symlink from ${jar} to ${destjar}"
777 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}" 955 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
956 popd > /dev/null
778 return 0 957 return 0
779 fi 958 fi
780 done 959 done
960 popd > /dev/null
781 # if no target was specified, we're ok 961 # if no target was specified, we're ok
782 if [[ -z "${target_jar}" ]] ; then 962 if [[ -z "${target_jar}" ]] ; then
783 return 0 963 return 0
784 # otherwise, die bitterly 964 # otherwise, die bitterly
785 else 965 else
809# Example: Get the classpath for xerces-2 and xalan, 989# Example: Get the classpath for xerces-2 and xalan,
810# java-pkg_getjars xerces-2,xalan 990# java-pkg_getjars xerces-2,xalan
811# Example Return: 991# Example Return:
812# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 992# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
813# 993#
814# @param $1 - (optional) "--build-only" makes the jar(s) not added into 994# @param $opt
815# package.env DEPEND line. 995# --build-only - makes the jar(s) not added into package.env DEPEND line.
996# (assumed automatically when called inside src_test)
997# --with-dependencies - get jars also from requested package's dependencies
998# transitively.
816# @param $2 - list of packages to get jars from 999# @param $1 - list of packages to get jars from
817# (passed to java-config --classpath) 1000# (passed to java-config --classpath)
818# ------------------------------------------------------------------------------ 1001# ------------------------------------------------------------------------------
819java-pkg_getjars() { 1002java-pkg_getjars() {
820 debug-print-function ${FUNCNAME} $* 1003 debug-print-function ${FUNCNAME} $*
821 1004
1005 local build_only=""
1006 local deep=""
1007
1008 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1009
1010 while [[ "${1}" == --* ]]; do
822 if [[ "${1}" = "--build-only" ]]; then 1011 if [[ "${1}" = "--build-only" ]]; then
823 local build_only="true" 1012 build_only="build"
1013 elif [[ "${1}" = "--with-dependencies" ]]; then
1014 deep="--with-dependencies"
1015 else
1016 die "java-pkg_jar-from called with unknown parameter: ${1}"
1017 fi
824 shift 1018 shift
825 fi 1019 done
826 1020
827 if [[ "${1}" = "--with-dependencies" ]]; then
828 local deep="--with-dependencies"
829 shift
830 fi
831
832 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --build-only" 1021 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
833 1022
1023
834 local classpath pkgs="${1}" 1024 local pkgs="${1}"
1025
1026 if [[ "${EAPI}" == "1" ]]; then
1027 pkgs="${pkgs//:/-}"
1028 fi
1029
835 jars="$(java-config ${deep} --classpath=${pkgs})" 1030 jars="$(java-config ${deep} --classpath=${pkgs})"
836 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed" 1031 [[ $? != 0 ]] && die "java-config --classpath=${pkgs} failed"
837 debug-print "${pkgs}:${jars}" 1032 debug-print "${pkgs}:${jars}"
838 1033
839 if [[ -z "${classpath}" ]]; then 1034 for pkg in ${pkgs//,/ }; do
840 classpath="${jars}" 1035 java-pkg_ensure-dep "${build_only}" "${pkg}"
841 else 1036 done
842 classpath="${classpath}:${jars}"
843 fi
844 1037
845 # Only record jars that aren't build-only 1038 # Only record jars that aren't build-only
846 if [[ -z "${build_only}" ]]; then 1039 if [[ -z "${build_only}" ]]; then
847 oldifs="${IFS}"
848 IFS=","
849 for pkg in ${pkgs}; do 1040 for pkg in ${pkgs//,/ }; do
850 java-pkg_record-jar_ "${pkg}" 1041 java-pkg_record-jar_ "${pkg}"
851 done 1042 done
852 IFS="${oldifs}"
853 fi 1043 fi
854 1044
855 echo "${classpath}" 1045 echo "${jars}"
856} 1046}
857 1047
858# ------------------------------------------------------------------------------ 1048# ------------------------------------------------------------------------------
859# @ebuild-function java-pkg_getjar 1049# @ebuild-function java-pkg_getjar
860# 1050#
867# @example 1057# @example
868# java-pkg_getjar xerces-2 xml-apis.jar 1058# java-pkg_getjar xerces-2 xml-apis.jar
869# @example-return 1059# @example-return
870# /usr/share/xerces-2/lib/xml-apis.jar 1060# /usr/share/xerces-2/lib/xml-apis.jar
871# 1061#
872# @param $1 - (optional) "--build-only" makes the jar not added into 1062# @param $opt
873# package.env DEPEND line. 1063# --build-only - makes the jar not added into package.env DEPEND line.
1064# --virtual - Packages passed to this function are to be handled as virtuals
1065# and will not have individual jar dependencies recorded.
874# @param $1 - package to use 1066# @param $1 - package to use
875# @param $2 - jar to get 1067# @param $2 - jar to get
876# ------------------------------------------------------------------------------ 1068# ------------------------------------------------------------------------------
877java-pkg_getjar() { 1069java-pkg_getjar() {
878 debug-print-function ${FUNCNAME} $* 1070 debug-print-function ${FUNCNAME} $*
879 1071
880 local build_only="" 1072 local build_only=""
1073 local virtual=""
881 1074
1075 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1076
1077 while [[ "${1}" == --* ]]; do
882 if [[ "${1}" = "--build-only" ]]; then 1078 if [[ "${1}" = "--build-only" ]]; then
883 build_only="true" 1079 build_only="build"
1080 elif [[ "${1}" == "--virtual" ]]; then
1081 virtual="true"
1082 else
1083 die "java-pkg_getjar called with unknown parameter: ${1}"
1084 fi
884 shift 1085 shift
885 fi 1086 done
1087
1088 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
886 1089
887 local pkg="${1}" target_jar="${2}" jar 1090 local pkg="${1}" target_jar="${2}" jar
1091
1092 if [[ "${EAPI}" == "1" ]]; then
1093 pkg="${pkg//:/-}"
1094 fi
1095
888 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 1096 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
889 [[ -z ${target_jar} ]] && die "Must specify jar to get" 1097 [[ -z ${target_jar} ]] && die "Must specify jar to get"
890 1098
891 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?" 1099 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
892 local classpath 1100 local classpath
893 classpath=$(java-config --classpath=${pkg}) 1101 classpath=$(java-config --classpath=${pkg})
894 [[ $? != 0 ]] && die ${error_msg} 1102 [[ $? != 0 ]] && die ${error_msg}
1103
1104 java-pkg_ensure-dep "${build_only}" "${pkg}"
1105
1106 # Record the package(Virtual) as a dependency and then set build_only
1107 # So that individual jars are not recorded.
1108 if [[ -n "${virtual}" ]]; then
1109 java-pkg_record-jar_ "${pkg}"
1110 build_only="true"
1111 fi
895 1112
896 for jar in ${classpath//:/ }; do 1113 for jar in ${classpath//:/ }; do
897 if [[ ! -f "${jar}" ]] ; then 1114 if [[ ! -f "${jar}" ]] ; then
898 die "Installation problem with jar ${jar} in ${pkg} - is it installed?" 1115 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
899 fi 1116 fi
906 fi 1123 fi
907 done 1124 done
908 1125
909 die "Could not find ${target_jar} in ${pkg}" 1126 die "Could not find ${target_jar} in ${pkg}"
910 return 1 1127 return 1
1128}
1129
1130# ------------------------------------------------------------------------------
1131# @ebuild-function java-pkg_register-dependency
1132#
1133# Registers runtime dependency on a package, list of packages, or a single jar
1134# from a package, into package.env DEPEND line. Can only be called in
1135# src_install phase.
1136# Intended for binary packages where you don't need to symlink the jars or get
1137# their classpath during build. As such, the dependencies only need to be
1138# specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1139#
1140# @param $1 - comma-separated list of packages, or a single package
1141# @param $2 - if param $1 is a single package, optionally specify the jar
1142# to depend on
1143#
1144# Example: Record the dependency on whole xerces-2 and xalan,
1145# java-pkg_register-dependency xerces-2,xalan
1146# Example: Record the dependency on ant.jar from ant-core
1147# java-pkg_register-dependency ant-core ant.jar
1148#
1149# Note: Passing both list of packages as the first parameter AND specifying the
1150# jar as the second is not allowed and will cause the function to die. We assume
1151# that there's more chance one passes such combination as a mistake, than that
1152# there are more packages providing identically named jar without class
1153# collisions.
1154# ------------------------------------------------------------------------------
1155java-pkg_register-dependency() {
1156 debug-print-function ${FUNCNAME} $*
1157
1158 java-pkg_check-phase install
1159
1160 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1161
1162 local pkgs="${1}"
1163 local jar="${2}"
1164
1165 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1166
1167 if [[ "${EAPI}" == "1" ]]; then
1168 pkgs="${pkgs//:/-}"
1169 fi
1170
1171 if [[ -z "${jar}" ]]; then
1172 for pkg in ${pkgs//,/ }; do
1173 java-pkg_ensure-dep runtime "${pkg}"
1174 java-pkg_record-jar_ "${pkg}"
1175 done
1176 else
1177 [[ ${pkgs} == *,* ]] && \
1178 die "${FUNCNAME} called with both package list and jar name"
1179 java-pkg_ensure-dep runtime "${pkgs}"
1180 java-pkg_record-jar_ "${pkgs}" "${jar}"
1181 fi
1182
1183 java-pkg_do_write_
1184}
1185
1186# ------------------------------------------------------------------------------
1187# @ebuild-function java-pkg_register-optional-dependency
1188#
1189# Registers optional runtime dependency on a package, list of packages, or a
1190# single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be
1191# called in src_install phase.
1192# Intended for packages that can use other packages when those are in classpath.
1193# Will be put on classpath by launcher if they are installed. Typical case is
1194# JDBC implementations for various databases. It's better than having USE flag
1195# for each implementation triggering hard dependency.
1196#
1197# @param $1 - comma-separated list of packages, or a single package
1198# @param $2 - if param $1 is a single package, optionally specify the jar
1199# to depend on
1200#
1201# Example: Record the optional dependency on some jdbc providers
1202# java-pkg_register-optional-dependency jdbc-jaybird,jtds-1.2,jdbc-mysql
1203#
1204# Note: Passing both list of packages as the first parameter AND specifying the
1205# jar as the second is not allowed and will cause the function to die. We assume
1206# that there's more chance one passes such combination as a mistake, than that
1207# there are more packages providing identically named jar without class
1208# collisions.
1209# ------------------------------------------------------------------------------
1210java-pkg_register-optional-dependency() {
1211 debug-print-function ${FUNCNAME} $*
1212
1213 java-pkg_check-phase install
1214
1215 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1216
1217 local pkgs="${1}"
1218 local jar="${2}"
1219
1220 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1221
1222 if [[ "${EAPI}" == "1" ]]; then
1223 pkgs="${pkgs//:/-}"
1224 fi
1225
1226 if [[ -z "${jar}" ]]; then
1227 for pkg in ${pkgs//,/ }; do
1228 java-pkg_record-jar_ --optional "${pkg}"
1229 done
1230 else
1231 [[ ${pkgs} == *,* ]] && \
1232 die "${FUNCNAME} called with both package list and jar name"
1233 java-pkg_record-jar_ --optional "${pkgs}" "${jar}"
1234 fi
1235
1236 java-pkg_do_write_
1237}
1238
1239# ------------------------------------------------------------------------------
1240# @ebuild-function java-pkg_register-environment-variable
1241#
1242# Register an arbitrary environment variable into package.env. The gjl launcher
1243# for this package or any package depending on this will export it into
1244# environement before executing java command.
1245# Must only be called in src_install phase.
1246#
1247# @param $1 - variable name
1248# @param $2 - variable value
1249# ------------------------------------------------------------------------------
1250JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
1251JAVA_PKG_EXTRA_ENV_VARS=""
1252java-pkg_register-environment-variable() {
1253 debug-print-function ${FUNCNAME} $*
1254
1255 java-pkg_check-phase install
1256
1257 [[ ${#} != 2 ]] && die "${FUNCNAME} takes two arguments"
1258
1259 echo "${1}=\"${2}\"" >> ${JAVA_PKG_EXTRA_ENV}
1260 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
1261
1262 java-pkg_do_write_
911} 1263}
912 1264
913# This function reads stdin, and based on that input, figures out how to 1265# This function reads stdin, and based on that input, figures out how to
914# populate jars from the filesystem. 1266# populate jars from the filesystem.
915# Need to figure out a good way of making use of this, ie be able to use a 1267# Need to figure out a good way of making use of this, ie be able to use a
1341 die "Need USE=test enabled" 1693 die "Need USE=test enabled"
1342 fi 1694 fi
1343} 1695}
1344 1696
1345# ------------------------------------------------------------------------------ 1697# ------------------------------------------------------------------------------
1698# @ebuild-function java-pkg_register-ant-task
1699#
1700# Register this package as ant task, so that ant will load it when no specific
1701# ANT_TASKS are specified. Note that even without this registering, all packages
1702# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1703# packages, but can be also used by other ebuilds that used to symlink their
1704# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1705# compatibility.
1706#
1707# @param --version x.y Register only for ant version x.y (otherwise for any ant
1708# version). Used by the ant-* packages to prevent loading of mismatched
1709# ant-core ant tasks after core was updated, before the tasks are updated,
1710# without a need for blockers.
1711# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1712# ------------------------------------------------------------------------------
1713java-pkg_register-ant-task() {
1714 local TASKS_DIR="tasks"
1715
1716 # check for --version x.y parameters
1717 while [[ -n "${1}" && -n "${2}" ]]; do
1718 local var="${1#--}"
1719 local val="${2}"
1720 if [[ "${var}" == "version" ]]; then
1721 TASKS_DIR="tasks-${val}"
1722 else
1723 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1724 fi
1725 shift 2
1726 done
1727
1728 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1729
1730 dodir /usr/share/ant/${TASKS_DIR}
1731 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1732}
1733
1734# ------------------------------------------------------------------------------
1735# @internal-function java-pkg_ant-tasks-depend
1736#
1737# Translates the WANT_ANT_TASKS variable into valid dependencies.
1738# ------------------------------------------------------------------------------
1739java-pkg_ant-tasks-depend() {
1740 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1741
1742 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1743 local DEP=""
1744 for i in ${WANT_ANT_TASKS}
1745 do
1746 if [[ ${i} = ant-* ]]; then
1747 DEP="${DEP}dev-java/${i} "
1748 elif [[ ${i} = */*:* ]]; then
1749 DEP="${DEP}${i} "
1750 else
1751 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1752 return 1
1753 fi
1754 done
1755 echo ${DEP}
1756 return 0
1757 else
1758 return 0
1759 fi
1760}
1761
1762# ------------------------------------------------------------------------------
1763# @ebuild-function ejunit
1764#
1765# Junit wrapper function. Makes it easier to run the tests and checks for
1766# dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner.
1767#
1768# Examples:
1769# ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1770# ejunit org.blinkenlights.jid3.test.AllTests
1771#
1772# @param $1 - -cp or -classpath
1773# @param $2 - classpath; junit and recorded dependencies get appended
1774# @param $@ - the rest of the parameters are passed to java
1775# ------------------------------------------------------------------------------
1776ejunit() {
1777 debug-print-function ${FUNCNAME} $*
1778
1779 local pkgs
1780 if [[ -f ${JAVA_PKG_DEPEND_FILE} ]]; then
1781 for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
1782 pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
1783 done
1784 fi
1785
1786 local cp=$(java-pkg_getjars --with-dependencies junit${pkgs})
1787 if [[ ${1} = -cp || ${1} = -classpath ]]; then
1788 cp="${2}:${cp}"
1789 shift 2
1790 else
1791 cp=".:${cp}"
1792 fi
1793
1794 local runner=junit.textui.TestRunner
1795 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}"
1796 java -cp "${cp}" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
1797}
1798
1799# ------------------------------------------------------------------------------
1346# @section-end helper 1800# @section-end helper
1347# ------------------------------------------------------------------------------ 1801# ------------------------------------------------------------------------------
1802
1803# ------------------------------------------------------------------------------
1804# @eclass-src_prepare
1805#
1806# src_prepare Searches for bundled jars
1807# Don't call directly, but via java-pkg-2_src_prepare!
1808# ------------------------------------------------------------------------------
1809
1810java-utils-2_src_prepare() {
1811 [[ ${EBUILD_PHASE} == prepare ]] &&
1812 java-pkg_func-exists java_prepare && java_prepare
1813
1814 # Remember that eant will call this unless called via Portage
1815 if [[ ! -e "${T}/java-utils-2_src_prepare-run" ]] && is-java-strict; then
1816 echo "Searching for bundled jars:"
1817 java-pkg_find-normal-jars || echo "None found."
1818 echo "Searching for bundled classes (no output if none found):"
1819 find "${WORKDIR}" -name "*.class"
1820 echo "Search done."
1821 fi
1822 touch "${T}/java-utils-2_src_prepare-run"
1823}
1824
1825# ------------------------------------------------------------------------------
1826# @eclass-pkg_preinst
1827#
1828# pkg_preinst Searches for missing and unneeded dependencies
1829# Don't call directly, but via java-pkg-2_pkg_preinst!
1830# ------------------------------------------------------------------------------
1831
1832java-utils-2_pkg_preinst() {
1833 if is-java-strict; then
1834 if has_version dev-java/java-dep-check; then
1835 [[ -e "${JAVA_PKG_ENV}" ]] || return
1836 local output=$(GENTOO_VM= java-dep-check --image "${D}" "${JAVA_PKG_ENV}")
1837 if [[ ${output} && has_version <=dev-java/java-dep-check-0.2 ]]; then
1838 ewarn "Possibly unneeded dependencies found in package.env:"
1839 for dep in ${output}; do
1840 ewarn "\t${dep}"
1841 done
1842 fi
1843 if [[ ${output} && has_version >dev-java/java-dep-check-0.2 ]]; then
1844 ewarn "${output}"
1845 fi
1846 else
1847 eerror "Install dev-java/java-dep-check for dependency checking"
1848 fi
1849 fi
1850}
1348 1851
1349# ------------------------------------------------------------------------------ 1852# ------------------------------------------------------------------------------
1350# @section-begin build 1853# @section-begin build
1351# @section-summary Build functions 1854# @section-summary Build functions
1352# 1855#
1356 1859
1357# ------------------------------------------------------------------------------ 1860# ------------------------------------------------------------------------------
1358# @ebuild-function eant 1861# @ebuild-function eant
1359# 1862#
1360# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1863# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1361# compiler. 1864# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1362# variables: 1865# variables:
1363# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the 1866# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1364# gentoo.classpath property. Be sure to call 1867# gentoo.classpath property. Be sure to call
1365# java-ant_rewrite-classpath in src_unpack. 1868# java-ant_rewrite-classpath in src_unpack.
1366# 1869# EANT_NEEDS_TOOLS - add tools.jar to the gentoo.classpath. Should only be used
1870# for build-time purposes, the dependency is not recorded to
1871# package.env!
1872# JAVA_PKG_NO_BUNDLED_SEARCH - Don't search for bundled jars or class files
1873# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1367# ------------------------------------------------------------------------------ 1874# ------------------------------------------------------------------------------
1368eant() { 1875eant() {
1369 debug-print-function ${FUNCNAME} $* 1876 debug-print-function ${FUNCNAME} $*
1370 1877
1371 # FIXME get this working 1878 if [[ ${EBUILD_PHASE} = compile ]]; then
1372# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then 1879 java-ant-2_src_configure
1880 java-utils-2_src_prepare
1881 fi
1882
1883 if ! hasq java-ant-2 ${INHERITED}; then
1884 local msg="You should inherit java-ant-2 when using eant"
1373# java-pkg_announce-qa-violation \ 1885 java-pkg_announce-qa-violation "${msg}"
1374# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1375# fi 1886 fi
1376 1887
1377 local antflags="-Dnoget=true" 1888 local antflags="-Dnoget=true -Dmaven.mode.offline=true -Dbuild.sysclasspath=ignore"
1889
1378 java-pkg_init-compiler_ 1890 java-pkg_init-compiler_
1379 local compiler="${GENTOO_COMPILER}" 1891 local compiler="${GENTOO_COMPILER}"
1380 1892
1381 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1893 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1382
1383 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})" 1894 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})"
1384 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1895 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1385 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1896 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1386 fi 1897 fi
1387 1898
1395 if [[ -n ${build_compiler_deps} ]]; then 1906 if [[ -n ${build_compiler_deps} ]]; then
1396 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})" 1907 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1397 fi 1908 fi
1398 fi 1909 fi
1399 1910
1911 for arg in "${@}"; do
1912 if [[ ${arg} = -lib ]]; then
1400 if is-java-strict; then 1913 if is-java-strict; then
1401 einfo "Disabling system classpath for ant" 1914 eerror "You should not use the -lib argument to eant because it will fail"
1402 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1915 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1916 eerror "or ant properties to make dependencies available."
1917 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1918 eerror "split ant (>=dev-java/ant-core-1.7)."
1919 die "eant -lib is deprecated/forbidden"
1920 else
1921 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1922 echo "more info."
1923 fi
1403 fi 1924 fi
1925 done
1404 1926
1405 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1927 # parse WANT_ANT_TASKS for atoms
1406 antflags="${antflags} -debug" 1928 local want_ant_tasks
1929 for i in ${WANT_ANT_TASKS}; do
1930 if [[ ${i} = */*:* ]]; then
1931 i=${i#*/}
1932 i=${i%:0}
1933 want_ant_tasks+="${i/:/-} "
1934 else
1935 want_ant_tasks+="${i} "
1407 fi 1936 fi
1937 done
1938 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1939 ANT_TASKS="${ANT_TASKS:-${want_ant_tasks% }}"
1940
1941 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1942 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1943
1944 # if ant-tasks is not set by ebuild or forced, use none
1945 ANT_TASKS="${ANT_TASKS:-none}"
1946
1947 # at this point, ANT_TASKS should be "all", "none" or explicit list
1948 if [[ "${ANT_TASKS}" == "all" ]]; then
1949 einfo "Using all available ANT_TASKS"
1950 elif [[ "${ANT_TASKS}" == "none" ]]; then
1951 einfo "Disabling all optional ANT_TASKS"
1952 else
1953 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1954 fi
1955
1956 export ANT_TASKS
1957
1958 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1959 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1408 1960
1409 local gcp="${EANT_GENTOO_CLASSPATH}" 1961 local gcp="${EANT_GENTOO_CLASSPATH}"
1962 local getjarsarg=""
1410 1963
1964 if [[ ${EBUILD_PHASE} = "test" ]]; then
1965 antflags="${antflags} -DJunit.present=true"
1966 [[ ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1967 getjarsarg="--with-dependencies"
1968 fi
1969
1970 local cp
1971
1972 for atom in ${gcp}; do
1973 cp="${cp}:$(java-pkg_getjars ${getjarsarg} ${atom})"
1974 done
1975
1976 [[ -n "${EANT_NEEDS_TOOLS}" ]] && cp="${cp}:$(java-config --tools)"
1977
1411 if [[ "${gcp}" ]]; then 1978 if [[ ${cp} ]]; then
1412 local cp="$(java-pkg_getjars ${gcp})"
1413 # It seems ant does not like single quotes around ${cp} 1979 # It seems ant does not like single quotes around ${cp}
1980 cp=${cp#:}
1981 [[ ${EANT_GENTOO_CLASSPATH_EXTRA} ]] && \
1982 cp="${cp}:${EANT_GENTOO_CLASSPATH_EXTRA}"
1414 antflags="${antflags} -Dgentoo.classpath=\"${cp}\"" 1983 antflags="${antflags} -Dgentoo.classpath=\"${cp}\""
1415 fi 1984 fi
1416 1985
1417 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1986 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1987 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
1418 ant ${antflags} "${@}" || die "eant failed" 1988 ant ${antflags} "${@}" || die "eant failed"
1419
1420} 1989}
1421 1990
1422# ------------------------------------------------------------------------------ 1991# ------------------------------------------------------------------------------
1423# @ebuild-function ejavac 1992# @ebuild-function ejavac
1424# 1993#
1519# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will 2088# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will
1520# call it during each of the phases of the merge process. 2089# call it during each of the phases of the merge process.
1521# 2090#
1522# ----------------------------------------------------------------------------- 2091# -----------------------------------------------------------------------------
1523java-pkg_init() { 2092java-pkg_init() {
2093 debug-print-function ${FUNCNAME} $*
1524 unset JAVAC 2094 unset JAVAC
1525 unset JAVA_HOME 2095 unset JAVA_HOME
2096
2097 java-config --help >/dev/null || {
2098 eerror ""
2099 eerror "Can't run java-config --help"
2100 eerror "Have you upgraded python recently but haven't"
2101 eerror "run python-updater yet?"
2102 die "Can't run java-config --help"
2103 }
2104
2105 # People do all kinds of weird things.
2106 # http://forums.gentoo.org/viewtopic-p-3943166.html
2107 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
2108 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
2109 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
2110 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
2111 ewarn "sun-jdk vms and and as such break configure scripts that"
2112 ewarn "use it (for example app-office/openoffice) so we filter it out."
2113 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
2114 ewarn "make.conf for example) to silence this warning or"
2115 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
2116 fi
2117
2118 if [[ -z ${accept} ]]; then
2119 # export _JAVA_OPTIONS= doesn't work because it will show up in java
2120 # -version output
2121 unset _JAVA_OPTIONS
2122 # phase hooks make this run many times without this
2123 I_WANT_GLOBAL_JAVA_OPTIONS="true"
2124 fi
2125
2126 if java-pkg_func-exists ant_src_unpack; then
2127 java-pkg_announce-qa-violation "Using old ant_src_unpack. Should be src_unpack"
2128 fi
2129
1526 java-pkg_init_paths_ 2130 java-pkg_init_paths_
1527 java-pkg_switch-vm 2131 java-pkg_switch-vm
1528 PATH=${JAVA_HOME}/bin:${PATH} 2132 PATH=${JAVA_HOME}/bin:${PATH}
1529 2133
1530 # TODO we will probably want to set JAVAC and JAVACFLAGS 2134 # TODO we will probably want to set JAVAC and JAVACFLAGS
1531 2135
1532 # Do some QA checks 2136 # Do some QA checks
1533 java-pkg_check-jikes 2137 java-pkg_check-jikes
2138
2139 # Can't use unset here because Portage does not save the unset
2140 # see https://bugs.gentoo.org/show_bug.cgi?id=189417#c11
1534 2141
1535 # When users have crazy classpaths some packages can fail to compile. 2142 # When users have crazy classpaths some packages can fail to compile.
1536 # and everything should work with empty CLASSPATH. 2143 # and everything should work with empty CLASSPATH.
1537 # This also helps prevent unexpected dependencies on random things 2144 # This also helps prevent unexpected dependencies on random things
1538 # from the CLASSPATH. 2145 # from the CLASSPATH.
1539 unset CLASSPATH 2146 export CLASSPATH=
2147
2148 # Unset external ANT_ stuff
2149 export ANT_TASKS=
2150 export ANT_OPTS=
2151 export ANT_RESPECT_JAVA_HOME=
1540} 2152}
1541 2153
1542# ------------------------------------------------------------------------------ 2154# ------------------------------------------------------------------------------
1543# @function-internal java-pkg-init-compiler_ 2155# @function-internal java-pkg-init-compiler_
1544# 2156#
1635 done 2247 done
1636 2248
1637 # If it hasn't been defined already, default to javac 2249 # If it hasn't been defined already, default to javac
1638 if [[ -z ${GENTOO_COMPILER} ]]; then 2250 if [[ -z ${GENTOO_COMPILER} ]]; then
1639 if [[ -n ${compilers} ]]; then 2251 if [[ -n ${compilers} ]]; then
1640 einfo "No suitable compiler found: defaulting javac for compilation" 2252 einfo "No suitable compiler found: defaulting to JDK default for compilation"
1641 else 2253 else
1642 # probably don't need to notify users about the default. 2254 # probably don't need to notify users about the default.
1643 :;#einfo "Defaulting to javac for compilation" 2255 :;#einfo "Defaulting to javac for compilation"
1644 fi 2256 fi
2257 if java-config -g GENTOO_COMPILER 2> /dev/null; then
2258 export GENTOO_COMPILER=$(java-config -g GENTOO_COMPILER)
2259 else
1645 export GENTOO_COMPILER=javac 2260 export GENTOO_COMPILER=javac
2261 fi
1646 else 2262 else
1647 einfo "Using ${GENTOO_COMPILER} for compilation" 2263 einfo "Using ${GENTOO_COMPILER} for compilation"
1648 fi 2264 fi
1649 2265
1650} 2266}
1666 fi 2282 fi
1667 2283
1668 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}" 2284 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}"
1669 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/" 2285 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/"
1670 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env" 2286 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env"
2287 JAVA_PKG_VIRTUALS_PATH="${DESTTREE}/share/java-config-2/virtuals"
2288 JAVA_PKG_VIRTUAL_PROVIDER="${D}/${JAVA_PKG_VIRTUALS_PATH}/${JAVA_PKG_NAME}"
1671 2289
1672 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib" 2290 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib"
1673 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}" 2291 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}"
1674 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps" 2292 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps"
1675 2293
1688# Writes the package.env out to disk. 2306# Writes the package.env out to disk.
1689# 2307#
1690# ------------------------------------------------------------------------------ 2308# ------------------------------------------------------------------------------
1691# TODO change to do-write, to match everything else 2309# TODO change to do-write, to match everything else
1692java-pkg_do_write_() { 2310java-pkg_do_write_() {
2311 debug-print-function ${FUNCNAME} $*
1693 java-pkg_init_paths_ 2312 java-pkg_init_paths_
1694 # Create directory for package.env 2313 # Create directory for package.env
1695 dodir "${JAVA_PKG_SHAREPATH}" 2314 dodir "${JAVA_PKG_SHAREPATH}"
1696 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 2315 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f \
2316 "${JAVA_PKG_DEPEND_FILE}" || -f \
2317 "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]]; then
1697 # Create package.env 2318 # Create package.env
1698 ( 2319 (
1699 echo "DESCRIPTION=\"${DESCRIPTION}\"" 2320 echo "DESCRIPTION=\"${DESCRIPTION}\""
1700 echo "GENERATION=\"2\"" 2321 echo "GENERATION=\"2\""
2322 echo "SLOT=\"${SLOT}\""
1701 2323
1702 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\"" 2324 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
1703 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 2325 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1704 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 2326 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1705 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 2327 [[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
2328 && echo "DEPEND=\"$(cat "${JAVA_PKG_DEPEND_FILE}" | uniq | tr '\n' ':')\""
2329 [[ -f "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]] \
2330 && echo "OPTIONAL_DEPEND=\"$(cat "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" | uniq | tr '\n' ':')\""
1706 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 2331 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1707 ) > "${JAVA_PKG_ENV}" 2332 ) > "${JAVA_PKG_ENV}"
1708 2333
1709 # register target/source 2334 # register target/source
1710 local target="$(java-pkg_get-target)" 2335 local target="$(java-pkg_get-target)"
1721 2346
1722 2347
1723 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}" 2348 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
1724 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}" 2349 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
1725 2350
2351 # extra env variables
2352 if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
2353 cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}" || die
2354 # nested echo to remove leading/trailing spaces
2355 echo "ENV_VARS=\"$(echo ${JAVA_PKG_EXTRA_ENV_VARS})\"" \
2356 >> "${JAVA_PKG_ENV}" || die
2357 fi
2358
1726 # Strip unnecessary leading and trailing colons 2359 # Strip unnecessary leading and trailing colons
1727 # TODO try to cleanup if possible 2360 # TODO try to cleanup if possible
1728 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 2361 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
2362 else
2363 debug-print "JAVA_PKG_CLASSPATH, JAVA_PKG_LIBRARY, JAVA_PKG_DEPEND_FILE"
2364 debug-print "or JAVA_PKG_OPTIONAL_DEPEND_FILE not defined so can't"
2365 debug-print "write package.env."
1729 fi 2366 fi
1730} 2367}
1731 2368
1732# ------------------------------------------------------------------------------ 2369# ------------------------------------------------------------------------------
1733# @internal-function java-pkg_record-jar_ 2370# @internal-function java-pkg_record-jar_
1734# 2371#
1735# Record a dependency to the package.env 2372# Record an (optional) dependency to the package.env
1736# 2373# @param --optional - record dependency as optional
2374# @param $1 - package to record
2375# @param $2 - (optional) jar of package to record
1737# ------------------------------------------------------------------------------ 2376# ------------------------------------------------------------------------------
1738JAVA_PKG_DEPEND="${T}/java-pkg-depend" 2377JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2378JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
1739 2379
1740java-pkg_record-jar_() { 2380java-pkg_record-jar_() {
1741 debug-print-function ${FUNCNAME} $* 2381 debug-print-function ${FUNCNAME} $*
2382
2383 local depend_file="${JAVA_PKG_DEPEND_FILE}"
2384 if [[ "${1}" == "--optional" ]]; then
2385 depend_file="${JAVA_PKG_OPTIONAL_DEPEND_FILE}"
2386 shift
2387 fi
1742 2388
1743 local pkg=${1} jar=${2} append 2389 local pkg=${1} jar=${2} append
1744 if [[ -z "${jar}" ]]; then 2390 if [[ -z "${jar}" ]]; then
1745 append="${pkg}" 2391 append="${pkg}"
1746 else 2392 else
1747 append="$(basename ${jar})@${pkg}" 2393 append="$(basename ${jar})@${pkg}"
1748 fi 2394 fi
1749 2395
1750 echo ${append} >> ${JAVA_PKG_DEPEND} 2396 echo "${append}" >> "${depend_file}"
1751} 2397}
1752 2398
1753# ------------------------------------------------------------------------------ 2399# ------------------------------------------------------------------------------
1754# @internal-function java-pkg_append_ 2400# @internal-function java-pkg_append_
1755# 2401#
1799# 2445#
1800# @return 0 - function is declared 2446# @return 0 - function is declared
1801# @return 1 - function is undeclared 2447# @return 1 - function is undeclared
1802# ------------------------------------------------------------------------------ 2448# ------------------------------------------------------------------------------
1803java-pkg_func-exists() { 2449java-pkg_func-exists() {
1804 if [[ -n "$(declare -f ${1})" ]]; then 2450 declare -F ${1} > /dev/null
1805 return 0
1806 else
1807 return 1
1808 fi
1809} 2451}
1810 2452
1811# ------------------------------------------------------------------------------ 2453# ------------------------------------------------------------------------------
1812# @internal-function java-pkg_setup-vm 2454# @internal-function java-pkg_setup-vm
1813# 2455#
1814# Sets up the environment for a specific VM 2456# Sets up the environment for a specific VM
1815# 2457#
1816# ------------------------------------------------------------------------------ 2458# ------------------------------------------------------------------------------
1817java-pkg_setup-vm() { 2459java-pkg_setup-vm() {
1818 debug-print-function ${FUNCNAME} $* 2460 debug-print-function ${FUNCNAME} $*
2461
2462 export LANG="C" LC_ALL="C"
1819 2463
1820 local vendor="$(java-pkg_get-vm-vendor)" 2464 local vendor="$(java-pkg_get-vm-vendor)"
1821 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then 2465 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1822 addpredict "/dev/random" 2466 addpredict "/dev/random"
1823 elif [[ "${vendor}" == "ibm" ]]; then 2467 elif [[ "${vendor}" == "ibm" ]]; then
1824 addpredict "/proc/self/maps" 2468 addpredict "/proc/self/maps"
1825 addpredict "/proc/cpuinfo" 2469 addpredict "/proc/cpuinfo"
1826 export LANG="C" LC_ALL="C"
1827 elif [[ "${vendor}" == "jrockit" ]]; then 2470 elif [[ "${vendor}" == "jrockit" ]]; then
1828 addpredict "/proc/cpuinfo" 2471 addpredict "/proc/cpuinfo"
1829 fi 2472 fi
1830} 2473}
1831 2474
1935 2578
1936 #TODO If you know a better solution let us know. 2579 #TODO If you know a better solution let us know.
1937 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 2580 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1938 2581
1939 local tann="${T}/announced-vm" 2582 local tann="${T}/announced-vm"
2583 # With the hooks we should only get here once from pkg_setup but better safe than sorry
2584 # if people have for example modified eclasses some where
1940 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 2585 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1941 # Add a check for setup/preinst phase... to avoid duplicate outputs
1942 # for when FEATURES=buildpkg
1943 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1944 then
1945 einfo "Using: $(java-config -f)" 2586 einfo "Using: $(java-config -f)"
1946 [[ ! -f "${tann}" ]] && touch "${tann}" 2587 [[ ! -f "${tann}" ]] && touch "${tann}"
1947 fi
1948 fi 2588 fi
1949 2589
1950 else 2590 else
1951 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!" 2591 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!"
1952 fi 2592 fi
1982 einfo "Classes" 2622 einfo "Classes"
1983 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR}," 2623 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1984 fi 2624 fi
1985} 2625}
1986 2626
1987# TODO document 2627# ------------------------------------------------------------------------------
2628# @internal-function java-pkg_verify-classes
2629#
1988# Verify that the classes were compiled for the right source / target 2630# Verify that the classes were compiled for the right source / target. Dies if
2631# not.
2632# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2633# ------------------------------------------------------------------------------
1989java-pkg_verify-classes() { 2634java-pkg_verify-classes() {
1990 ebegin "Verifying java class versions"
1991 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 2635 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1992 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 2636
2637 local version_verify="/usr/bin/class-version-verify.py"
2638
2639 if [[ ! -x "${version_verify}" ]]; then
2640 version_verify="/usr/$(get_libdir)/javatoolkit/bin/class-version-verify.py"
2641 fi
2642
2643 if [[ ! -x "${version_verify}" ]]; then
2644 ewarn "Unable to perform class version checks as"
2645 ewarn "class-version-verify.py is unavailable"
2646 ewarn "Please install dev-java/javatoolkit."
2647 return
2648 fi
2649
2650 local target=$(java-pkg_get-target)
2651 local result
2652 local log="${T}/class-version-verify.log"
2653 if [[ -n "${1}" ]]; then
2654 ${version_verify} -v -t ${target} "${1}" > "${log}"
1993 result=$? 2655 result=$?
1994 eend ${result}
1995 if [[ ${result} == 0 ]]; then
1996 einfo "All good"
1997 else 2656 else
1998 ewarn "Possible problem" 2657 ebegin "Verifying java class versions (target: ${target})"
1999 die "Bad class files found" 2658 ${version_verify} -v -t ${target} -r "${D}" > "${log}"
2659 result=$?
2660 eend ${result}
2661 fi
2662 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2663 if [[ ${result} != 0 ]]; then
2664 eerror "Incorrect bytecode version found"
2665 [[ -n "${1}" ]] && eerror "in file: ${1}"
2666 eerror "See ${log} for more details."
2667 die "Incorrect bytecode found"
2668 fi
2669}
2670
2671# ----------------------------------------------------------------------------
2672# @internal-function java-pkg_ensure-dep
2673# Check that a package being used in jarfrom, getjars and getjar is contained
2674# within DEPEND or RDEPEND.
2675# @param $1 - empty - check both vars; "runtime" or "build" - check only
2676# RDEPEND, resp. DEPEND
2677# @param $2 - Package name and slot.
2678
2679java-pkg_ensure-dep() {
2680 debug-print-function ${FUNCNAME} $*
2681
2682 local limit_to="${1}"
2683 local target_pkg="${2}"
2684 local dev_error=""
2685
2686 local stripped_pkg=$(echo "${target_pkg}" | sed \
2687 's/-[0-9]*\(\.[0-9]\)*$//')
2688
2689 debug-print "Matching against: ${stripped_pkg}"
2690
2691 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2692 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2693 dev_error="${dev_error} declared in DEPEND."
2694 if is-java-strict; then
2695 eerror "${dev_error}"
2696 die "${dev_error}"
2697 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2698 eerror "${dev_error}"
2699 elog "Because you have this package installed the package will"
2700 elog "build without problems, but please report this to"
2701 elog "http://bugs.gentoo.org"
2702 fi
2703 fi
2704
2705 if [[ ${limit_to} != build ]]; then
2706 if [[ ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2707 if [[ ! ( ${PDEPEND} =~ "${stripped_pkg}" ) ]]; then
2708 dev_error="The ebuild is attempting to use ${target_pkg},"
2709 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND"
2710 dev_error="${dev_error} or PDEPEND."
2711 if is-java-strict; then
2712 eerror "${dev_error}"
2713 die "${dev_error}"
2714 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2715 eerror "${dev_error}"
2716 elog "The package will build without problems, but may fail to run"
2717 elog "if you don't have ${target_pkg} installed, so please report"
2718 elog "this to http://bugs.gentoo.org"
2719 fi
2720 fi
2721 fi
2000 fi 2722 fi
2001} 2723}
2002 2724
2003# ------------------------------------------------------------------------------ 2725# ------------------------------------------------------------------------------
2004# @section-end internal 2726# @section-end internal
2005# ------------------------------------------------------------------------------ 2727# ------------------------------------------------------------------------------
2006 2728
2007java-pkg_check-phase() { 2729java-pkg_check-phase() {
2008 local phase=${1} 2730 local phase=${1}
2009 local funcname=${2} 2731 local funcname=${FUNCNAME[1]}
2010 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then 2732 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
2011 java-pkg_announce-qa-violation \
2012 "${funcname} used outside of src_${phase}" 2733 local msg="${funcname} used outside of src_${phase}"
2734 java-pkg_announce-qa-violation "${msg}"
2013 fi 2735 fi
2014} 2736}
2015 2737
2016java-pkg_check-versioned-jar() { 2738java-pkg_check-versioned-jar() {
2017 local jar=${1} 2739 local jar=${1}
2026 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2748 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
2027 fi 2749 fi
2028} 2750}
2029 2751
2030java-pkg_announce-qa-violation() { 2752java-pkg_announce-qa-violation() {
2031 if is-java-strict; then 2753 local nodie
2754 if [[ ${1} == "--nodie" ]]; then
2755 nodie="true"
2756 shift
2757 fi
2032 echo "Java QA Notice: $@" >&2 2758 echo "Java QA Notice: $@" >&2
2033 increment-qa-violations 2759 increment-qa-violations
2034 fi 2760 [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
2035} 2761}
2036 2762
2037increment-qa-violations() { 2763increment-qa-violations() {
2038 let "JAVA_PKG_QA_VIOLATIONS+=1" 2764 let "JAVA_PKG_QA_VIOLATIONS+=1"
2039 export JAVA_PKG_QA_VIOLATIONS 2765 export JAVA_PKG_QA_VIOLATIONS
2042is-java-strict() { 2768is-java-strict() {
2043 [[ -n ${JAVA_PKG_STRICT} ]] 2769 [[ -n ${JAVA_PKG_STRICT} ]]
2044 return $? 2770 return $?
2045} 2771}
2046 2772
2773
2047# ------------------------------------------------------------------------------ 2774# ------------------------------------------------------------------------------
2048# @eclass-end 2775# @eclass-end
2049# ------------------------------------------------------------------------------ 2776# ------------------------------------------------------------------------------

Legend:
Removed from v.1.43  
changed lines
  Added in v.1.127

  ViewVC Help
Powered by ViewVC 1.1.20