/[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.105
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.105 2008/03/26 23:00:23 ali_bush Exp $
10
11 10
12# ----------------------------------------------------------------------------- 11# -----------------------------------------------------------------------------
13# @eclass-begin 12# @eclass-begin
14# @eclass-shortdesc Java Utility eclass 13# @eclass-shortdesc Java Utility eclass
15# @eclass-maintainer java@gentoo.org 14# @eclass-maintainer java@gentoo.org
36# ----------------------------------------------------------------------------- 35# -----------------------------------------------------------------------------
37 36
38# Make sure we use java-config-2 37# Make sure we use java-config-2
39export WANT_JAVA_CONFIG="2" 38export WANT_JAVA_CONFIG="2"
40 39
41# TODO document 40# -----------------------------------------------------------------------------
41# @variable-external WANT_ANT_TASKS
42# @variable-default ""
43#
44# An $IFS separated list of ant tasks.
45# Ebuild can specify this variable before inheriting java-ant-2 eclass to
46# determine ANT_TASKS it needs. They will be automatically translated to
47# DEPEND variable and ANT_TASKS variable. JAVA_PKG_FORCE_ANT_TASKS can override
48# ANT_TASKS set by WANT_ANT_TASKS, but not the DEPEND due to caching.
49# Ebuilds that need to depend conditionally on certain tasks and specify them
50# differently for different eant calls can't use this simplified approach.
51# You also cannot specify version or anything else than ant-*.
52#
53# @example WANT_ANT_TASKS="ant-junit ant-trax"
54#
55# @seealso JAVA_PKG_FORCE_ANT_TASKS
56# -----------------------------------------------------------------------------
57#WANT_ANT_TASKS
58
59# -----------------------------------------------------------------------------
60# @variable-internal JAVA_PKG_PORTAGE_DEP
61#
62# The version of portage we need to function properly. Previously it was
63# portage with phase hooks support but now we use a version with proper env
64# saving.
65# -----------------------------------------------------------------------------
42JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1" 66JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1.2.7"
43 67
44# ----------------------------------------------------------------------------- 68# -----------------------------------------------------------------------------
45# @variable-internal JAVA_PKG_E_DEPEND 69# @variable-internal JAVA_PKG_E_DEPEND
46# 70#
47# This is a convience variable to be used from the other java eclasses. This is 71# This is a convience variable to be used from the other java eclasses. This is
48# the version of java-config we want to use. We also need a recent version 72# the version of java-config we want to use. Usually the latest stable version
49# portage, that includes phase hooks. 73# so that ebuilds can use new features without depending on specific versions.
50# ----------------------------------------------------------------------------- 74# -----------------------------------------------------------------------------
51JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 ${JAVA_PKG_PORTAGE_DEP}" 75JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.33-r1 ${JAVA_PKG_PORTAGE_DEP}"
76hasq source ${JAVA_PKG_IUSE} && JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} source? ( app-arch/zip )"
52 77
53# ----------------------------------------------------------------------------- 78# -----------------------------------------------------------------------------
54# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 79# @variable-external JAVA_PKG_ALLOW_VM_CHANGE
55# @variable-default yes 80# @variable-default yes
56# 81#
130# @note This should only be used internally or for testing. 155# @note This should only be used internally or for testing.
131# @example Use jikes and javac, in that order 156# @example Use jikes and javac, in that order
132# JAVA_PKG_FORCE_COMPILER="jikes javac" 157# JAVA_PKG_FORCE_COMPILER="jikes javac"
133# ----------------------------------------------------------------------------- 158# -----------------------------------------------------------------------------
134 159
160# -----------------------------------------------------------------------------
161# @variable-external JAVA_PKG_FORCE_ANT_TASKS
162#
163# An $IFS separated list of ant tasks. Can be set in environment before calling
164# emerge/ebuild to override variables set in ebuild, mainly for testing before
165# putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in
166# eant() call, not the dependencies specified in WANT_ANT_TASKS.
167#
168# @example JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \
169# ebuild foo.ebuild compile
170#
171# @seealso WANT_ANT_TASKS
172# -----------------------------------------------------------------------------
173
135# TODO document me 174# TODO document me
136JAVA_PKG_QA_VIOLATIONS=0 175JAVA_PKG_QA_VIOLATIONS=0
137 176
138# ----------------------------------------------------------------------------- 177# -----------------------------------------------------------------------------
139# @section-end variables 178# @section-end variables
146# 185#
147# These are used to install Java-related things, such as jars, Javadocs, JNI 186# These are used to install Java-related things, such as jars, Javadocs, JNI
148# libraries, etc. 187# libraries, etc.
149# ----------------------------------------------------------------------------- 188# -----------------------------------------------------------------------------
150 189
190# -----------------------------------------------------------------------------
191# @ebuild-function java-pkg_doexamples
192#
193# Installs given arguments to /usr/share/doc/${PF}/examples
194# If you give it only one parameter and it is a directory it will install
195# everything in that directory to the examples directory.
196#
197# @example
198# java-pkg_doexamples demo
199# java-pkg_doexamples demo/* examples/*
200#
201# @param --subdir - If the examples need a certain directory structure
202# @param $* - list of files to install
203# ------------------------------------------------------------------------------
204java-pkg_doexamples() {
205 debug-print-function ${FUNCNAME} $*
206
207 [[ ${#} -lt 1 ]] && die "At least one argument needed"
208
209 java-pkg_check-phase install
210
211 local dest=/usr/share/doc/${PF}/examples
212 if [[ ${1} == --subdir ]]; then
213 local dest=${dest}/${2}
214 dodir ${dest}
215 shift 2
216 fi
217
218 if [[ ${#} = 1 && -d ${1} ]]; then
219 ( # dont want to pollute calling env
220 insinto "${dest}"
221 doins -r ${1}/*
222 ) || die "Installing examples failed"
223 else
224 ( # dont want to pollute calling env
225 insinto "${dest}"
226 doins -r "$@"
227 ) || die "Installing examples failed"
228 fi
229}
151 230
152# ----------------------------------------------------------------------------- 231# -----------------------------------------------------------------------------
153# @ebuild-function java-pkg_dojar 232# @ebuild-function java-pkg_dojar
154# 233#
155# Installs any number of jars. 234# Installs any number of jars.
174 # Create JARDEST if it doesn't exist 253 # Create JARDEST if it doesn't exist
175 dodir ${JAVA_PKG_JARDEST} 254 dodir ${JAVA_PKG_JARDEST}
176 255
177 local jar 256 local jar
178 # for each jar 257 # for each jar
179 for jar in "$@"; do 258 for jar in "${@}"; do
180 local jar_basename=$(basename "${jar}") 259 local jar_basename=$(basename "${jar}")
181 260
182 java-pkg_check-versioned-jar ${jar_basename} 261 java-pkg_check-versioned-jar ${jar_basename}
183 262
184 # check if it exists 263 # check if it exists
185 if [[ -e "${jar}" ]] ; then 264 if [[ -e "${jar}" ]] ; then
265 # Don't overwrite if jar has already been installed with the same
266 # name
267 local dest="${D}${JAVA_PKG_JARDEST}/${jar_basename}"
268 if [[ -e "${dest}" ]]; then
269 ewarn "Overwriting ${dest}"
270 fi
271
186 # install it into JARDEST if it's a non-symlink 272 # install it into JARDEST if it's a non-symlink
187 if [[ ! -L "${jar}" ]] ; then 273 if [[ ! -L "${jar}" ]] ; then
274 #but first check class version when in strict mode.
275 is-java-strict && java-pkg_verify-classes "${jar}"
276
188 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 277 INSDESTTREE="${JAVA_PKG_JARDEST}" \
189 doins "${jar}" || die "failed to install ${jar}" 278 doins "${jar}" || die "failed to install ${jar}"
190 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 279 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
191 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}" 280 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}"
192 # make a symlink to the original jar if it's symlink 281 # make a symlink to the original jar if it's symlink
202 done 291 done
203 292
204 java-pkg_do_write_ 293 java-pkg_do_write_
205} 294}
206 295
296# ------------------------------------------------------------------------------
297# @internal-function depend-java-query
298#
299# Wrapper for the depend-java-query binary to enable passing USE in env.
300# Using env variables keeps this eclass working with java-config versions that
301# do not handle use flags.
302# ------------------------------------------------------------------------------
207 303
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.
307 USE="${USE}" /usr/bin/depend-java-query "${@}"
308}
208 309
209# ------------------------------------------------------------------------------ 310# ------------------------------------------------------------------------------
210# @ebuild-function java-pkg_regjar 311# @ebuild-function java-pkg_regjar
211# 312#
212# Records an already installed jar in the package.env 313# Records an already installed jar in the package.env
243 [[ ${#} -lt 1 ]] && die "at least one argument needed" 344 [[ ${#} -lt 1 ]] && die "at least one argument needed"
244 345
245 java-pkg_init_paths_ 346 java-pkg_init_paths_
246 347
247 local jar jar_dir jar_file 348 local jar jar_dir jar_file
248 for jar in "$@"; do 349 for jar in "${@}"; do
249 # TODO use java-pkg_check-versioned-jar 350 # TODO use java-pkg_check-versioned-jar
250 if [[ -e "${jar}" ]]; then 351 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
352 [[ -d "${jar}" || -d "${D}${jar}" ]] \
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
251 # 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:
252 # imagine such call: 359 # imagine such call:
253 # java-pkg_regjar ${D}/opt/java/*.jar 360 # java-pkg_regjar ${D}/opt/java/*.jar
254 # such call will fall into this case (-e ${jar}) and will 361 # such call will fall into this case (-e ${jar}) and will
255 # record paths with ${D} in package.env 362 # record paths with ${D} in package.env
256 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 363 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 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
260 die "${jar} does not exist" 370 die "${jar} does not exist"
261 fi 371 fi
262 done 372 done
263 373
264 java-pkg_do_write_ 374 java-pkg_do_write_
265} 375}
266
267 376
268# ------------------------------------------------------------------------------ 377# ------------------------------------------------------------------------------
269# @ebuild-function java-pkg_newjar 378# @ebuild-function java-pkg_newjar
270# 379#
271# Installs a jar with a new name 380# Installs a jar with a new name
282 local original_jar="${1}" 391 local original_jar="${1}"
283 local new_jar="${2:-${PN}.jar}" 392 local new_jar="${2:-${PN}.jar}"
284 local new_jar_dest="${T}/${new_jar}" 393 local new_jar_dest="${T}/${new_jar}"
285 394
286 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 395 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
287 [[ ! -f ${original_jar} ]] && die "${original_jar} does not exist!" 396 [[ ! -f ${original_jar} ]] \
397 && die "${original_jar} does not exist or is not a file!"
288 398
289 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 399 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
290 cp "${original_jar}" "${new_jar_dest}" \ 400 cp "${original_jar}" "${new_jar_dest}" \
291 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 401 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
292 java-pkg_dojar "${new_jar_dest}" 402 java-pkg_dojar "${new_jar_dest}"
341 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 451 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
342 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 452 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
343 # otherwise make a symlink to the symlink's origin 453 # otherwise make a symlink to the symlink's origin
344 else 454 else
345 # TODO use dosym 455 # TODO use dosym
456 ln -s "$(readlink "${lib}")" \
346 ln -s "$(readlink "${lib}")" "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")" 457 "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")"
347 debug-print "${lib} is a symlink, linking accordanly" 458 debug-print "${lib} is a symlink, linking accordanly"
348 fi 459 fi
349 # otherwise die 460 # otherwise die
350 else 461 else
351 die "${lib} does not exist" 462 die "${lib} does not exist"
445# ------------------------------------------------------------------------------ 556# ------------------------------------------------------------------------------
446# @ebuild-function java-pkg_dojavadoc 557# @ebuild-function java-pkg_dojavadoc
447# 558#
448# Installs javadoc documentation. This should be controlled by the doc use flag. 559# Installs javadoc documentation. This should be controlled by the doc use flag.
449# 560#
561# @param $1: optional --symlink creates to symlink like this for html
562# documentation bundles.
450# @param $1: - The javadoc root directory. 563# @param $2: - The javadoc root directory.
451# 564#
452# @example: 565# @example:
453# java-pkg_dojavadoc docs/api 566# java-pkg_dojavadoc docs/api
567# java-pkg_dojavadoc --symlink apidocs docs/api
454# 568#
455# ------------------------------------------------------------------------------ 569# ------------------------------------------------------------------------------
456java-pkg_dojavadoc() { 570java-pkg_dojavadoc() {
571 debug-print-function ${FUNCNAME} $*
572
573 # For html documentation bundles that link to Javadoc
574 local symlink
575 if [[ ${1} = --symlink ]]; then
576 symlink=${2}
577 shift 2
578 fi
579
457 local dir="$1" 580 local dir="$1"
581 local dest=/usr/share/doc/${PF}/html
582
583 # QA checks
458 584
459 java-pkg_check-phase install 585 java-pkg_check-phase install
460 586
461 [[ -z "${dir}" ]] && die "Must specify a directory!" 587 [[ -z "${dir}" ]] && die "Must specify a directory!"
462 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!" 588 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!"
589 if [[ ! -e "${dir}/index.html" ]]; then
590 local msg="No index.html in javadoc directory"
591 ewarn "${msg}"
592 is-java-strict && die "${msg}"
593 fi
594
595 if [[ -e ${D}/${dest}/api ]]; then
596 eerror "${dest} already exists. Will not overwrite."
597 die "${dest}"
598 fi
599
600 # Renaming to match our directory layout
463 601
464 local dir_to_install="${dir}" 602 local dir_to_install="${dir}"
465 if [[ "$(basename "${dir}")" != "api" ]]; then 603 if [[ "$(basename "${dir}")" != "api" ]]; then
466 dir_to_install="${T}/api" 604 dir_to_install="${T}/api"
467 # TODO use doins 605 # TODO use doins
468 cp -r "${dir}" "${dir_to_install}" || die "cp failed" 606 cp -r "${dir}" "${dir_to_install}" || die "cp failed"
469 fi 607 fi
470 608
609 # Actual installation
610
471 java-pkg_dohtml -r ${dir_to_install} 611 java-pkg_dohtml -r "${dir_to_install}"
612
613 # Let's make a symlink to the directory we have everything else under
614 dosym ${dest}/api "${JAVA_PKG_SHAREPATH}/api" || die
615
616 if [[ ${symlink} ]]; then
617 dosym ${dest}/{api,${symlink}} || die
618 fi
472} 619}
473 620
474# ------------------------------------------------------------------------------ 621# ------------------------------------------------------------------------------
475# @ebuild-function java-pkg_dosrc 622# @ebuild-function java-pkg_dosrc
476# 623#
492# FIXME apparently this fails if you give it an empty directories 639# FIXME apparently this fails if you give it an empty directories
493java-pkg_dosrc() { 640java-pkg_dosrc() {
494 debug-print-function ${FUNCNAME} $* 641 debug-print-function ${FUNCNAME} $*
495 642
496 [ ${#} -lt 1 ] && die "At least one argument needed" 643 [ ${#} -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 644
501 java-pkg_check-phase install 645 java-pkg_check-phase install
502 646
503 [[ ${#} -lt 1 ]] && die "At least one argument needed" 647 [[ ${#} -lt 1 ]] && die "At least one argument needed"
648
649 if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
650 local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
651 java-pkg_announce-qa-violation ${msg}
652 fi
504 653
505 java-pkg_init_paths_ 654 java-pkg_init_paths_
506 655
507 local zip_name="${PN}-src.zip" 656 local zip_name="${PN}-src.zip"
508 local zip_path="${T}/${zip_name}" 657 local zip_path="${T}/${zip_name}"
509 local dir 658 local dir
510 for dir in ${@}; do 659 for dir in "${@}"; do
511 local dir_parent=$(dirname "${dir}") 660 local dir_parent=$(dirname "${dir}")
512 local dir_name=$(basename "${dir}") 661 local dir_name=$(basename "${dir}")
513 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 662 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
514 zip -q -r ${zip_path} ${dir_name} -i '*.java' 663 zip -q -r ${zip_path} ${dir_name} -i '*.java'
515 local result=$? 664 local result=$?
540# @param $1 - filename of launcher to create 689# @param $1 - filename of launcher to create
541# @param $2 - options, as follows: 690# @param $2 - options, as follows:
542# --main the.main.class.too.start 691# --main the.main.class.too.start
543# --jar /the/jar/too/launch.jar or just <name>.jar 692# --jar /the/jar/too/launch.jar or just <name>.jar
544# --java_args 'Extra arguments to pass to java' 693# --java_args 'Extra arguments to pass to java'
545# --pkg_args 'Extra arguments too pass to the package' 694# --pkg_args 'Extra arguments to pass to the package'
546# --pwd 695# --pwd Directory the launcher changes to before executing java
547# -into 696# -into Directory to install the launcher to, instead of /usr/bin
548# -pre 697# -pre Prepend contents of this file to the launcher
549# ------------------------------------------------------------------------------ 698# ------------------------------------------------------------------------------
550java-pkg_dolauncher() { 699java-pkg_dolauncher() {
551 debug-print-function ${FUNCNAME} $* 700 debug-print-function ${FUNCNAME} $*
552 701
553 java-pkg_check-phase install 702 java-pkg_check-phase install
565 local var_tmp="${T}/launcher_variables_tmp" 714 local var_tmp="${T}/launcher_variables_tmp"
566 local target_dir pre 715 local target_dir pre
567 716
568 # Process the other the rest of the arguments 717 # Process the other the rest of the arguments
569 while [[ -n "${1}" && -n "${2}" ]]; do 718 while [[ -n "${1}" && -n "${2}" ]]; do
570 local var=${1} value=${2} 719 local var="${1}" value="${2}"
571 if [[ "${var:0:2}" == "--" ]]; then 720 if [[ "${var:0:2}" == "--" ]]; then
572 local var=${var:2} 721 local var=${var:2}
573 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}" 722 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
574 local gjl_${var}="${value}" 723 local gjl_${var}="${value}"
575 elif [[ "${var}" == "-into" ]]; then 724 elif [[ "${var}" == "-into" ]]; then
594 fi 743 fi
595 fi 744 fi
596 745
597 # Write the actual script 746 # Write the actual script
598 echo "#!/bin/bash" > "${target}" 747 echo "#!/bin/bash" > "${target}"
599 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 748 if [[ -n "${pre}" ]]; then
749 if [[ -f "${pre}" ]]; then
750 cat "${pre}" >> "${target}"
751 else
752 die "-pre specified file '${pre}' does not exist"
753 fi
754 fi
600 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 755 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
601 cat "${var_tmp}" >> "${target}" 756 cat "${var_tmp}" >> "${target}"
602 rm -f "${var_tmp}" 757 rm -f "${var_tmp}"
603 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 758 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
604 759
696# Example: get a specific jar from xerces slot 2, and name it diffrently 851# 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 852# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
698# Example: get junit.jar which is needed only for building 853# Example: get junit.jar which is needed only for building
699# java-pkg_jar-from --build-only junit junit.jar 854# java-pkg_jar-from --build-only junit junit.jar
700# 855#
701# @param $1 - (optional) "--build-only" makes the jar(s) not added into 856# @param $opt
702# package.env DEPEND line. 857# --build-only - makes the jar(s) not added into package.env DEPEND line.
703# @param $1 - Package to get jars from. 858# (assumed automatically when called inside src_test)
859# --with-dependencies - get jars also from requested package's dependencies
860# transitively.
861# --virtual - Packages passed to this function are to be handled as virtuals
862# and will not have individual jar dependencies recorded.
863# --into $dir - symlink jar(s) into $dir (must exist) instead of .
864# @param $1 - Package to get jars from, or comma-separated list of packages in
865# case other parameters are not used.
704# @param $2 - jar from package. If not specified, all jars will be used. 866# @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 867# @param $3 - When a single jar is specified, destination filename of the
706# symlink. Defaults to the name of the jar. 868# symlink. Defaults to the name of the jar.
707# ------------------------------------------------------------------------------ 869# ------------------------------------------------------------------------------
708# TODO could probably be cleaned up a little 870# TODO could probably be cleaned up a little
709java-pkg_jar-from() { 871java-pkg_jar-from() {
710 debug-print-function ${FUNCNAME} $* 872 debug-print-function ${FUNCNAME} $*
711 873
712 local build_only="" 874 local build_only=""
875 local destdir="."
876 local deep=""
877 local virtual=""
713 878
879 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
880
881 while [[ "${1}" == --* ]]; do
714 if [[ "${1}" = "--build-only" ]]; then 882 if [[ "${1}" = "--build-only" ]]; then
715 build_only="true" 883 build_only="build"
884 elif [[ "${1}" = "--with-dependencies" ]]; then
885 deep="--with-dependencies"
886 elif [[ "${1}" = "--virtual" ]]; then
887 virtual="true"
888 elif [[ "${1}" = "--into" ]]; then
889 destdir="${2}"
890 shift
891 else
892 die "java-pkg_jar-from called with unknown parameter: ${1}"
893 fi
716 shift 894 shift
717 fi 895 done
718 896
719 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 897 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
720 898
721 [[ -z ${target_pkg} ]] && die "Must specify a package" 899 [[ -z ${target_pkg} ]] && die "Must specify a package"
900
901 if [[ "${EAPI}" == "1" ]]; then
902 target_pkg="${target_pkg//:/-}"
903 fi
722 904
723 # default destjar to the target jar 905 # default destjar to the target jar
724 [[ -z "${destjar}" ]] && destjar="${target_jar}" 906 [[ -z "${destjar}" ]] && destjar="${target_jar}"
725 907
726 local error_msg="There was a problem getting the classpath for ${target_pkg}." 908 local error_msg="There was a problem getting the classpath for ${target_pkg}."
727 local classpath 909 local classpath
728 classpath="$(java-config --classpath=${target_pkg})" 910 classpath="$(java-config ${deep} --classpath=${target_pkg})"
729 [[ $? != 0 ]] && die ${error_msg} 911 [[ $? != 0 ]] && die ${error_msg}
912
913 # When we have commas this functions is called to bring jars from multiple
914 # packages. This affects recording of dependencencies performed later
915 # which expects one package only, so we do it here.
916 if [[ ${target_pkg} = *,* ]]; then
917 for pkg in ${target_pkg//,/ }; do
918 java-pkg_ensure-dep "${build_only}" "${pkg}"
919 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
920 done
921 # setting this disables further record-jar_ calls later
922 build_only="build"
923 else
924 java-pkg_ensure-dep "${build_only}" "${target_pkg}"
925 fi
926
927 # Record the entire virtual as a dependency so that
928 # no jars are missed.
929 if [[ -z "${build_only}" && -n "${virtual}" ]]; then
930 java-pkg_record-jar_ "${target_pkg}"
931 # setting this disables further record-jars_ calls later
932 build_only="build"
933 fi
934
935 pushd ${destdir} > /dev/null \
936 || die "failed to change directory to ${destdir}"
730 937
731 local jar 938 local jar
732 for jar in ${classpath//:/ }; do 939 for jar in ${classpath//:/ }; do
733 local jar_name=$(basename "${jar}") 940 local jar_name=$(basename "${jar}")
734 if [[ ! -f "${jar}" ]] ; then 941 if [[ ! -f "${jar}" ]] ; then
745 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 952 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
746 [[ -f "${destjar}" ]] && rm "${destjar}" 953 [[ -f "${destjar}" ]] && rm "${destjar}"
747 ln -snf "${jar}" "${destjar}" \ 954 ln -snf "${jar}" "${destjar}" \
748 || die "Failed to make symlink from ${jar} to ${destjar}" 955 || die "Failed to make symlink from ${jar} to ${destjar}"
749 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}" 956 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
957 popd > /dev/null
750 return 0 958 return 0
751 fi 959 fi
752 done 960 done
961 popd > /dev/null
753 # if no target was specified, we're ok 962 # if no target was specified, we're ok
754 if [[ -z "${target_jar}" ]] ; then 963 if [[ -z "${target_jar}" ]] ; then
755 return 0 964 return 0
756 # otherwise, die bitterly 965 # otherwise, die bitterly
757 else 966 else
781# Example: Get the classpath for xerces-2 and xalan, 990# Example: Get the classpath for xerces-2 and xalan,
782# java-pkg_getjars xerces-2,xalan 991# java-pkg_getjars xerces-2,xalan
783# Example Return: 992# Example Return:
784# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 993# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
785# 994#
786# @param $1 - (optional) "--build-only" makes the jar(s) not added into 995# @param $opt
787# package.env DEPEND line. 996# --build-only - makes the jar(s) not added into package.env DEPEND line.
997# (assumed automatically when called inside src_test)
998# --with-dependencies - get jars also from requested package's dependencies
999# transitively.
788# @param $2 - list of packages to get jars from 1000# @param $1 - list of packages to get jars from
789# (passed to java-config --classpath) 1001# (passed to java-config --classpath)
790# ------------------------------------------------------------------------------ 1002# ------------------------------------------------------------------------------
791java-pkg_getjars() { 1003java-pkg_getjars() {
792 debug-print-function ${FUNCNAME} $* 1004 debug-print-function ${FUNCNAME} $*
793 1005
794 [[ ${#} -lt 1 || ${#} -gt 2 ]] && die "${FUNCNAME} takes only one or two arguments" 1006 local build_only=""
1007 local deep=""
795 1008
1009 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1010
1011 while [[ "${1}" == --* ]]; do
796 if [[ "${1}" = "--build-only" ]]; then 1012 if [[ "${1}" = "--build-only" ]]; then
797 local build_only="true" 1013 build_only="build"
1014 elif [[ "${1}" = "--with-dependencies" ]]; then
1015 deep="--with-dependencies"
1016 else
1017 die "java-pkg_jar-from called with unknown parameter: ${1}"
1018 fi
798 shift 1019 shift
799 fi 1020 done
1021
1022 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
1023
800 1024
801 local classpath pkgs="${1}" 1025 local classpath pkgs="${1}"
1026
1027 if [[ "${EAPI}" == "1" ]]; then
1028 pkgs="${pkgs//:/-}"
1029 fi
1030
802 jars="$(java-config --classpath=${pkgs})" 1031 jars="$(java-config ${deep} --classpath=${pkgs})"
803 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed" 1032 [[ $? != 0 || -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed"
804 debug-print "${pkgs}:${jars}" 1033 debug-print "${pkgs}:${jars}"
1034
1035 for pkg in ${pkgs//,/ }; do
1036 java-pkg_ensure-dep "${build_only}" "${pkg}"
1037 done
805 1038
806 if [[ -z "${classpath}" ]]; then 1039 if [[ -z "${classpath}" ]]; then
807 classpath="${jars}" 1040 classpath="${jars}"
808 else 1041 else
809 classpath="${classpath}:${jars}" 1042 classpath="${classpath}:${jars}"
810 fi 1043 fi
811 1044
812 # Only record jars that aren't build-only 1045 # Only record jars that aren't build-only
813 if [[ -z "${build_only}" ]]; then 1046 if [[ -z "${build_only}" ]]; then
814 oldifs="${IFS}"
815 IFS=","
816 for pkg in ${pkgs}; do 1047 for pkg in ${pkgs//,/ }; do
817 java-pkg_record-jar_ "${pkg}" 1048 java-pkg_record-jar_ "${pkg}"
818 done 1049 done
819 IFS="${oldifs}"
820 fi 1050 fi
821 1051
822 echo "${classpath}" 1052 echo "${classpath}"
823} 1053}
824 1054
834# @example 1064# @example
835# java-pkg_getjar xerces-2 xml-apis.jar 1065# java-pkg_getjar xerces-2 xml-apis.jar
836# @example-return 1066# @example-return
837# /usr/share/xerces-2/lib/xml-apis.jar 1067# /usr/share/xerces-2/lib/xml-apis.jar
838# 1068#
839# @param $1 - (optional) "--build-only" makes the jar not added into 1069# @param $opt
840# package.env DEPEND line. 1070# --build-only - makes the jar not added into package.env DEPEND line.
1071# --virtual - Packages passed to this function are to be handled as virtuals
1072# and will not have individual jar dependencies recorded.
841# @param $1 - package to use 1073# @param $1 - package to use
842# @param $2 - jar to get 1074# @param $2 - jar to get
843# ------------------------------------------------------------------------------ 1075# ------------------------------------------------------------------------------
844java-pkg_getjar() { 1076java-pkg_getjar() {
845 debug-print-function ${FUNCNAME} $* 1077 debug-print-function ${FUNCNAME} $*
846 1078
847 local build_only="" 1079 local build_only=""
1080 local virtual=""
848 1081
1082 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1083
1084 while [[ "${1}" == --* ]]; do
849 if [[ "${1}" = "--build-only" ]]; then 1085 if [[ "${1}" = "--build-only" ]]; then
850 build_only="true" 1086 build_only="build"
1087 elif [[ "${1}" == "--virtual" ]]; then
1088 virtual="true"
1089 else
1090 die "java-pkg_getjar called with unknown parameter: ${1}"
1091 fi
851 shift 1092 shift
852 fi 1093 done
1094
1095 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
853 1096
854 local pkg="${1}" target_jar="${2}" jar 1097 local pkg="${1}" target_jar="${2}" jar
1098
1099 if [[ "${EAPI}" == "1" ]]; then
1100 pkg="${pkg//:/-}"
1101 fi
1102
855 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 1103 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
856 [[ -z ${target_jar} ]] && die "Must specify jar to get" 1104 [[ -z ${target_jar} ]] && die "Must specify jar to get"
857 1105
858 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?" 1106 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
859 local classpath 1107 local classpath
860 classpath=$(java-config --classpath=${pkg}) 1108 classpath=$(java-config --classpath=${pkg})
861 [[ $? != 0 ]] && die ${error_msg} 1109 [[ $? != 0 ]] && die ${error_msg}
1110
1111 java-pkg_ensure-dep "${build_only}" "${pkg}"
1112
1113 # Record the package(Virtual) as a dependency and then set build_only
1114 # So that individual jars are not recorded.
1115 if [[ -n "${virtual}" ]]; then
1116 java-pkg_record-jar_ "${pkg}"
1117 build_only="true"
1118 fi
862 1119
863 for jar in ${classpath//:/ }; do 1120 for jar in ${classpath//:/ }; do
864 if [[ ! -f "${jar}" ]] ; then 1121 if [[ ! -f "${jar}" ]] ; then
865 die "Installation problem with jar ${jar} in ${pkg} - is it installed?" 1122 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
866 fi 1123 fi
873 fi 1130 fi
874 done 1131 done
875 1132
876 die "Could not find ${target_jar} in ${pkg}" 1133 die "Could not find ${target_jar} in ${pkg}"
877 return 1 1134 return 1
1135}
1136
1137# ------------------------------------------------------------------------------
1138# @ebuild-function java-pkg_register-dependency
1139#
1140# Registers runtime dependency on a package, list of packages, or a single jar
1141# from a package, into package.env DEPEND line. Can only be called in
1142# src_install phase.
1143# Intended for binary packages where you don't need to symlink the jars or get
1144# their classpath during build. As such, the dependencies only need to be
1145# specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1146#
1147# @param $1 - comma-separated list of packages, or a single package
1148# @param $2 - if param $1 is a single package, optionally specify the jar
1149# to depend on
1150#
1151# Example: Record the dependency on whole xerces-2 and xalan,
1152# java-pkg_register-dependency xerces-2,xalan
1153# Example: Record the dependency on ant.jar from ant-core
1154# java-pkg_register-dependency ant-core ant.jar
1155#
1156# Note: Passing both list of packages as the first parameter AND specifying the
1157# jar as the second is not allowed and will cause the function to die. We assume
1158# that there's more chance one passes such combination as a mistake, than that
1159# there are more packages providing identically named jar without class
1160# collisions.
1161# ------------------------------------------------------------------------------
1162java-pkg_register-dependency() {
1163 debug-print-function ${FUNCNAME} $*
1164
1165 java-pkg_check-phase install
1166
1167 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1168
1169 local pkgs="${1}"
1170 local jar="${2}"
1171
1172 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1173
1174 if [[ "${EAPI}" == "1" ]]; then
1175 pkgs="${pkgs//:/-}"
1176 fi
1177
1178 if [[ -z "${jar}" ]]; then
1179 for pkg in ${pkgs//,/ }; do
1180 java-pkg_ensure-dep runtime "${pkg}"
1181 java-pkg_record-jar_ "${pkg}"
1182 done
1183 else
1184 [[ ${pkgs} == *,* ]] && \
1185 die "${FUNCNAME} called with both package list and jar name"
1186 java-pkg_ensure-dep runtime "${pkgs}"
1187 java-pkg_record-jar_ "${pkgs}" "${jar}"
1188 fi
1189
1190 java-pkg_do_write_
1191}
1192
1193# ------------------------------------------------------------------------------
1194# @ebuild-function java-pkg_register-optional-dependency
1195#
1196# Registers optional runtime dependency on a package, list of packages, or a
1197# single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be
1198# called in src_install phase.
1199# Intended for packages that can use other packages when those are in classpath.
1200# Will be put on classpath by launcher if they are installed. Typical case is
1201# JDBC implementations for various databases. It's better than having USE flag
1202# for each implementation triggering hard dependency.
1203#
1204# @param $1 - comma-separated list of packages, or a single package
1205# @param $2 - if param $1 is a single package, optionally specify the jar
1206# to depend on
1207#
1208# Example: Record the optional dependency on some jdbc providers
1209# java-pkg_register-optional-dependency jdbc-jaybird,jtds-1.2,jdbc-mysql
1210#
1211# Note: Passing both list of packages as the first parameter AND specifying the
1212# jar as the second is not allowed and will cause the function to die. We assume
1213# that there's more chance one passes such combination as a mistake, than that
1214# there are more packages providing identically named jar without class
1215# collisions.
1216# ------------------------------------------------------------------------------
1217java-pkg_register-optional-dependency() {
1218 debug-print-function ${FUNCNAME} $*
1219
1220 java-pkg_check-phase install
1221
1222 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1223
1224 local pkgs="${1}"
1225 local jar="${2}"
1226
1227 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1228
1229 if [[ "${EAPI}" == "1" ]]; then
1230 pkgs="${pkgs//:/-}"
1231 fi
1232
1233 if [[ -z "${jar}" ]]; then
1234 for pkg in ${pkgs//,/ }; do
1235 java-pkg_record-jar_ --optional "${pkg}"
1236 done
1237 else
1238 [[ ${pkgs} == *,* ]] && \
1239 die "${FUNCNAME} called with both package list and jar name"
1240 java-pkg_record-jar_ --optional "${pkgs}" "${jar}"
1241 fi
1242
1243 java-pkg_do_write_
1244}
1245
1246# ------------------------------------------------------------------------------
1247# @ebuild-function java-pkg_register-environment-variable
1248#
1249# Register an arbitrary environment variable into package.env. The gjl launcher
1250# for this package or any package depending on this will export it into
1251# environement before executing java command.
1252# Must only be called in src_install phase.
1253#
1254# @param $1 - variable name
1255# @param $2 - variable value
1256# ------------------------------------------------------------------------------
1257JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
1258JAVA_PKG_EXTRA_ENV_VARS=""
1259java-pkg_register-environment-variable() {
1260 debug-print-function ${FUNCNAME} $*
1261
1262 java-pkg_check-phase install
1263
1264 [[ ${#} != 2 ]] && die "${FUNCNAME} takes two arguments"
1265
1266 echo "${1}=\"${2}\"" >> ${JAVA_PKG_EXTRA_ENV}
1267 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
1268
1269 java-pkg_do_write_
878} 1270}
879 1271
880# This function reads stdin, and based on that input, figures out how to 1272# This function reads stdin, and based on that input, figures out how to
881# populate jars from the filesystem. 1273# populate jars from the filesystem.
882# Need to figure out a good way of making use of this, ie be able to use a 1274# Need to figure out a good way of making use of this, ie be able to use a
999# 1391#
1000# export DEPEND="${DEPEND} ${depstr}" 1392# export DEPEND="${DEPEND} ${depstr}"
1001# export RDEPEND="${RDEPEND} ${depstr}" 1393# export RDEPEND="${RDEPEND} ${depstr}"
1002#} 1394#}
1003 1395
1396# ------------------------------------------------------------------------------
1397# @ebuild-function java-pkg_find-normal-jars
1398#
1399# Find the files with suffix .jar file in the given directory or $WORKDIR
1400#
1401# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1402# ------------------------------------------------------------------------------
1403java-pkg_find-normal-jars() {
1404 local dir=$1
1405 [[ "${dir}" ]] || dir="${WORKDIR}"
1406 local found
1407 for jar in $(find "${dir}" -name "*.jar" -type f); do
1408 echo "${jar}"
1409 found="true"
1410 done
1411 [[ "${found}" ]]
1412 return $?
1413}
1414
1415# ------------------------------------------------------------------------------
1416# @ebuild-function java-pkg_ensure-no-bundled-jars
1417#
1418# 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 1419# This function should be called after WORKDIR has been populated with symlink
1005# TODO document 1420# to system jar files or bundled jars removed.
1421# ------------------------------------------------------------------------------
1006java-pkg_ensure-no-bundled-jars() { 1422java-pkg_ensure-no-bundled-jars() {
1007 debug-print-function ${FUNCNAME} $* 1423 debug-print-function ${FUNCNAME} $*
1008 pushd ${WORKDIR} >/dev/null 2>/dev/null
1009 1424
1010 local bundled_jars=$(find . -name "*.jar" -type f) 1425 local bundled_jars=$(java-pkg_find-normal-jars)
1011 if [[ -n ${bundled_jars} ]]; then 1426 if [[ -n ${bundled_jars} ]]; then
1012 echo "Bundled jars found:" 1427 echo "Bundled jars found:"
1013 local jar 1428 local jar
1014 for jar in ${bundled_jars}; do 1429 for jar in ${bundled_jars}; do
1015 echo $(pwd)${jar/./} 1430 echo $(pwd)${jar/./}
1016 done 1431 done
1017 die "Bundled jars found!" 1432 die "Bundled jars found!"
1018
1019 fi 1433 fi
1020 popd >/dev/null 2>/dev/null
1021} 1434}
1022 1435
1023# ------------------------------------------------------------------------------ 1436# ------------------------------------------------------------------------------
1024# @internal-function java-pkg_ensure-vm-version-sufficient 1437# @internal-function java-pkg_ensure-vm-version-sufficient
1025# 1438#
1174# @ebuild-function java-pkg_get-target 1587# @ebuild-function java-pkg_get-target
1175# 1588#
1176# Determines what target version should be used, for passing to -target. 1589# 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 1590# If you don't care about lower versions, you can set _WANT_TARGET to the
1178# version of your JDK. 1591# 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# 1592#
1183# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1593# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1184# ------------------------------------------------------------------------------ 1594# ------------------------------------------------------------------------------
1185java-pkg_get-target() { 1595java-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}")} 1596 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1199} 1597}
1200 1598
1201java-pkg_get-javac() { 1599java-pkg_get-javac() {
1202 debug-print-function ${FUNCNAME} $* 1600 debug-print-function ${FUNCNAME} $*
1203 1601
1292 die "No GCJ support found!" 1690 die "No GCJ support found!"
1293 fi 1691 fi
1294} 1692}
1295 1693
1296java-pkg_ensure-test() { 1694java-pkg_ensure-test() {
1297 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} && ! use test; then 1695 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \
1696 && hasq test ${IUSE} && ! use test;
1697 then
1298 eerror "You specified FEATURES=test, but USE=test is needed" 1698 eerror "You specified FEATURES=test, but USE=test is needed"
1299 eerror "to pull in the additional dependencies for testing" 1699 eerror "to pull in the additional dependencies for testing"
1300 die "Need USE=test enabled" 1700 die "Need USE=test enabled"
1301 fi 1701 fi
1302} 1702}
1303 1703
1304# ------------------------------------------------------------------------------ 1704# ------------------------------------------------------------------------------
1705# @ebuild-function java-pkg_register-ant-task
1706#
1707# Register this package as ant task, so that ant will load it when no specific
1708# ANT_TASKS are specified. Note that even without this registering, all packages
1709# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1710# packages, but can be also used by other ebuilds that used to symlink their
1711# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1712# compatibility.
1713#
1714# @param --version x.y Register only for ant version x.y (otherwise for any ant
1715# version). Used by the ant-* packages to prevent loading of mismatched
1716# ant-core ant tasks after core was updated, before the tasks are updated,
1717# without a need for blockers.
1718# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1719# ------------------------------------------------------------------------------
1720java-pkg_register-ant-task() {
1721 local TASKS_DIR="tasks"
1722
1723 # check for --version x.y parameters
1724 while [[ -n "${1}" && -n "${2}" ]]; do
1725 local var="${1#--}"
1726 local val="${2}"
1727 if [[ "${var}" == "version" ]]; then
1728 TASKS_DIR="tasks-${val}"
1729 else
1730 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1731 fi
1732 shift 2
1733 done
1734
1735 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1736
1737 dodir /usr/share/ant/${TASKS_DIR}
1738 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1739}
1740
1741# ------------------------------------------------------------------------------
1742# @internal-function java-pkg_ant-tasks-depend
1743#
1744# Translates the WANT_ANT_TASKS variable into valid dependencies.
1745# ------------------------------------------------------------------------------
1746java-pkg_ant-tasks-depend() {
1747 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1748
1749 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1750 local DEP=""
1751 for i in ${WANT_ANT_TASKS}
1752 do
1753 if [[ ${i} != ant-* ]]; then
1754 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1755 return 1
1756 fi
1757 DEP="${DEP}dev-java/${i} "
1758 done
1759 echo ${DEP}
1760 return 0
1761 else
1762 return 0
1763 fi
1764}
1765
1766# ------------------------------------------------------------------------------
1767# @ebuild-function ejunit
1768#
1769# Junit wrapper function. Makes it easier to run the tests and checks for
1770# dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner.
1771#
1772# Examples:
1773# ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1774# ejunit org.blinkenlights.jid3.test.AllTests
1775#
1776# @param $1 - -cp or -classpath
1777# @param $2 - classpath; junit and recorded dependencies get appended
1778# @param $@ - the rest of the parameters are passed to java
1779# ------------------------------------------------------------------------------
1780ejunit() {
1781 debug-print-function ${FUNCNAME} $*
1782
1783 local pkgs
1784 for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
1785 pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
1786 done
1787
1788 local cp=$(java-pkg_getjars --with-dependencies junit${pkgs})
1789 if [[ ${1} = -cp || ${1} = -classpath ]]; then
1790 cp="${2}:${cp}"
1791 shift 2
1792 else
1793 cp=".:${cp}"
1794 fi
1795
1796 local runner=junit.textui.TestRunner
1797 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}"
1798 java -cp "${cp}" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
1799}
1800
1801# ------------------------------------------------------------------------------
1305# @section-end helper 1802# @section-end helper
1306# ------------------------------------------------------------------------------ 1803# ------------------------------------------------------------------------------
1307 1804
1308# ------------------------------------------------------------------------------ 1805# ------------------------------------------------------------------------------
1309# @section-begin build 1806# @section-begin build
1315 1812
1316# ------------------------------------------------------------------------------ 1813# ------------------------------------------------------------------------------
1317# @ebuild-function eant 1814# @ebuild-function eant
1318# 1815#
1319# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1816# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1320# compiler. 1817# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1321# 1818# variables:
1819# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1820# gentoo.classpath property. Be sure to call
1821# java-ant_rewrite-classpath in src_unpack.
1822# JAVA_PKG_NO_BUNDLED_SEARCH - Don't search for bundled jars or class files
1823# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1322# ------------------------------------------------------------------------------ 1824# ------------------------------------------------------------------------------
1323eant() { 1825eant() {
1324 debug-print-function ${FUNCNAME} $* 1826 debug-print-function ${FUNCNAME} $*
1325 1827
1326 # FIXME get this working 1828 if [[ ${EBUILD_PHASE} = compile ]]; then
1327# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then 1829 # Used to be done in hooks in java-ant-2.eclass but moved here so that we can
1830 # finally get rid of the hooks without breaking stuff
1831
1832 [[ "${JAVA_ANT_IGNORE_SYSTEM_CLASSES}" && "${JAVA_PKG_BSFIX}" ]] \
1833 && java-ant_ignore-system-classes "${S}/build.xml"
1834
1835 if hasq java-ant-2 ${INHERITED}; then
1836 java-ant_bsfix
1837 fi
1838
1839 # eant can be called multiple times
1840 JAVA_PKG_BSFIX="off"
1841
1842 if [[ -z ${JAVA_PKG_NO_BUNDLED_SEARCH} ]] && is-java-strict; then
1843 echo "Searching for bundled jars:"
1844 java-pkg_find-normal-jars || echo "None found."
1845 echo "Searching for bundled classes (no output if none found):"
1846 find "${WORKDIR}" -name "*.class"
1847 echo "Search done."
1848 JAVA_PKG_NO_BUNDLED_SEARCH=true # eant can be called many times
1849 fi
1850 fi
1851
1852 if ! hasq java-ant-2 ${INHERITED}; then
1853 local msg="You should inherit java-ant-2 when using eant"
1328# java-pkg_announce-qa-violation \ 1854 java-pkg_announce-qa-violation "${msg}"
1329# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1330# fi 1855 fi
1331 1856
1332 local antflags 1857 local antflags="-Dnoget=true -Dmaven.mode.offline=true -Dbuild.sysclasspath=ignore"
1858
1333 java-pkg_init-compiler_ 1859 java-pkg_init-compiler_
1334 local compiler="${GENTOO_COMPILER}" 1860 local compiler="${GENTOO_COMPILER}"
1335 1861
1336 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1862 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1337
1338 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})" 1863 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})"
1339 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1864 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1340 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1865 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1341 fi 1866 fi
1342 1867
1343 if [[ ${compiler} != "javac" ]]; then 1868 if [[ ${compiler} != "javac" ]]; then
1344 antflags="-Dbuild.compiler=${build_compiler}" 1869 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1345 # Figure out any extra stuff to put on the classpath for compilers aside 1870 # Figure out any extra stuff to put on the classpath for compilers aside
1346 # from javac 1871 # from javac
1347 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to 1872 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1348 # java-config -p 1873 # java-config -p
1349 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1874 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})"
1350 if [[ -n ${build_compiler_deps} ]]; then 1875 if [[ -n ${build_compiler_deps} ]]; then
1351 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})" 1876 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1352 fi 1877 fi
1353 fi 1878 fi
1354 1879
1880 for arg in "${@}"; do
1881 if [[ ${arg} = -lib ]]; then
1355 if is-java-strict; then 1882 if is-java-strict; then
1356 einfo "Disabling system classpath for ant" 1883 eerror "You should not use the -lib argument to eant because it will fail"
1357 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1884 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1885 eerror "or ant properties to make dependencies available."
1886 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1887 eerror "split ant (>=dev-java/ant-core-1.7)."
1888 die "eant -lib is deprecated/forbidden"
1889 else
1890 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1891 echo "more info."
1892 fi
1358 fi 1893 fi
1894 done
1359 1895
1360 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1896 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1361 antflags="${antflags} -debug" 1897 ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}"
1898
1899 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1900 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1901
1902 # if ant-tasks is not set by ebuild or forced, use none
1903 ANT_TASKS="${ANT_TASKS:-none}"
1904
1905 # at this point, ANT_TASKS should be "all", "none" or explicit list
1906 if [[ "${ANT_TASKS}" == "all" ]]; then
1907 einfo "Using all available ANT_TASKS"
1908 elif [[ "${ANT_TASKS}" == "none" ]]; then
1909 einfo "Disabling all optional ANT_TASKS"
1910 else
1911 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1912 fi
1913
1914 export ANT_TASKS
1915
1916 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1917 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1918
1919 local gcp="${EANT_GENTOO_CLASSPATH}"
1920 local getjarsarg=""
1921
1922 if [[ ${EBUILD_PHASE} = "test" ]]; then
1923 antflags="${antflags} -DJunit.present=true"
1924 [[ ${gcp} && ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1925 getjarsarg="--with-dependencies"
1926 fi
1927
1928 local cp
1929
1930 for atom in ${gcp}; do
1931 cp="${cp}:$(java-pkg_getjars ${getjarsarg} ${atom})"
1932 done
1933
1934 if [[ ${cp} ]]; then
1935 # It seems ant does not like single quotes around ${cp}
1936 antflags="${antflags} -Dgentoo.classpath=\"${cp#:}\""
1362 fi 1937 fi
1363 1938
1364 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1939 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1940 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
1365 ant ${antflags} "${@}" || die "eant failed" 1941 ant ${antflags} "${@}" || die "eant failed"
1366
1367} 1942}
1368 1943
1369# ------------------------------------------------------------------------------ 1944# ------------------------------------------------------------------------------
1370# @ebuild-function ejavac 1945# @ebuild-function ejavac
1371# 1946#
1440# ------------------------------------------------------------------------------ 2015# ------------------------------------------------------------------------------
1441use_doc() { 2016use_doc() {
1442 use doc && echo ${@:-javadoc} 2017 use doc && echo ${@:-javadoc}
1443} 2018}
1444 2019
2020
1445# ------------------------------------------------------------------------------ 2021# ------------------------------------------------------------------------------
1446# @section-end build 2022# @section-end build
1447# ------------------------------------------------------------------------------ 2023# ------------------------------------------------------------------------------
1448 2024
1449# ------------------------------------------------------------------------------ 2025# ------------------------------------------------------------------------------
1465# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will 2041# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will
1466# call it during each of the phases of the merge process. 2042# call it during each of the phases of the merge process.
1467# 2043#
1468# ----------------------------------------------------------------------------- 2044# -----------------------------------------------------------------------------
1469java-pkg_init() { 2045java-pkg_init() {
2046 debug-print-function ${FUNCNAME} $*
1470 unset JAVAC 2047 unset JAVAC
1471 unset JAVA_HOME 2048 unset JAVA_HOME
2049
2050 # People do all kinds of weird things.
2051 # http://forums.gentoo.org/viewtopic-p-3943166.html
2052 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
2053 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
2054 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
2055 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
2056 ewarn "sun-jdk vms and and as such break configure scripts that"
2057 ewarn "use it (for example app-office/openoffice) so we filter it out."
2058 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
2059 ewarn "make.conf for example) to silence this warning or"
2060 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
2061 fi
2062
2063 if [[ -z ${accept} ]]; then
2064 # export _JAVA_OPTIONS= doesn't work because it will show up in java
2065 # -version output
2066 unset _JAVA_OPTIONS
2067 # phase hooks make this run many times without this
2068 I_WANT_GLOBAL_JAVA_OPTIONS="true"
2069 fi
2070
2071 if java-pkg_func-exists ant_src_unpack; then
2072 java-pkg_announce-qa-violation "Using old ant_src_unpack. Should be src_unpack"
2073 fi
2074
1472 java-pkg_init_paths_ 2075 java-pkg_init_paths_
1473 java-pkg_switch-vm 2076 java-pkg_switch-vm
1474 PATH=${JAVA_HOME}/bin:${PATH} 2077 PATH=${JAVA_HOME}/bin:${PATH}
1475 2078
1476 # TODO we will probably want to set JAVAC and JAVACFLAGS 2079 # TODO we will probably want to set JAVAC and JAVACFLAGS
1477 2080
1478 # Do some QA checks 2081 # Do some QA checks
1479 java-pkg_check-jikes 2082 java-pkg_check-jikes
2083
2084 # Can't use unset here because Portage does not save the unset
2085 # see https://bugs.gentoo.org/show_bug.cgi?id=189417#c11
1480 2086
1481 # When users have crazy classpaths some packages can fail to compile. 2087 # When users have crazy classpaths some packages can fail to compile.
1482 # and everything should work with empty CLASSPATH. 2088 # and everything should work with empty CLASSPATH.
1483 # This also helps prevent unexpected dependencies on random things 2089 # This also helps prevent unexpected dependencies on random things
1484 # from the CLASSPATH. 2090 # from the CLASSPATH.
1485 unset CLASSPATH 2091 export CLASSPATH=
2092
2093 # Unset external ANT_ stuff
2094 export ANT_TASKS=
2095 export ANT_OPTS=
1486} 2096}
1487 2097
1488# ------------------------------------------------------------------------------ 2098# ------------------------------------------------------------------------------
1489# @function-internal java-pkg-init-compiler_ 2099# @function-internal java-pkg-init-compiler_
1490# 2100#
1581 done 2191 done
1582 2192
1583 # If it hasn't been defined already, default to javac 2193 # If it hasn't been defined already, default to javac
1584 if [[ -z ${GENTOO_COMPILER} ]]; then 2194 if [[ -z ${GENTOO_COMPILER} ]]; then
1585 if [[ -n ${compilers} ]]; then 2195 if [[ -n ${compilers} ]]; then
1586 einfo "No suitable compiler found: defaulting javac for compilation" 2196 einfo "No suitable compiler found: defaulting to JDK default for compilation"
1587 else 2197 else
1588 # probably don't need to notify users about the default. 2198 # probably don't need to notify users about the default.
1589 :;#einfo "Defaulting to javac for compilation" 2199 :;#einfo "Defaulting to javac for compilation"
1590 fi 2200 fi
2201 if java-config -g GENTOO_COMPILER 2> /dev/null; then
2202 export GENTOO_COMPILER=$(java-config -g GENTOO_COMPILER)
2203 else
1591 export GENTOO_COMPILER=javac 2204 export GENTOO_COMPILER=javac
2205 fi
1592 else 2206 else
1593 einfo "Using ${GENTOO_COMPILER} for compilation" 2207 einfo "Using ${GENTOO_COMPILER} for compilation"
1594 fi 2208 fi
1595 2209
1596} 2210}
1612 fi 2226 fi
1613 2227
1614 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}" 2228 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}"
1615 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/" 2229 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/"
1616 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env" 2230 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env"
2231 JAVA_PKG_VIRTUALS_PATH="${DESTTREE}/share/java-config-2/virtuals"
2232 JAVA_PKG_VIRTUAL_PROVIDER="${D}/${JAVA_PKG_VIRTUALS_PATH}/${JAVA_PKG_NAME}"
1617 2233
1618 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib" 2234 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib"
1619 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}" 2235 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}"
1620 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps" 2236 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps"
1621 2237
1634# Writes the package.env out to disk. 2250# Writes the package.env out to disk.
1635# 2251#
1636# ------------------------------------------------------------------------------ 2252# ------------------------------------------------------------------------------
1637# TODO change to do-write, to match everything else 2253# TODO change to do-write, to match everything else
1638java-pkg_do_write_() { 2254java-pkg_do_write_() {
2255 debug-print-function ${FUNCNAME} $*
1639 java-pkg_init_paths_ 2256 java-pkg_init_paths_
1640 # Create directory for package.env 2257 # Create directory for package.env
1641 dodir "${JAVA_PKG_SHAREPATH}" 2258 dodir "${JAVA_PKG_SHAREPATH}"
1642 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 2259 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f \
2260 "${JAVA_PKG_DEPEND_FILE}" || -f \
2261 "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]]; then
1643 # Create package.env 2262 # Create package.env
1644 ( 2263 (
1645 echo "DESCRIPTION=\"${DESCRIPTION}\"" 2264 echo "DESCRIPTION=\"${DESCRIPTION}\""
1646 echo "GENERATION=\"2\"" 2265 echo "GENERATION=\"2\""
2266 echo "SLOT=\"${SLOT}\""
1647 2267
1648 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\"" 2268 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
1649 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 2269 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1650 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 2270 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1651 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 2271 [[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
2272 && echo "DEPEND=\"$(cat "${JAVA_PKG_DEPEND_FILE}" | uniq | tr '\n' ':')\""
2273 [[ -f "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]] \
2274 && echo "OPTIONAL_DEPEND=\"$(cat "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" | uniq | tr '\n' ':')\""
1652 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 2275 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1653 ) > "${JAVA_PKG_ENV}" 2276 ) > "${JAVA_PKG_ENV}"
1654 2277
1655 # register target/source 2278 # register target/source
1656 local target="$(java-pkg_get-target)" 2279 local target="$(java-pkg_get-target)"
1667 2290
1668 2291
1669 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}" 2292 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
1670 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}" 2293 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
1671 2294
2295 # extra env variables
2296 if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
2297 cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}" || die
2298 # nested echo to remove leading/trailing spaces
2299 echo "ENV_VARS=\"$(echo ${JAVA_PKG_EXTRA_ENV_VARS})\"" \
2300 >> "${JAVA_PKG_ENV}" || die
2301 fi
2302
1672 # Strip unnecessary leading and trailing colons 2303 # Strip unnecessary leading and trailing colons
1673 # TODO try to cleanup if possible 2304 # TODO try to cleanup if possible
1674 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 2305 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
2306 else
2307 debug-print "JAVA_PKG_CLASSPATH, JAVA_PKG_LIBRARY, JAVA_PKG_DEPEND_FILE"
2308 debug-print "or JAVA_PKG_OPTIONAL_DEPEND_FILE not defined so can't"
2309 debug-print "write package.env."
1675 fi 2310 fi
1676} 2311}
1677 2312
1678# ------------------------------------------------------------------------------ 2313# ------------------------------------------------------------------------------
1679# @internal-function java-pkg_record-jar_ 2314# @internal-function java-pkg_record-jar_
1680# 2315#
1681# Record a dependency to the package.env 2316# Record an (optional) dependency to the package.env
1682# 2317# @param --optional - record dependency as optional
2318# @param $1 - package to record
2319# @param $2 - (optional) jar of package to record
1683# ------------------------------------------------------------------------------ 2320# ------------------------------------------------------------------------------
1684JAVA_PKG_DEPEND="${T}/java-pkg-depend" 2321JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2322JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
1685 2323
1686java-pkg_record-jar_() { 2324java-pkg_record-jar_() {
1687 debug-print-function ${FUNCNAME} $* 2325 debug-print-function ${FUNCNAME} $*
2326
2327 local depend_file="${JAVA_PKG_DEPEND_FILE}"
2328 if [[ "${1}" == "--optional" ]]; then
2329 depend_file="${JAVA_PKG_OPTIONAL_DEPEND_FILE}"
2330 shift
2331 fi
1688 2332
1689 local pkg=${1} jar=${2} append 2333 local pkg=${1} jar=${2} append
1690 if [[ -z "${jar}" ]]; then 2334 if [[ -z "${jar}" ]]; then
1691 append="${pkg}" 2335 append="${pkg}"
1692 else 2336 else
1693 append="$(basename ${jar})@${pkg}" 2337 append="$(basename ${jar})@${pkg}"
1694 fi 2338 fi
1695 2339
1696 echo ${append} >> ${JAVA_PKG_DEPEND} 2340 echo "${append}" >> "${depend_file}"
1697} 2341}
1698 2342
1699# ------------------------------------------------------------------------------ 2343# ------------------------------------------------------------------------------
1700# @internal-function java-pkg_append_ 2344# @internal-function java-pkg_append_
1701# 2345#
1761# 2405#
1762# ------------------------------------------------------------------------------ 2406# ------------------------------------------------------------------------------
1763java-pkg_setup-vm() { 2407java-pkg_setup-vm() {
1764 debug-print-function ${FUNCNAME} $* 2408 debug-print-function ${FUNCNAME} $*
1765 2409
2410 export LANG="C" LC_ALL="C"
2411
1766 local vendor="$(java-pkg_get-vm-vendor)" 2412 local vendor="$(java-pkg_get-vm-vendor)"
1767 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then 2413 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1768 addpredict "/dev/random" 2414 addpredict "/dev/random"
1769 elif [[ "${vendor}" == "ibm" ]]; then 2415 elif [[ "${vendor}" == "ibm" ]]; then
1770 addpredict "/proc/self/maps" 2416 addpredict "/proc/self/maps"
1771 addpredict "/proc/cpuinfo" 2417 addpredict "/proc/cpuinfo"
1772 export LANG="C" LC_ALL="C"
1773 elif [[ "${vendor}" == "jrockit" ]]; then 2418 elif [[ "${vendor}" == "jrockit" ]]; then
1774 addpredict "/proc/cpuinfo" 2419 addpredict "/proc/cpuinfo"
1775 fi 2420 fi
1776} 2421}
1777 2422
1832# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 2477# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1833# verify that the current VM is sufficient. 2478# verify that the current VM is sufficient.
1834# Setup the environment for the VM being used. 2479# Setup the environment for the VM being used.
1835# ------------------------------------------------------------------------------ 2480# ------------------------------------------------------------------------------
1836java-pkg_switch-vm() { 2481java-pkg_switch-vm() {
2482 debug-print-function ${FUNCNAME} $*
2483
1837 if java-pkg_needs-vm; then 2484 if java-pkg_needs-vm; then
1838 # Use the VM specified by JAVA_PKG_FORCE_VM 2485 # Use the VM specified by JAVA_PKG_FORCE_VM
1839 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then 2486 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1840 # If you're forcing the VM, I hope you know what your doing... 2487 # If you're forcing the VM, I hope you know what your doing...
2488 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1841 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 2489 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1842 # if we're allowed to switch the vm... 2490 # if we're allowed to switch the vm...
1843 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 2491 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}" 2492 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1845 if [[ -n ${JAVA_PKG_VNEED} ]]; then 2493 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1878 2526
1879 #TODO If you know a better solution let us know. 2527 #TODO If you know a better solution let us know.
1880 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 2528 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1881 2529
1882 local tann="${T}/announced-vm" 2530 local tann="${T}/announced-vm"
2531 # With the hooks we should only get here once from pkg_setup but better safe than sorry
2532 # if people have for example modified eclasses some where
1883 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 2533 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1884 # Add a check for setup/preinst phase... to avoid duplicate outputs
1885 # for when FEATURES=buildpkg
1886 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1887 then
1888 einfo "Using: $(java-config -f)" 2534 einfo "Using: $(java-config -f)"
1889 [[ ! -f "${tann}" ]] && touch "${tann}" 2535 [[ ! -f "${tann}" ]] && touch "${tann}"
1890 fi
1891 fi 2536 fi
1892 2537
1893 else 2538 else
1894 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!" 2539 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!"
1895 fi 2540 fi
1925 einfo "Classes" 2570 einfo "Classes"
1926 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR}," 2571 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1927 fi 2572 fi
1928} 2573}
1929 2574
1930# TODO document 2575# ------------------------------------------------------------------------------
2576# @internal-function java-pkg_verify-classes
2577#
1931# Verify that the classes were compiled for the right source / target 2578# Verify that the classes were compiled for the right source / target. Dies if
2579# not.
2580# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2581# ------------------------------------------------------------------------------
1932java-pkg_verify-classes() { 2582java-pkg_verify-classes() {
1933 ebegin "Verifying java class versions"
1934 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 2583 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1935 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 2584 local target=$(java-pkg_get-target)
2585 local result
2586 local log="${T}/class-version-verify.log"
2587 if [[ -n "${1}" ]]; then
2588 class-version-verify.py -v -t ${target} "${1}" > "${log}"
1936 result=$? 2589 result=$?
1937 eend ${result}
1938 if [[ ${result} == 0 ]]; then
1939 einfo "All good"
1940 else 2590 else
1941 ewarn "Possible problem" 2591 ebegin "Verifying java class versions (target: ${target})"
1942 die "Bad class files found" 2592 class-version-verify.py -v -t ${target} -r "${D}" > "${log}"
2593 result=$?
2594 eend ${result}
2595 fi
2596 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2597 if [[ ${result} != 0 ]]; then
2598 eerror "Incorrect bytecode version found"
2599 [[ -n "${1}" ]] && eerror "in file: ${1}"
2600 eerror "See ${log} for more details."
2601 die "Incorrect bytecode found"
2602 fi
2603}
2604
2605# ----------------------------------------------------------------------------
2606# @internal-function java-pkg_ensure-dep
2607# Check that a package being used in jarfrom, getjars and getjar is contained
2608# within DEPEND or RDEPEND.
2609# @param $1 - empty - check both vars; "runtime" or "build" - check only
2610# RDEPEND, resp. DEPEND
2611# @param $2 - Package name and slot.
2612
2613java-pkg_ensure-dep() {
2614 debug-print-function ${FUNCNAME} $*
2615
2616 local limit_to="${1}"
2617 local target_pkg="${2}"
2618 local dev_error=""
2619
2620 local stripped_pkg=$(echo "${target_pkg}" | sed \
2621 's/-[0-9]*\(\.[0-9]\)*$//')
2622
2623 debug-print "Matching against: ${stripped_pkg}"
2624
2625 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2626 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2627 dev_error="${dev_error} declared in DEPEND."
2628 if is-java-strict; then
2629 eerror "${dev_error}"
2630 die "${dev_error}"
2631 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2632 eerror "${dev_error}"
2633 elog "Because you have this package installed the package will"
2634 elog "build without problems, but please report this to"
2635 elog "http://bugs.gentoo.org"
2636 fi
2637 fi
2638
2639 if [[ ${limit_to} != build ]]; then
2640 if [[ ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2641 if [[ ! ( ${PDEPEND} =~ "${stripped_pkg}" ) ]]; then
2642 dev_error="The ebuild is attempting to use ${target_pkg},"
2643 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND"
2644 dev_error="${dev_error} or PDEPEND."
2645 if is-java-strict; then
2646 eerror "${dev_error}"
2647 die "${dev_error}"
2648 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2649 eerror "${dev_error}"
2650 elog "The package will build without problems, but may fail to run"
2651 elog "if you don't have ${target_pkg} installed, so please report"
2652 elog "this to http://bugs.gentoo.org"
2653 fi
2654 fi
2655 fi
1943 fi 2656 fi
1944} 2657}
1945 2658
1946# ------------------------------------------------------------------------------ 2659# ------------------------------------------------------------------------------
1947# @section-end internal 2660# @section-end internal
1948# ------------------------------------------------------------------------------ 2661# ------------------------------------------------------------------------------
1949 2662
1950java-pkg_check-phase() { 2663java-pkg_check-phase() {
1951 local phase=${1} 2664 local phase=${1}
1952 local funcname=${2} 2665 local funcname=${FUNCNAME[1]}
1953 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then 2666 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
1954 java-pkg_announce-qa-violation \
1955 "${funcname} used outside of src_${phase}" 2667 local msg="${funcname} used outside of src_${phase}"
2668 java-pkg_announce-qa-violation "${msg}"
1956 fi 2669 fi
1957} 2670}
1958 2671
1959java-pkg_check-versioned-jar() { 2672java-pkg_check-versioned-jar() {
1960 local jar=${1} 2673 local jar=${1}
1969 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2682 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1970 fi 2683 fi
1971} 2684}
1972 2685
1973java-pkg_announce-qa-violation() { 2686java-pkg_announce-qa-violation() {
1974 if is-java-strict; then 2687 local nodie
2688 if [[ ${1} == "--nodie" ]]; then
2689 nodie="true"
2690 shift
2691 fi
1975 echo "Java QA Notice: $@" >&2 2692 echo "Java QA Notice: $@" >&2
1976 increment-qa-violations 2693 increment-qa-violations
1977 fi 2694 [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
1978} 2695}
1979 2696
1980increment-qa-violations() { 2697increment-qa-violations() {
1981 let "JAVA_PKG_QA_VIOLATIONS+=1" 2698 let "JAVA_PKG_QA_VIOLATIONS+=1"
1982 export JAVA_PKG_QA_VIOLATIONS 2699 export JAVA_PKG_QA_VIOLATIONS

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

  ViewVC Help
Powered by ViewVC 1.1.20