/[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.38 Revision 1.126
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.38 2006/12/31 19:30:54 betelgeuse Exp $ 9# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.126 2009/03/31 19:19:20 betelgeuse Exp $
10
11 10
12# ----------------------------------------------------------------------------- 11# -----------------------------------------------------------------------------
13# @eclass-begin 12# @eclass-begin
14# @eclass-shortdesc Java Utility eclass 13# @eclass-shortdesc Java Utility eclass
15# @eclass-maintainer java@gentoo.org 14# @eclass-maintainer java@gentoo.org
36# ----------------------------------------------------------------------------- 35# -----------------------------------------------------------------------------
37 36
38# Make sure we use java-config-2 37# Make sure we use java-config-2
39export WANT_JAVA_CONFIG="2" 38export WANT_JAVA_CONFIG="2"
40 39
41# TODO document 40# -----------------------------------------------------------------------------
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
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
207
208# ------------------------------------------------------------------------------ 296# ------------------------------------------------------------------------------
209# @internal-function depend-java-query 297# @internal-function depend-java-query
210# 298#
211# 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.
212# 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
213# do not handle use flags. 301# do not handle use flags.
214# ------------------------------------------------------------------------------ 302# ------------------------------------------------------------------------------
215 303
216depend-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.
217 USE="${USE}" $(which depend-java-query) "${@}" 307 USE="${USE}" /usr/bin/depend-java-query "${@}"
218} 308}
219 309
220# ------------------------------------------------------------------------------ 310# ------------------------------------------------------------------------------
221# @ebuild-function java-pkg_regjar 311# @ebuild-function java-pkg_regjar
222# 312#
254 [[ ${#} -lt 1 ]] && die "at least one argument needed" 344 [[ ${#} -lt 1 ]] && die "at least one argument needed"
255 345
256 java-pkg_init_paths_ 346 java-pkg_init_paths_
257 347
258 local jar jar_dir jar_file 348 local jar jar_dir jar_file
259 for jar in "$@"; do 349 for jar in "${@}"; do
260 # TODO use java-pkg_check-versioned-jar 350 # TODO use java-pkg_check-versioned-jar
261 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then 351 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
262 [[ -d "${jar}" || -d "${D}${jar}" ]] \ 352 [[ -d "${jar}" || -d "${D}${jar}" ]] \
263 && 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
264 # 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:
265 # imagine such call: 359 # imagine such call:
266 # java-pkg_regjar ${D}/opt/java/*.jar 360 # java-pkg_regjar ${D}/opt/java/*.jar
267 # such call will fall into this case (-e ${jar}) and will 361 # such call will fall into this case (-e ${jar}) and will
268 # record paths with ${D} in package.env 362 # record paths with ${D} in package.env
269 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 363 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
270 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"
271 die "${jar} does not exist" 371 die "${jar} does not exist"
272 fi 372 fi
273 done 373 done
274 374
275 java-pkg_do_write_ 375 java-pkg_do_write_
292 local original_jar="${1}" 392 local original_jar="${1}"
293 local new_jar="${2:-${PN}.jar}" 393 local new_jar="${2:-${PN}.jar}"
294 local new_jar_dest="${T}/${new_jar}" 394 local new_jar_dest="${T}/${new_jar}"
295 395
296 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 396 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
297 [[ ! -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!"
298 399
299 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}"
300 cp "${original_jar}" "${new_jar_dest}" \ 401 cp "${original_jar}" "${new_jar_dest}" \
301 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 402 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
302 java-pkg_dojar "${new_jar_dest}" 403 java-pkg_dojar "${new_jar_dest}"
345 if [[ -e "${lib}" ]] ; then 446 if [[ -e "${lib}" ]] ; then
346 # install if it isn't a symlink 447 # install if it isn't a symlink
347 if [[ ! -L "${lib}" ]] ; then 448 if [[ ! -L "${lib}" ]] ; then
348 INSDESTTREE="${JAVA_PKG_LIBDEST}" \ 449 INSDESTTREE="${JAVA_PKG_LIBDEST}" \
349 INSOPTIONS="${LIBOPTIONS}" \ 450 INSOPTIONS="${LIBOPTIONS}" \
350 doins "${lib}" || "failed to install ${lib}" 451 doins "${lib}" || die "failed to install ${lib}"
351 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 452 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
352 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 453 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
353 # otherwise make a symlink to the symlink's origin 454 # otherwise make a symlink to the symlink's origin
354 else 455 else
355 # TODO use dosym 456 # TODO use dosym
457 ln -s "$(readlink "${lib}")" \
356 ln -s "$(readlink "${lib}")" "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")" 458 "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")"
357 debug-print "${lib} is a symlink, linking accordanly" 459 debug-print "${lib} is a symlink, linking accordanly"
358 fi 460 fi
359 # otherwise die 461 # otherwise die
360 else 462 else
361 die "${lib} does not exist" 463 die "${lib} does not exist"
455# ------------------------------------------------------------------------------ 557# ------------------------------------------------------------------------------
456# @ebuild-function java-pkg_dojavadoc 558# @ebuild-function java-pkg_dojavadoc
457# 559#
458# Installs javadoc documentation. This should be controlled by the doc use flag. 560# Installs javadoc documentation. This should be controlled by the doc use flag.
459# 561#
562# @param $1: optional --symlink creates to symlink like this for html
563# documentation bundles.
460# @param $1: - The javadoc root directory. 564# @param $2: - The javadoc root directory.
461# 565#
462# @example: 566# @example:
463# java-pkg_dojavadoc docs/api 567# java-pkg_dojavadoc docs/api
568# java-pkg_dojavadoc --symlink apidocs docs/api
464# 569#
465# ------------------------------------------------------------------------------ 570# ------------------------------------------------------------------------------
466java-pkg_dojavadoc() { 571java-pkg_dojavadoc() {
572 debug-print-function ${FUNCNAME} $*
573
574 # For html documentation bundles that link to Javadoc
575 local symlink
576 if [[ ${1} = --symlink ]]; then
577 symlink=${2}
578 shift 2
579 fi
580
467 local dir="$1" 581 local dir="$1"
582 local dest=/usr/share/doc/${PF}/html
583
584 # QA checks
468 585
469 java-pkg_check-phase install 586 java-pkg_check-phase install
470 587
471 [[ -z "${dir}" ]] && die "Must specify a directory!" 588 [[ -z "${dir}" ]] && die "Must specify a directory!"
472 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!" 589 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!"
590 if [[ ! -e "${dir}/index.html" ]]; then
591 local msg="No index.html in javadoc directory"
592 ewarn "${msg}"
593 is-java-strict && die "${msg}"
594 fi
595
596 if [[ -e ${D}/${dest}/api ]]; then
597 eerror "${dest} already exists. Will not overwrite."
598 die "${dest}"
599 fi
600
601 # Renaming to match our directory layout
473 602
474 local dir_to_install="${dir}" 603 local dir_to_install="${dir}"
475 if [[ "$(basename "${dir}")" != "api" ]]; then 604 if [[ "$(basename "${dir}")" != "api" ]]; then
476 dir_to_install="${T}/api" 605 dir_to_install="${T}/api"
477 # TODO use doins 606 # TODO use doins
478 cp -r "${dir}" "${dir_to_install}" || die "cp failed" 607 cp -r "${dir}" "${dir_to_install}" || die "cp failed"
479 fi 608 fi
480 609
610 # Actual installation
611
481 java-pkg_dohtml -r ${dir_to_install} 612 java-pkg_dohtml -r "${dir_to_install}"
613
614 # Let's make a symlink to the directory we have everything else under
615 dosym ${dest}/api "${JAVA_PKG_SHAREPATH}/api" || die
616
617 if [[ ${symlink} ]]; then
618 debug-print "symlinking ${dest}/{api,${symlink}}"
619 dosym ${dest}/{api,${symlink}} || die
620 fi
482} 621}
483 622
484# ------------------------------------------------------------------------------ 623# ------------------------------------------------------------------------------
485# @ebuild-function java-pkg_dosrc 624# @ebuild-function java-pkg_dosrc
486# 625#
502# FIXME apparently this fails if you give it an empty directories 641# FIXME apparently this fails if you give it an empty directories
503java-pkg_dosrc() { 642java-pkg_dosrc() {
504 debug-print-function ${FUNCNAME} $* 643 debug-print-function ${FUNCNAME} $*
505 644
506 [ ${#} -lt 1 ] && die "At least one argument needed" 645 [ ${#} -lt 1 ] && die "At least one argument needed"
507 if ! hasq source ${IUSE}; then
508 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
509 fi
510 646
511 java-pkg_check-phase install 647 java-pkg_check-phase install
512 648
513 [[ ${#} -lt 1 ]] && die "At least one argument needed" 649 [[ ${#} -lt 1 ]] && die "At least one argument needed"
650
651 if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
652 local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
653 java-pkg_announce-qa-violation ${msg}
654 fi
514 655
515 java-pkg_init_paths_ 656 java-pkg_init_paths_
516 657
517 local zip_name="${PN}-src.zip" 658 local zip_name="${PN}-src.zip"
518 local zip_path="${T}/${zip_name}" 659 local zip_path="${T}/${zip_name}"
519 local dir 660 local dir
520 for dir in ${@}; do 661 for dir in "${@}"; do
521 local dir_parent=$(dirname "${dir}") 662 local dir_parent=$(dirname "${dir}")
522 local dir_name=$(basename "${dir}") 663 local dir_name=$(basename "${dir}")
523 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 664 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
524 zip -q -r ${zip_path} ${dir_name} -i '*.java' 665 zip -q -r ${zip_path} ${dir_name} -i '*.java'
525 local result=$? 666 local result=$?
550# @param $1 - filename of launcher to create 691# @param $1 - filename of launcher to create
551# @param $2 - options, as follows: 692# @param $2 - options, as follows:
552# --main the.main.class.too.start 693# --main the.main.class.too.start
553# --jar /the/jar/too/launch.jar or just <name>.jar 694# --jar /the/jar/too/launch.jar or just <name>.jar
554# --java_args 'Extra arguments to pass to java' 695# --java_args 'Extra arguments to pass to java'
555# --pkg_args 'Extra arguments too pass to the package' 696# --pkg_args 'Extra arguments to pass to the package'
556# --pwd 697# --pwd Directory the launcher changes to before executing java
557# -into 698# -into Directory to install the launcher to, instead of /usr/bin
558# -pre 699# -pre Prepend contents of this file to the launcher
559# ------------------------------------------------------------------------------ 700# ------------------------------------------------------------------------------
560java-pkg_dolauncher() { 701java-pkg_dolauncher() {
561 debug-print-function ${FUNCNAME} $* 702 debug-print-function ${FUNCNAME} $*
562 703
563 java-pkg_check-phase install 704 java-pkg_check-phase install
604 fi 745 fi
605 fi 746 fi
606 747
607 # Write the actual script 748 # Write the actual script
608 echo "#!/bin/bash" > "${target}" 749 echo "#!/bin/bash" > "${target}"
609 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 750 if [[ -n "${pre}" ]]; then
751 if [[ -f "${pre}" ]]; then
752 cat "${pre}" >> "${target}"
753 else
754 die "-pre specified file '${pre}' does not exist"
755 fi
756 fi
610 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 757 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
611 cat "${var_tmp}" >> "${target}" 758 cat "${var_tmp}" >> "${target}"
612 rm -f "${var_tmp}" 759 rm -f "${var_tmp}"
613 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 760 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
614 761
706# Example: get a specific jar from xerces slot 2, and name it diffrently 853# Example: get a specific jar from xerces slot 2, and name it diffrently
707# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 854# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
708# Example: get junit.jar which is needed only for building 855# Example: get junit.jar which is needed only for building
709# java-pkg_jar-from --build-only junit junit.jar 856# java-pkg_jar-from --build-only junit junit.jar
710# 857#
711# @param $1 - (optional) "--build-only" makes the jar(s) not added into 858# @param $opt
712# package.env DEPEND line. 859# --build-only - makes the jar(s) not added into package.env DEPEND line.
713# @param $1 - Package to get jars from. 860# (assumed automatically when called inside src_test)
861# --with-dependencies - get jars also from requested package's dependencies
862# transitively.
863# --virtual - Packages passed to this function are to be handled as virtuals
864# and will not have individual jar dependencies recorded.
865# --into $dir - symlink jar(s) into $dir (must exist) instead of .
866# @param $1 - Package to get jars from, or comma-separated list of packages in
867# case other parameters are not used.
714# @param $2 - jar from package. If not specified, all jars will be used. 868# @param $2 - jar from package. If not specified, all jars will be used.
715# @param $3 - When a single jar is specified, destination filename of the 869# @param $3 - When a single jar is specified, destination filename of the
716# symlink. Defaults to the name of the jar. 870# symlink. Defaults to the name of the jar.
717# ------------------------------------------------------------------------------ 871# ------------------------------------------------------------------------------
718# TODO could probably be cleaned up a little 872# TODO could probably be cleaned up a little
719java-pkg_jar-from() { 873java-pkg_jar-from() {
720 debug-print-function ${FUNCNAME} $* 874 debug-print-function ${FUNCNAME} $*
721 875
722 local build_only="" 876 local build_only=""
877 local destdir="."
878 local deep=""
879 local virtual=""
723 880
881 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
882
883 while [[ "${1}" == --* ]]; do
724 if [[ "${1}" = "--build-only" ]]; then 884 if [[ "${1}" = "--build-only" ]]; then
725 build_only="true" 885 build_only="build"
886 elif [[ "${1}" = "--with-dependencies" ]]; then
887 deep="--with-dependencies"
888 elif [[ "${1}" = "--virtual" ]]; then
889 virtual="true"
890 elif [[ "${1}" = "--into" ]]; then
891 destdir="${2}"
892 shift
893 else
894 die "java-pkg_jar-from called with unknown parameter: ${1}"
895 fi
726 shift 896 shift
727 fi 897 done
728 898
729 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 899 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
730 900
731 [[ -z ${target_pkg} ]] && die "Must specify a package" 901 [[ -z ${target_pkg} ]] && die "Must specify a package"
902
903 if [[ "${EAPI}" == "1" ]]; then
904 target_pkg="${target_pkg//:/-}"
905 fi
732 906
733 # default destjar to the target jar 907 # default destjar to the target jar
734 [[ -z "${destjar}" ]] && destjar="${target_jar}" 908 [[ -z "${destjar}" ]] && destjar="${target_jar}"
735 909
736 local error_msg="There was a problem getting the classpath for ${target_pkg}." 910 local error_msg="There was a problem getting the classpath for ${target_pkg}."
737 local classpath 911 local classpath
738 classpath="$(java-config --classpath=${target_pkg})" 912 classpath="$(java-config ${deep} --classpath=${target_pkg})"
739 [[ $? != 0 ]] && die ${error_msg} 913 [[ $? != 0 ]] && die ${error_msg}
914
915 # When we have commas this functions is called to bring jars from multiple
916 # packages. This affects recording of dependencencies performed later
917 # which expects one package only, so we do it here.
918 if [[ ${target_pkg} = *,* ]]; then
919 for pkg in ${target_pkg//,/ }; do
920 java-pkg_ensure-dep "${build_only}" "${pkg}"
921 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
922 done
923 # setting this disables further record-jar_ calls later
924 build_only="build"
925 else
926 java-pkg_ensure-dep "${build_only}" "${target_pkg}"
927 fi
928
929 # Record the entire virtual as a dependency so that
930 # no jars are missed.
931 if [[ -z "${build_only}" && -n "${virtual}" ]]; then
932 java-pkg_record-jar_ "${target_pkg}"
933 # setting this disables further record-jars_ calls later
934 build_only="build"
935 fi
936
937 pushd ${destdir} > /dev/null \
938 || die "failed to change directory to ${destdir}"
740 939
741 local jar 940 local jar
742 for jar in ${classpath//:/ }; do 941 for jar in ${classpath//:/ }; do
743 local jar_name=$(basename "${jar}") 942 local jar_name=$(basename "${jar}")
744 if [[ ! -f "${jar}" ]] ; then 943 if [[ ! -f "${jar}" ]] ; then
755 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 954 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
756 [[ -f "${destjar}" ]] && rm "${destjar}" 955 [[ -f "${destjar}" ]] && rm "${destjar}"
757 ln -snf "${jar}" "${destjar}" \ 956 ln -snf "${jar}" "${destjar}" \
758 || die "Failed to make symlink from ${jar} to ${destjar}" 957 || die "Failed to make symlink from ${jar} to ${destjar}"
759 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}" 958 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
959 popd > /dev/null
760 return 0 960 return 0
761 fi 961 fi
762 done 962 done
963 popd > /dev/null
763 # if no target was specified, we're ok 964 # if no target was specified, we're ok
764 if [[ -z "${target_jar}" ]] ; then 965 if [[ -z "${target_jar}" ]] ; then
765 return 0 966 return 0
766 # otherwise, die bitterly 967 # otherwise, die bitterly
767 else 968 else
791# Example: Get the classpath for xerces-2 and xalan, 992# Example: Get the classpath for xerces-2 and xalan,
792# java-pkg_getjars xerces-2,xalan 993# java-pkg_getjars xerces-2,xalan
793# Example Return: 994# Example Return:
794# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 995# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
795# 996#
796# @param $1 - (optional) "--build-only" makes the jar(s) not added into 997# @param $opt
797# package.env DEPEND line. 998# --build-only - makes the jar(s) not added into package.env DEPEND line.
999# (assumed automatically when called inside src_test)
1000# --with-dependencies - get jars also from requested package's dependencies
1001# transitively.
798# @param $2 - list of packages to get jars from 1002# @param $1 - list of packages to get jars from
799# (passed to java-config --classpath) 1003# (passed to java-config --classpath)
800# ------------------------------------------------------------------------------ 1004# ------------------------------------------------------------------------------
801java-pkg_getjars() { 1005java-pkg_getjars() {
802 debug-print-function ${FUNCNAME} $* 1006 debug-print-function ${FUNCNAME} $*
803 1007
1008 local build_only=""
1009 local deep=""
1010
1011 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1012
1013 while [[ "${1}" == --* ]]; do
804 if [[ "${1}" = "--build-only" ]]; then 1014 if [[ "${1}" = "--build-only" ]]; then
805 local build_only="true" 1015 build_only="build"
1016 elif [[ "${1}" = "--with-dependencies" ]]; then
1017 deep="--with-dependencies"
1018 else
1019 die "java-pkg_jar-from called with unknown parameter: ${1}"
1020 fi
806 shift 1021 shift
807 fi 1022 done
808 1023
809 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --build-only" 1024 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
810 1025
1026
811 local classpath pkgs="${1}" 1027 local pkgs="${1}"
1028
1029 if [[ "${EAPI}" == "1" ]]; then
1030 pkgs="${pkgs//:/-}"
1031 fi
1032
812 jars="$(java-config --classpath=${pkgs})" 1033 jars="$(java-config ${deep} --classpath=${pkgs})"
813 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed" 1034 [[ $? != 0 ]] && die "java-config --classpath=${pkgs} failed"
814 debug-print "${pkgs}:${jars}" 1035 debug-print "${pkgs}:${jars}"
815 1036
816 if [[ -z "${classpath}" ]]; then 1037 for pkg in ${pkgs//,/ }; do
817 classpath="${jars}" 1038 java-pkg_ensure-dep "${build_only}" "${pkg}"
818 else 1039 done
819 classpath="${classpath}:${jars}"
820 fi
821 1040
822 # Only record jars that aren't build-only 1041 # Only record jars that aren't build-only
823 if [[ -z "${build_only}" ]]; then 1042 if [[ -z "${build_only}" ]]; then
824 oldifs="${IFS}"
825 IFS=","
826 for pkg in ${pkgs}; do 1043 for pkg in ${pkgs//,/ }; do
827 java-pkg_record-jar_ "${pkg}" 1044 java-pkg_record-jar_ "${pkg}"
828 done 1045 done
829 IFS="${oldifs}"
830 fi 1046 fi
831 1047
832 echo "${classpath}" 1048 echo "${jars}"
833} 1049}
834 1050
835# ------------------------------------------------------------------------------ 1051# ------------------------------------------------------------------------------
836# @ebuild-function java-pkg_getjar 1052# @ebuild-function java-pkg_getjar
837# 1053#
844# @example 1060# @example
845# java-pkg_getjar xerces-2 xml-apis.jar 1061# java-pkg_getjar xerces-2 xml-apis.jar
846# @example-return 1062# @example-return
847# /usr/share/xerces-2/lib/xml-apis.jar 1063# /usr/share/xerces-2/lib/xml-apis.jar
848# 1064#
849# @param $1 - (optional) "--build-only" makes the jar not added into 1065# @param $opt
850# package.env DEPEND line. 1066# --build-only - makes the jar not added into package.env DEPEND line.
1067# --virtual - Packages passed to this function are to be handled as virtuals
1068# and will not have individual jar dependencies recorded.
851# @param $1 - package to use 1069# @param $1 - package to use
852# @param $2 - jar to get 1070# @param $2 - jar to get
853# ------------------------------------------------------------------------------ 1071# ------------------------------------------------------------------------------
854java-pkg_getjar() { 1072java-pkg_getjar() {
855 debug-print-function ${FUNCNAME} $* 1073 debug-print-function ${FUNCNAME} $*
856 1074
857 local build_only="" 1075 local build_only=""
1076 local virtual=""
858 1077
1078 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1079
1080 while [[ "${1}" == --* ]]; do
859 if [[ "${1}" = "--build-only" ]]; then 1081 if [[ "${1}" = "--build-only" ]]; then
860 build_only="true" 1082 build_only="build"
1083 elif [[ "${1}" == "--virtual" ]]; then
1084 virtual="true"
1085 else
1086 die "java-pkg_getjar called with unknown parameter: ${1}"
1087 fi
861 shift 1088 shift
862 fi 1089 done
1090
1091 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
863 1092
864 local pkg="${1}" target_jar="${2}" jar 1093 local pkg="${1}" target_jar="${2}" jar
1094
1095 if [[ "${EAPI}" == "1" ]]; then
1096 pkg="${pkg//:/-}"
1097 fi
1098
865 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 1099 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
866 [[ -z ${target_jar} ]] && die "Must specify jar to get" 1100 [[ -z ${target_jar} ]] && die "Must specify jar to get"
867 1101
868 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?" 1102 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
869 local classpath 1103 local classpath
870 classpath=$(java-config --classpath=${pkg}) 1104 classpath=$(java-config --classpath=${pkg})
871 [[ $? != 0 ]] && die ${error_msg} 1105 [[ $? != 0 ]] && die ${error_msg}
1106
1107 java-pkg_ensure-dep "${build_only}" "${pkg}"
1108
1109 # Record the package(Virtual) as a dependency and then set build_only
1110 # So that individual jars are not recorded.
1111 if [[ -n "${virtual}" ]]; then
1112 java-pkg_record-jar_ "${pkg}"
1113 build_only="true"
1114 fi
872 1115
873 for jar in ${classpath//:/ }; do 1116 for jar in ${classpath//:/ }; do
874 if [[ ! -f "${jar}" ]] ; then 1117 if [[ ! -f "${jar}" ]] ; then
875 die "Installation problem with jar ${jar} in ${pkg} - is it installed?" 1118 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
876 fi 1119 fi
883 fi 1126 fi
884 done 1127 done
885 1128
886 die "Could not find ${target_jar} in ${pkg}" 1129 die "Could not find ${target_jar} in ${pkg}"
887 return 1 1130 return 1
1131}
1132
1133# ------------------------------------------------------------------------------
1134# @ebuild-function java-pkg_register-dependency
1135#
1136# Registers runtime dependency on a package, list of packages, or a single jar
1137# from a package, into package.env DEPEND line. Can only be called in
1138# src_install phase.
1139# Intended for binary packages where you don't need to symlink the jars or get
1140# their classpath during build. As such, the dependencies only need to be
1141# specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1142#
1143# @param $1 - comma-separated list of packages, or a single package
1144# @param $2 - if param $1 is a single package, optionally specify the jar
1145# to depend on
1146#
1147# Example: Record the dependency on whole xerces-2 and xalan,
1148# java-pkg_register-dependency xerces-2,xalan
1149# Example: Record the dependency on ant.jar from ant-core
1150# java-pkg_register-dependency ant-core ant.jar
1151#
1152# Note: Passing both list of packages as the first parameter AND specifying the
1153# jar as the second is not allowed and will cause the function to die. We assume
1154# that there's more chance one passes such combination as a mistake, than that
1155# there are more packages providing identically named jar without class
1156# collisions.
1157# ------------------------------------------------------------------------------
1158java-pkg_register-dependency() {
1159 debug-print-function ${FUNCNAME} $*
1160
1161 java-pkg_check-phase install
1162
1163 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1164
1165 local pkgs="${1}"
1166 local jar="${2}"
1167
1168 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1169
1170 if [[ "${EAPI}" == "1" ]]; then
1171 pkgs="${pkgs//:/-}"
1172 fi
1173
1174 if [[ -z "${jar}" ]]; then
1175 for pkg in ${pkgs//,/ }; do
1176 java-pkg_ensure-dep runtime "${pkg}"
1177 java-pkg_record-jar_ "${pkg}"
1178 done
1179 else
1180 [[ ${pkgs} == *,* ]] && \
1181 die "${FUNCNAME} called with both package list and jar name"
1182 java-pkg_ensure-dep runtime "${pkgs}"
1183 java-pkg_record-jar_ "${pkgs}" "${jar}"
1184 fi
1185
1186 java-pkg_do_write_
1187}
1188
1189# ------------------------------------------------------------------------------
1190# @ebuild-function java-pkg_register-optional-dependency
1191#
1192# Registers optional runtime dependency on a package, list of packages, or a
1193# single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be
1194# called in src_install phase.
1195# Intended for packages that can use other packages when those are in classpath.
1196# Will be put on classpath by launcher if they are installed. Typical case is
1197# JDBC implementations for various databases. It's better than having USE flag
1198# for each implementation triggering hard dependency.
1199#
1200# @param $1 - comma-separated list of packages, or a single package
1201# @param $2 - if param $1 is a single package, optionally specify the jar
1202# to depend on
1203#
1204# Example: Record the optional dependency on some jdbc providers
1205# java-pkg_register-optional-dependency jdbc-jaybird,jtds-1.2,jdbc-mysql
1206#
1207# Note: Passing both list of packages as the first parameter AND specifying the
1208# jar as the second is not allowed and will cause the function to die. We assume
1209# that there's more chance one passes such combination as a mistake, than that
1210# there are more packages providing identically named jar without class
1211# collisions.
1212# ------------------------------------------------------------------------------
1213java-pkg_register-optional-dependency() {
1214 debug-print-function ${FUNCNAME} $*
1215
1216 java-pkg_check-phase install
1217
1218 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1219
1220 local pkgs="${1}"
1221 local jar="${2}"
1222
1223 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1224
1225 if [[ "${EAPI}" == "1" ]]; then
1226 pkgs="${pkgs//:/-}"
1227 fi
1228
1229 if [[ -z "${jar}" ]]; then
1230 for pkg in ${pkgs//,/ }; do
1231 java-pkg_record-jar_ --optional "${pkg}"
1232 done
1233 else
1234 [[ ${pkgs} == *,* ]] && \
1235 die "${FUNCNAME} called with both package list and jar name"
1236 java-pkg_record-jar_ --optional "${pkgs}" "${jar}"
1237 fi
1238
1239 java-pkg_do_write_
1240}
1241
1242# ------------------------------------------------------------------------------
1243# @ebuild-function java-pkg_register-environment-variable
1244#
1245# Register an arbitrary environment variable into package.env. The gjl launcher
1246# for this package or any package depending on this will export it into
1247# environement before executing java command.
1248# Must only be called in src_install phase.
1249#
1250# @param $1 - variable name
1251# @param $2 - variable value
1252# ------------------------------------------------------------------------------
1253JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
1254JAVA_PKG_EXTRA_ENV_VARS=""
1255java-pkg_register-environment-variable() {
1256 debug-print-function ${FUNCNAME} $*
1257
1258 java-pkg_check-phase install
1259
1260 [[ ${#} != 2 ]] && die "${FUNCNAME} takes two arguments"
1261
1262 echo "${1}=\"${2}\"" >> ${JAVA_PKG_EXTRA_ENV}
1263 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
1264
1265 java-pkg_do_write_
888} 1266}
889 1267
890# This function reads stdin, and based on that input, figures out how to 1268# This function reads stdin, and based on that input, figures out how to
891# populate jars from the filesystem. 1269# populate jars from the filesystem.
892# Need to figure out a good way of making use of this, ie be able to use a 1270# Need to figure out a good way of making use of this, ie be able to use a
1009# 1387#
1010# export DEPEND="${DEPEND} ${depstr}" 1388# export DEPEND="${DEPEND} ${depstr}"
1011# export RDEPEND="${RDEPEND} ${depstr}" 1389# export RDEPEND="${RDEPEND} ${depstr}"
1012#} 1390#}
1013 1391
1392# ------------------------------------------------------------------------------
1393# @ebuild-function java-pkg_find-normal-jars
1394#
1395# Find the files with suffix .jar file in the given directory or $WORKDIR
1396#
1397# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1398# ------------------------------------------------------------------------------
1399java-pkg_find-normal-jars() {
1400 local dir=$1
1401 [[ "${dir}" ]] || dir="${WORKDIR}"
1402 local found
1403 for jar in $(find "${dir}" -name "*.jar" -type f); do
1404 echo "${jar}"
1405 found="true"
1406 done
1407 [[ "${found}" ]]
1408 return $?
1409}
1410
1411# ------------------------------------------------------------------------------
1412# @ebuild-function java-pkg_ensure-no-bundled-jars
1413#
1414# Try to locate bundled jar files in ${WORKDIR} and die if found.
1014# This should be used after S has been populated with symlinks to jars 1415# This function should be called after WORKDIR has been populated with symlink
1015# TODO document 1416# to system jar files or bundled jars removed.
1417# ------------------------------------------------------------------------------
1016java-pkg_ensure-no-bundled-jars() { 1418java-pkg_ensure-no-bundled-jars() {
1017 debug-print-function ${FUNCNAME} $* 1419 debug-print-function ${FUNCNAME} $*
1018 pushd ${WORKDIR} >/dev/null 2>/dev/null
1019 1420
1020 local bundled_jars=$(find . -name "*.jar" -type f) 1421 local bundled_jars=$(java-pkg_find-normal-jars)
1021 if [[ -n ${bundled_jars} ]]; then 1422 if [[ -n ${bundled_jars} ]]; then
1022 echo "Bundled jars found:" 1423 echo "Bundled jars found:"
1023 local jar 1424 local jar
1024 for jar in ${bundled_jars}; do 1425 for jar in ${bundled_jars}; do
1025 echo $(pwd)${jar/./} 1426 echo $(pwd)${jar/./}
1026 done 1427 done
1027 die "Bundled jars found!" 1428 die "Bundled jars found!"
1028
1029 fi 1429 fi
1030 popd >/dev/null 2>/dev/null
1031} 1430}
1032 1431
1033# ------------------------------------------------------------------------------ 1432# ------------------------------------------------------------------------------
1034# @internal-function java-pkg_ensure-vm-version-sufficient 1433# @internal-function java-pkg_ensure-vm-version-sufficient
1035# 1434#
1297 die "Need USE=test enabled" 1696 die "Need USE=test enabled"
1298 fi 1697 fi
1299} 1698}
1300 1699
1301# ------------------------------------------------------------------------------ 1700# ------------------------------------------------------------------------------
1701# @ebuild-function java-pkg_register-ant-task
1702#
1703# Register this package as ant task, so that ant will load it when no specific
1704# ANT_TASKS are specified. Note that even without this registering, all packages
1705# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1706# packages, but can be also used by other ebuilds that used to symlink their
1707# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1708# compatibility.
1709#
1710# @param --version x.y Register only for ant version x.y (otherwise for any ant
1711# version). Used by the ant-* packages to prevent loading of mismatched
1712# ant-core ant tasks after core was updated, before the tasks are updated,
1713# without a need for blockers.
1714# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1715# ------------------------------------------------------------------------------
1716java-pkg_register-ant-task() {
1717 local TASKS_DIR="tasks"
1718
1719 # check for --version x.y parameters
1720 while [[ -n "${1}" && -n "${2}" ]]; do
1721 local var="${1#--}"
1722 local val="${2}"
1723 if [[ "${var}" == "version" ]]; then
1724 TASKS_DIR="tasks-${val}"
1725 else
1726 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1727 fi
1728 shift 2
1729 done
1730
1731 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1732
1733 dodir /usr/share/ant/${TASKS_DIR}
1734 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1735}
1736
1737# ------------------------------------------------------------------------------
1738# @internal-function java-pkg_ant-tasks-depend
1739#
1740# Translates the WANT_ANT_TASKS variable into valid dependencies.
1741# ------------------------------------------------------------------------------
1742java-pkg_ant-tasks-depend() {
1743 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1744
1745 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1746 local DEP=""
1747 for i in ${WANT_ANT_TASKS}
1748 do
1749 if [[ ${i} = ant-* ]]; then
1750 DEP="${DEP}dev-java/${i} "
1751 elif [[ ${i} = */*:* ]]; then
1752 DEP="${DEP}${i} "
1753 else
1754 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1755 return 1
1756 fi
1757 done
1758 echo ${DEP}
1759 return 0
1760 else
1761 return 0
1762 fi
1763}
1764
1765# ------------------------------------------------------------------------------
1766# @ebuild-function ejunit
1767#
1768# Junit wrapper function. Makes it easier to run the tests and checks for
1769# dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner.
1770#
1771# Examples:
1772# ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1773# ejunit org.blinkenlights.jid3.test.AllTests
1774#
1775# @param $1 - -cp or -classpath
1776# @param $2 - classpath; junit and recorded dependencies get appended
1777# @param $@ - the rest of the parameters are passed to java
1778# ------------------------------------------------------------------------------
1779ejunit() {
1780 debug-print-function ${FUNCNAME} $*
1781
1782 local pkgs
1783 if [[ -f ${JAVA_PKG_DEPEND_FILE} ]]; then
1784 for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
1785 pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
1786 done
1787 fi
1788
1789 local cp=$(java-pkg_getjars --with-dependencies junit${pkgs})
1790 if [[ ${1} = -cp || ${1} = -classpath ]]; then
1791 cp="${2}:${cp}"
1792 shift 2
1793 else
1794 cp=".:${cp}"
1795 fi
1796
1797 local runner=junit.textui.TestRunner
1798 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}"
1799 java -cp "${cp}" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
1800}
1801
1802# ------------------------------------------------------------------------------
1302# @section-end helper 1803# @section-end helper
1303# ------------------------------------------------------------------------------ 1804# ------------------------------------------------------------------------------
1805
1806# ------------------------------------------------------------------------------
1807# @eclass-src_prepare
1808#
1809# src_prepare Searches for bundled jars
1810# Don't call directly, but via java-pkg-2_src_prepare!
1811# ------------------------------------------------------------------------------
1812
1813java-utils-2_src_prepare() {
1814 [[ ${EBUILD_PHASE} == prepare ]] &&
1815 java-pkg_func-exists java_prepare && java_prepare
1816
1817 # Remember that eant will call this unless called via Portage
1818 if [[ ! -e "${T}/java-utils-2_src_prepare-run" ]] && is-java-strict; then
1819 echo "Searching for bundled jars:"
1820 java-pkg_find-normal-jars || echo "None found."
1821 echo "Searching for bundled classes (no output if none found):"
1822 find "${WORKDIR}" -name "*.class"
1823 echo "Search done."
1824 fi
1825 touch "${T}/java-utils-2_src_prepare-run"
1826}
1827
1828# ------------------------------------------------------------------------------
1829# @eclass-pkg_preinst
1830#
1831# pkg_preinst Searches for missing and unneeded dependencies
1832# Don't call directly, but via java-pkg-2_pkg_preinst!
1833# ------------------------------------------------------------------------------
1834
1835java-utils-2_pkg_preinst() {
1836 if is-java-strict; then
1837 if has_version dev-java/java-dep-check; then
1838 [[ -e "${JAVA_PKG_ENV}" ]] || return
1839 local output=$(GENTOO_VM= java-dep-check --image "${D}" "${JAVA_PKG_ENV}")
1840 if [[ ${output} && has_version <=dev-java/java-dep-check-0.2 ]]; then
1841 ewarn "Possibly unneeded dependencies found in package.env:"
1842 for dep in ${output}; do
1843 ewarn "\t${dep}"
1844 done
1845 fi
1846 if [[ ${output} && has_version >dev-java/java-dep-check-0.2 ]]; then
1847 ewarn "${output}"
1848 fi
1849 else
1850 eerror "Install dev-java/java-dep-check for dependency checking"
1851 fi
1852 fi
1853}
1304 1854
1305# ------------------------------------------------------------------------------ 1855# ------------------------------------------------------------------------------
1306# @section-begin build 1856# @section-begin build
1307# @section-summary Build functions 1857# @section-summary Build functions
1308# 1858#
1312 1862
1313# ------------------------------------------------------------------------------ 1863# ------------------------------------------------------------------------------
1314# @ebuild-function eant 1864# @ebuild-function eant
1315# 1865#
1316# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1866# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1317# compiler. 1867# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1318# 1868# variables:
1869# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1870# gentoo.classpath property. Be sure to call
1871# java-ant_rewrite-classpath in src_unpack.
1872# EANT_NEEDS_TOOLS - add tools.jar to the gentoo.classpath. Should only be used
1873# for build-time purposes, the dependency is not recorded to
1874# package.env!
1875# JAVA_PKG_NO_BUNDLED_SEARCH - Don't search for bundled jars or class files
1876# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1319# ------------------------------------------------------------------------------ 1877# ------------------------------------------------------------------------------
1320eant() { 1878eant() {
1321 debug-print-function ${FUNCNAME} $* 1879 debug-print-function ${FUNCNAME} $*
1322 1880
1323 # FIXME get this working 1881 if [[ ${EBUILD_PHASE} = compile ]]; then
1324# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then 1882 java-ant-2_src_configure
1883 java-utils-2_src_prepare
1884 fi
1885
1886 if ! hasq java-ant-2 ${INHERITED}; then
1887 local msg="You should inherit java-ant-2 when using eant"
1325# java-pkg_announce-qa-violation \ 1888 java-pkg_announce-qa-violation "${msg}"
1326# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1327# fi 1889 fi
1328 1890
1329 local antflags="-Dnoget=true" 1891 local antflags="-Dnoget=true -Dmaven.mode.offline=true -Dbuild.sysclasspath=ignore"
1892
1330 java-pkg_init-compiler_ 1893 java-pkg_init-compiler_
1331 local compiler="${GENTOO_COMPILER}" 1894 local compiler="${GENTOO_COMPILER}"
1332 1895
1333 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1896 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1334
1335 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})" 1897 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})"
1336 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1898 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1337 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1899 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1338 fi 1900 fi
1339 1901
1347 if [[ -n ${build_compiler_deps} ]]; then 1909 if [[ -n ${build_compiler_deps} ]]; then
1348 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})" 1910 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1349 fi 1911 fi
1350 fi 1912 fi
1351 1913
1914 for arg in "${@}"; do
1915 if [[ ${arg} = -lib ]]; then
1352 if is-java-strict; then 1916 if is-java-strict; then
1353 einfo "Disabling system classpath for ant" 1917 eerror "You should not use the -lib argument to eant because it will fail"
1354 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1918 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1919 eerror "or ant properties to make dependencies available."
1920 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1921 eerror "split ant (>=dev-java/ant-core-1.7)."
1922 die "eant -lib is deprecated/forbidden"
1923 else
1924 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1925 echo "more info."
1926 fi
1355 fi 1927 fi
1928 done
1356 1929
1357 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1930 # parse WANT_ANT_TASKS for atoms
1358 antflags="${antflags} -debug" 1931 local want_ant_tasks
1932 for i in ${WANT_ANT_TASKS}; do
1933 if [[ ${i} = */*:* ]]; then
1934 i=${i#*/}
1935 i=${i%:0}
1936 want_ant_tasks+="${i/:/-} "
1937 else
1938 want_ant_tasks+="${i} "
1939 fi
1940 done
1941 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1942 ANT_TASKS="${ANT_TASKS:-${want_ant_tasks% }}"
1943
1944 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1945 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1946
1947 # if ant-tasks is not set by ebuild or forced, use none
1948 ANT_TASKS="${ANT_TASKS:-none}"
1949
1950 # at this point, ANT_TASKS should be "all", "none" or explicit list
1951 if [[ "${ANT_TASKS}" == "all" ]]; then
1952 einfo "Using all available ANT_TASKS"
1953 elif [[ "${ANT_TASKS}" == "none" ]]; then
1954 einfo "Disabling all optional ANT_TASKS"
1955 else
1956 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1957 fi
1958
1959 export ANT_TASKS
1960
1961 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1962 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1963
1964 local gcp="${EANT_GENTOO_CLASSPATH}"
1965 local getjarsarg=""
1966
1967 if [[ ${EBUILD_PHASE} = "test" ]]; then
1968 antflags="${antflags} -DJunit.present=true"
1969 [[ ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1970 getjarsarg="--with-dependencies"
1971 fi
1972
1973 local cp
1974
1975 for atom in ${gcp}; do
1976 cp="${cp}:$(java-pkg_getjars ${getjarsarg} ${atom})"
1977 done
1978
1979 [[ -n "${EANT_NEEDS_TOOLS}" ]] && cp="${cp}:$(java-config --tools)"
1980
1981 if [[ ${cp} ]]; then
1982 # It seems ant does not like single quotes around ${cp}
1983 cp=${cp#:}
1984 [[ ${EANT_GENTOO_CLASSPATH_EXTRA} ]] && \
1985 cp="${cp}:${EANT_GENTOO_CLASSPATH_EXTRA}"
1986 antflags="${antflags} -Dgentoo.classpath=\"${cp}\""
1359 fi 1987 fi
1360 1988
1361 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1989 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1990 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
1362 ant ${antflags} "${@}" || die "eant failed" 1991 ant ${antflags} "${@}" || die "eant failed"
1363
1364} 1992}
1365 1993
1366# ------------------------------------------------------------------------------ 1994# ------------------------------------------------------------------------------
1367# @ebuild-function ejavac 1995# @ebuild-function ejavac
1368# 1996#
1463# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will 2091# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will
1464# call it during each of the phases of the merge process. 2092# call it during each of the phases of the merge process.
1465# 2093#
1466# ----------------------------------------------------------------------------- 2094# -----------------------------------------------------------------------------
1467java-pkg_init() { 2095java-pkg_init() {
2096 debug-print-function ${FUNCNAME} $*
1468 unset JAVAC 2097 unset JAVAC
1469 unset JAVA_HOME 2098 unset JAVA_HOME
2099
2100 java-config --help >/dev/null || {
2101 eerror ""
2102 eerror "Can't run java-config --help"
2103 eerror "Have you upgraded python recently but haven't"
2104 eerror "run python-updater yet?"
2105 die "Can't run java-config --help"
2106 }
2107
2108 # People do all kinds of weird things.
2109 # http://forums.gentoo.org/viewtopic-p-3943166.html
2110 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
2111 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
2112 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
2113 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
2114 ewarn "sun-jdk vms and and as such break configure scripts that"
2115 ewarn "use it (for example app-office/openoffice) so we filter it out."
2116 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
2117 ewarn "make.conf for example) to silence this warning or"
2118 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
2119 fi
2120
2121 if [[ -z ${accept} ]]; then
2122 # export _JAVA_OPTIONS= doesn't work because it will show up in java
2123 # -version output
2124 unset _JAVA_OPTIONS
2125 # phase hooks make this run many times without this
2126 I_WANT_GLOBAL_JAVA_OPTIONS="true"
2127 fi
2128
2129 if java-pkg_func-exists ant_src_unpack; then
2130 java-pkg_announce-qa-violation "Using old ant_src_unpack. Should be src_unpack"
2131 fi
2132
1470 java-pkg_init_paths_ 2133 java-pkg_init_paths_
1471 java-pkg_switch-vm 2134 java-pkg_switch-vm
1472 PATH=${JAVA_HOME}/bin:${PATH} 2135 PATH=${JAVA_HOME}/bin:${PATH}
1473 2136
1474 # TODO we will probably want to set JAVAC and JAVACFLAGS 2137 # TODO we will probably want to set JAVAC and JAVACFLAGS
1475 2138
1476 # Do some QA checks 2139 # Do some QA checks
1477 java-pkg_check-jikes 2140 java-pkg_check-jikes
2141
2142 # Can't use unset here because Portage does not save the unset
2143 # see https://bugs.gentoo.org/show_bug.cgi?id=189417#c11
1478 2144
1479 # When users have crazy classpaths some packages can fail to compile. 2145 # When users have crazy classpaths some packages can fail to compile.
1480 # and everything should work with empty CLASSPATH. 2146 # and everything should work with empty CLASSPATH.
1481 # This also helps prevent unexpected dependencies on random things 2147 # This also helps prevent unexpected dependencies on random things
1482 # from the CLASSPATH. 2148 # from the CLASSPATH.
1483 unset CLASSPATH 2149 export CLASSPATH=
2150
2151 # Unset external ANT_ stuff
2152 export ANT_TASKS=
2153 export ANT_OPTS=
2154 export ANT_RESPECT_JAVA_HOME=
1484} 2155}
1485 2156
1486# ------------------------------------------------------------------------------ 2157# ------------------------------------------------------------------------------
1487# @function-internal java-pkg-init-compiler_ 2158# @function-internal java-pkg-init-compiler_
1488# 2159#
1579 done 2250 done
1580 2251
1581 # If it hasn't been defined already, default to javac 2252 # If it hasn't been defined already, default to javac
1582 if [[ -z ${GENTOO_COMPILER} ]]; then 2253 if [[ -z ${GENTOO_COMPILER} ]]; then
1583 if [[ -n ${compilers} ]]; then 2254 if [[ -n ${compilers} ]]; then
1584 einfo "No suitable compiler found: defaulting javac for compilation" 2255 einfo "No suitable compiler found: defaulting to JDK default for compilation"
1585 else 2256 else
1586 # probably don't need to notify users about the default. 2257 # probably don't need to notify users about the default.
1587 :;#einfo "Defaulting to javac for compilation" 2258 :;#einfo "Defaulting to javac for compilation"
1588 fi 2259 fi
2260 if java-config -g GENTOO_COMPILER 2> /dev/null; then
2261 export GENTOO_COMPILER=$(java-config -g GENTOO_COMPILER)
2262 else
1589 export GENTOO_COMPILER=javac 2263 export GENTOO_COMPILER=javac
2264 fi
1590 else 2265 else
1591 einfo "Using ${GENTOO_COMPILER} for compilation" 2266 einfo "Using ${GENTOO_COMPILER} for compilation"
1592 fi 2267 fi
1593 2268
1594} 2269}
1610 fi 2285 fi
1611 2286
1612 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}" 2287 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}"
1613 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/" 2288 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/"
1614 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env" 2289 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env"
2290 JAVA_PKG_VIRTUALS_PATH="${DESTTREE}/share/java-config-2/virtuals"
2291 JAVA_PKG_VIRTUAL_PROVIDER="${D}/${JAVA_PKG_VIRTUALS_PATH}/${JAVA_PKG_NAME}"
1615 2292
1616 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib" 2293 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib"
1617 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}" 2294 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}"
1618 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps" 2295 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps"
1619 2296
1632# Writes the package.env out to disk. 2309# Writes the package.env out to disk.
1633# 2310#
1634# ------------------------------------------------------------------------------ 2311# ------------------------------------------------------------------------------
1635# TODO change to do-write, to match everything else 2312# TODO change to do-write, to match everything else
1636java-pkg_do_write_() { 2313java-pkg_do_write_() {
2314 debug-print-function ${FUNCNAME} $*
1637 java-pkg_init_paths_ 2315 java-pkg_init_paths_
1638 # Create directory for package.env 2316 # Create directory for package.env
1639 dodir "${JAVA_PKG_SHAREPATH}" 2317 dodir "${JAVA_PKG_SHAREPATH}"
1640 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 2318 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f \
2319 "${JAVA_PKG_DEPEND_FILE}" || -f \
2320 "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]]; then
1641 # Create package.env 2321 # Create package.env
1642 ( 2322 (
1643 echo "DESCRIPTION=\"${DESCRIPTION}\"" 2323 echo "DESCRIPTION=\"${DESCRIPTION}\""
1644 echo "GENERATION=\"2\"" 2324 echo "GENERATION=\"2\""
2325 echo "SLOT=\"${SLOT}\""
1645 2326
1646 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\"" 2327 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
1647 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 2328 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1648 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 2329 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1649 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 2330 [[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
2331 && echo "DEPEND=\"$(cat "${JAVA_PKG_DEPEND_FILE}" | uniq | tr '\n' ':')\""
2332 [[ -f "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]] \
2333 && echo "OPTIONAL_DEPEND=\"$(cat "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" | uniq | tr '\n' ':')\""
1650 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 2334 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1651 ) > "${JAVA_PKG_ENV}" 2335 ) > "${JAVA_PKG_ENV}"
1652 2336
1653 # register target/source 2337 # register target/source
1654 local target="$(java-pkg_get-target)" 2338 local target="$(java-pkg_get-target)"
1665 2349
1666 2350
1667 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}" 2351 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
1668 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}" 2352 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
1669 2353
2354 # extra env variables
2355 if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
2356 cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}" || die
2357 # nested echo to remove leading/trailing spaces
2358 echo "ENV_VARS=\"$(echo ${JAVA_PKG_EXTRA_ENV_VARS})\"" \
2359 >> "${JAVA_PKG_ENV}" || die
2360 fi
2361
1670 # Strip unnecessary leading and trailing colons 2362 # Strip unnecessary leading and trailing colons
1671 # TODO try to cleanup if possible 2363 # TODO try to cleanup if possible
1672 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 2364 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
2365 else
2366 debug-print "JAVA_PKG_CLASSPATH, JAVA_PKG_LIBRARY, JAVA_PKG_DEPEND_FILE"
2367 debug-print "or JAVA_PKG_OPTIONAL_DEPEND_FILE not defined so can't"
2368 debug-print "write package.env."
1673 fi 2369 fi
1674} 2370}
1675 2371
1676# ------------------------------------------------------------------------------ 2372# ------------------------------------------------------------------------------
1677# @internal-function java-pkg_record-jar_ 2373# @internal-function java-pkg_record-jar_
1678# 2374#
1679# Record a dependency to the package.env 2375# Record an (optional) dependency to the package.env
1680# 2376# @param --optional - record dependency as optional
2377# @param $1 - package to record
2378# @param $2 - (optional) jar of package to record
1681# ------------------------------------------------------------------------------ 2379# ------------------------------------------------------------------------------
1682JAVA_PKG_DEPEND="${T}/java-pkg-depend" 2380JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2381JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
1683 2382
1684java-pkg_record-jar_() { 2383java-pkg_record-jar_() {
1685 debug-print-function ${FUNCNAME} $* 2384 debug-print-function ${FUNCNAME} $*
2385
2386 local depend_file="${JAVA_PKG_DEPEND_FILE}"
2387 if [[ "${1}" == "--optional" ]]; then
2388 depend_file="${JAVA_PKG_OPTIONAL_DEPEND_FILE}"
2389 shift
2390 fi
1686 2391
1687 local pkg=${1} jar=${2} append 2392 local pkg=${1} jar=${2} append
1688 if [[ -z "${jar}" ]]; then 2393 if [[ -z "${jar}" ]]; then
1689 append="${pkg}" 2394 append="${pkg}"
1690 else 2395 else
1691 append="$(basename ${jar})@${pkg}" 2396 append="$(basename ${jar})@${pkg}"
1692 fi 2397 fi
1693 2398
1694 echo ${append} >> ${JAVA_PKG_DEPEND} 2399 echo "${append}" >> "${depend_file}"
1695} 2400}
1696 2401
1697# ------------------------------------------------------------------------------ 2402# ------------------------------------------------------------------------------
1698# @internal-function java-pkg_append_ 2403# @internal-function java-pkg_append_
1699# 2404#
1743# 2448#
1744# @return 0 - function is declared 2449# @return 0 - function is declared
1745# @return 1 - function is undeclared 2450# @return 1 - function is undeclared
1746# ------------------------------------------------------------------------------ 2451# ------------------------------------------------------------------------------
1747java-pkg_func-exists() { 2452java-pkg_func-exists() {
1748 if [[ -n "$(declare -f ${1})" ]]; then 2453 declare -F ${1} > /dev/null
1749 return 0
1750 else
1751 return 1
1752 fi
1753} 2454}
1754 2455
1755# ------------------------------------------------------------------------------ 2456# ------------------------------------------------------------------------------
1756# @internal-function java-pkg_setup-vm 2457# @internal-function java-pkg_setup-vm
1757# 2458#
1758# Sets up the environment for a specific VM 2459# Sets up the environment for a specific VM
1759# 2460#
1760# ------------------------------------------------------------------------------ 2461# ------------------------------------------------------------------------------
1761java-pkg_setup-vm() { 2462java-pkg_setup-vm() {
1762 debug-print-function ${FUNCNAME} $* 2463 debug-print-function ${FUNCNAME} $*
2464
2465 export LANG="C" LC_ALL="C"
1763 2466
1764 local vendor="$(java-pkg_get-vm-vendor)" 2467 local vendor="$(java-pkg_get-vm-vendor)"
1765 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then 2468 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1766 addpredict "/dev/random" 2469 addpredict "/dev/random"
1767 elif [[ "${vendor}" == "ibm" ]]; then 2470 elif [[ "${vendor}" == "ibm" ]]; then
1768 addpredict "/proc/self/maps" 2471 addpredict "/proc/self/maps"
1769 addpredict "/proc/cpuinfo" 2472 addpredict "/proc/cpuinfo"
1770 export LANG="C" LC_ALL="C"
1771 elif [[ "${vendor}" == "jrockit" ]]; then 2473 elif [[ "${vendor}" == "jrockit" ]]; then
1772 addpredict "/proc/cpuinfo" 2474 addpredict "/proc/cpuinfo"
1773 fi 2475 fi
1774} 2476}
1775 2477
1879 2581
1880 #TODO If you know a better solution let us know. 2582 #TODO If you know a better solution let us know.
1881 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 2583 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1882 2584
1883 local tann="${T}/announced-vm" 2585 local tann="${T}/announced-vm"
2586 # With the hooks we should only get here once from pkg_setup but better safe than sorry
2587 # if people have for example modified eclasses some where
1884 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 2588 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1885 # Add a check for setup/preinst phase... to avoid duplicate outputs
1886 # for when FEATURES=buildpkg
1887 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1888 then
1889 einfo "Using: $(java-config -f)" 2589 einfo "Using: $(java-config -f)"
1890 [[ ! -f "${tann}" ]] && touch "${tann}" 2590 [[ ! -f "${tann}" ]] && touch "${tann}"
1891 fi
1892 fi 2591 fi
1893 2592
1894 else 2593 else
1895 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!" 2594 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!"
1896 fi 2595 fi
1926 einfo "Classes" 2625 einfo "Classes"
1927 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR}," 2626 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1928 fi 2627 fi
1929} 2628}
1930 2629
1931# TODO document 2630# ------------------------------------------------------------------------------
2631# @internal-function java-pkg_verify-classes
2632#
1932# Verify that the classes were compiled for the right source / target 2633# Verify that the classes were compiled for the right source / target. Dies if
2634# not.
2635# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2636# ------------------------------------------------------------------------------
1933java-pkg_verify-classes() { 2637java-pkg_verify-classes() {
1934 ebegin "Verifying java class versions"
1935 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 2638 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1936 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 2639
2640 local version_verify="/usr/bin/class-version-verify.py"
2641
2642 if [[ ! -x "${version_verify}" ]]; then
2643 version_verify="/usr/$(get_libdir)/javatoolkit/bin/class-version-verify.py"
2644 fi
2645
2646 if [[ ! -x "${version_verify}" ]]; then
2647 ewarn "Unable to perform class version checks as"
2648 ewarn "class-version-verify.py is unavailable"
2649 ewarn "Please install dev-java/javatoolkit."
2650 return
2651 fi
2652
2653 local target=$(java-pkg_get-target)
2654 local result
2655 local log="${T}/class-version-verify.log"
2656 if [[ -n "${1}" ]]; then
2657 ${version_verify} -v -t ${target} "${1}" > "${log}"
1937 result=$? 2658 result=$?
1938 eend ${result}
1939 if [[ ${result} == 0 ]]; then
1940 einfo "All good"
1941 else 2659 else
1942 ewarn "Possible problem" 2660 ebegin "Verifying java class versions (target: ${target})"
1943 die "Bad class files found" 2661 ${version_verify} -v -t ${target} -r "${D}" > "${log}"
2662 result=$?
2663 eend ${result}
2664 fi
2665 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2666 if [[ ${result} != 0 ]]; then
2667 eerror "Incorrect bytecode version found"
2668 [[ -n "${1}" ]] && eerror "in file: ${1}"
2669 eerror "See ${log} for more details."
2670 die "Incorrect bytecode found"
2671 fi
2672}
2673
2674# ----------------------------------------------------------------------------
2675# @internal-function java-pkg_ensure-dep
2676# Check that a package being used in jarfrom, getjars and getjar is contained
2677# within DEPEND or RDEPEND.
2678# @param $1 - empty - check both vars; "runtime" or "build" - check only
2679# RDEPEND, resp. DEPEND
2680# @param $2 - Package name and slot.
2681
2682java-pkg_ensure-dep() {
2683 debug-print-function ${FUNCNAME} $*
2684
2685 local limit_to="${1}"
2686 local target_pkg="${2}"
2687 local dev_error=""
2688
2689 local stripped_pkg=$(echo "${target_pkg}" | sed \
2690 's/-[0-9]*\(\.[0-9]\)*$//')
2691
2692 debug-print "Matching against: ${stripped_pkg}"
2693
2694 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2695 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2696 dev_error="${dev_error} declared in DEPEND."
2697 if is-java-strict; then
2698 eerror "${dev_error}"
2699 die "${dev_error}"
2700 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2701 eerror "${dev_error}"
2702 elog "Because you have this package installed the package will"
2703 elog "build without problems, but please report this to"
2704 elog "http://bugs.gentoo.org"
2705 fi
2706 fi
2707
2708 if [[ ${limit_to} != build ]]; then
2709 if [[ ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2710 if [[ ! ( ${PDEPEND} =~ "${stripped_pkg}" ) ]]; then
2711 dev_error="The ebuild is attempting to use ${target_pkg},"
2712 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND"
2713 dev_error="${dev_error} or PDEPEND."
2714 if is-java-strict; then
2715 eerror "${dev_error}"
2716 die "${dev_error}"
2717 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2718 eerror "${dev_error}"
2719 elog "The package will build without problems, but may fail to run"
2720 elog "if you don't have ${target_pkg} installed, so please report"
2721 elog "this to http://bugs.gentoo.org"
2722 fi
2723 fi
2724 fi
1944 fi 2725 fi
1945} 2726}
1946 2727
1947# ------------------------------------------------------------------------------ 2728# ------------------------------------------------------------------------------
1948# @section-end internal 2729# @section-end internal
1949# ------------------------------------------------------------------------------ 2730# ------------------------------------------------------------------------------
1950 2731
1951java-pkg_check-phase() { 2732java-pkg_check-phase() {
1952 local phase=${1} 2733 local phase=${1}
1953 local funcname=${2} 2734 local funcname=${FUNCNAME[1]}
1954 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then 2735 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
1955 java-pkg_announce-qa-violation \
1956 "${funcname} used outside of src_${phase}" 2736 local msg="${funcname} used outside of src_${phase}"
2737 java-pkg_announce-qa-violation "${msg}"
1957 fi 2738 fi
1958} 2739}
1959 2740
1960java-pkg_check-versioned-jar() { 2741java-pkg_check-versioned-jar() {
1961 local jar=${1} 2742 local jar=${1}
1970 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2751 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1971 fi 2752 fi
1972} 2753}
1973 2754
1974java-pkg_announce-qa-violation() { 2755java-pkg_announce-qa-violation() {
1975 if is-java-strict; then 2756 local nodie
2757 if [[ ${1} == "--nodie" ]]; then
2758 nodie="true"
2759 shift
2760 fi
1976 echo "Java QA Notice: $@" >&2 2761 echo "Java QA Notice: $@" >&2
1977 increment-qa-violations 2762 increment-qa-violations
1978 fi 2763 [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
1979} 2764}
1980 2765
1981increment-qa-violations() { 2766increment-qa-violations() {
1982 let "JAVA_PKG_QA_VIOLATIONS+=1" 2767 let "JAVA_PKG_QA_VIOLATIONS+=1"
1983 export JAVA_PKG_QA_VIOLATIONS 2768 export JAVA_PKG_QA_VIOLATIONS
1986is-java-strict() { 2771is-java-strict() {
1987 [[ -n ${JAVA_PKG_STRICT} ]] 2772 [[ -n ${JAVA_PKG_STRICT} ]]
1988 return $? 2773 return $?
1989} 2774}
1990 2775
2776
1991# ------------------------------------------------------------------------------ 2777# ------------------------------------------------------------------------------
1992# @eclass-end 2778# @eclass-end
1993# ------------------------------------------------------------------------------ 2779# ------------------------------------------------------------------------------

Legend:
Removed from v.1.38  
changed lines
  Added in v.1.126

  ViewVC Help
Powered by ViewVC 1.1.20