/[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.130
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.130 2009/11/08 20:39:30 caster Exp $
10
11 10
12# ----------------------------------------------------------------------------- 11# -----------------------------------------------------------------------------
13# @eclass-begin 12# @eclass-begin
14# @eclass-shortdesc Java Utility eclass 13# @eclass-shortdesc Java Utility eclass
15# @eclass-maintainer java@gentoo.org 14# @eclass-maintainer java@gentoo.org
36# ----------------------------------------------------------------------------- 35# -----------------------------------------------------------------------------
37 36
38# Make sure we use java-config-2 37# Make sure we use java-config-2
39export WANT_JAVA_CONFIG="2" 38export WANT_JAVA_CONFIG="2"
40 39
41# TODO document 40# -----------------------------------------------------------------------------
42JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1" 41# @variable-external WANT_ANT_TASKS
42# @variable-default ""
43#
44# An $IFS separated list of ant tasks.
45# Ebuild can specify this variable before inheriting java-ant-2 eclass to
46# determine ANT_TASKS it needs. They will be automatically translated to
47# DEPEND variable and ANT_TASKS variable. JAVA_PKG_FORCE_ANT_TASKS can override
48# ANT_TASKS set by WANT_ANT_TASKS, but not the DEPEND due to caching.
49# Ebuilds that need to depend conditionally on certain tasks and specify them
50# differently for different eant calls can't use this simplified approach.
51# You also cannot specify version or anything else than ant-*.
52#
53# @example WANT_ANT_TASKS="ant-junit ant-trax"
54#
55# @seealso JAVA_PKG_FORCE_ANT_TASKS
56# -----------------------------------------------------------------------------
57#WANT_ANT_TASKS
58
59# -----------------------------------------------------------------------------
60# @variable-internal JAVA_PKG_PORTAGE_DEP
61#
62# The version of portage we need to function properly. Previously it was
63# portage with phase hooks support but now we use a version with proper env
64# saving. For EAPI 2 we have new enough stuff so let's have cleaner deps.
65# -----------------------------------------------------------------------------
66hasq "${EAPI}" 0 1 && JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1.2.7"
43 67
44# ----------------------------------------------------------------------------- 68# -----------------------------------------------------------------------------
45# @variable-internal JAVA_PKG_E_DEPEND 69# @variable-internal JAVA_PKG_E_DEPEND
46# 70#
47# This is a convience variable to be used from the other java eclasses. This is 71# This is a convience variable to be used from the other java eclasses. This is
48# the version of java-config we want to use. We also need a recent version 72# the version of java-config we want to use. Usually the latest stable version
49# portage, that includes phase hooks. 73# so that ebuilds can use new features without depending on specific versions.
50# ----------------------------------------------------------------------------- 74# -----------------------------------------------------------------------------
51JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 ${JAVA_PKG_PORTAGE_DEP}" 75JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.1.6 ${JAVA_PKG_PORTAGE_DEP}"
76hasq source ${JAVA_PKG_IUSE} && JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} source? ( app-arch/zip )"
77
78# -----------------------------------------------------------------------------
79# @variable-preinherit JAVA_PKG_WANT_BOOTCLASSPATH
80#
81# The version of bootclasspath the package needs to work. Translates to a proper
82# dependency. The bootclasspath has to be obtained by java-ant_rewrite-bootclasspath
83# -----------------------------------------------------------------------------
84
85if [[ -n "${JAVA_PKG_WANT_BOOTCLASSPATH}" ]]; then
86 if [[ "${JAVA_PKG_WANT_BOOTCLASSPATH}" == "1.5" ]]; then
87 JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} >=dev-java/gnu-classpath-0.98-r1:0.98"
88 else
89 eerror "Unknown value of JAVA_PKG_WANT_BOOTCLASSPATH"
90 # since die in global scope doesn't work, this will make repoman fail
91 JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} BAD_JAVA_PKG_WANT_BOOTCLASSPATH"
92 fi
93fi
52 94
53# ----------------------------------------------------------------------------- 95# -----------------------------------------------------------------------------
54# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 96# @variable-external JAVA_PKG_ALLOW_VM_CHANGE
55# @variable-default yes 97# @variable-default yes
56# 98#
130# @note This should only be used internally or for testing. 172# @note This should only be used internally or for testing.
131# @example Use jikes and javac, in that order 173# @example Use jikes and javac, in that order
132# JAVA_PKG_FORCE_COMPILER="jikes javac" 174# JAVA_PKG_FORCE_COMPILER="jikes javac"
133# ----------------------------------------------------------------------------- 175# -----------------------------------------------------------------------------
134 176
177# -----------------------------------------------------------------------------
178# @variable-external JAVA_PKG_FORCE_ANT_TASKS
179#
180# An $IFS separated list of ant tasks. Can be set in environment before calling
181# emerge/ebuild to override variables set in ebuild, mainly for testing before
182# putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in
183# eant() call, not the dependencies specified in WANT_ANT_TASKS.
184#
185# @example JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \
186# ebuild foo.ebuild compile
187#
188# @seealso WANT_ANT_TASKS
189# -----------------------------------------------------------------------------
190
135# TODO document me 191# TODO document me
136JAVA_PKG_QA_VIOLATIONS=0 192JAVA_PKG_QA_VIOLATIONS=0
137 193
138# ----------------------------------------------------------------------------- 194# -----------------------------------------------------------------------------
139# @section-end variables 195# @section-end variables
146# 202#
147# These are used to install Java-related things, such as jars, Javadocs, JNI 203# These are used to install Java-related things, such as jars, Javadocs, JNI
148# libraries, etc. 204# libraries, etc.
149# ----------------------------------------------------------------------------- 205# -----------------------------------------------------------------------------
150 206
207# -----------------------------------------------------------------------------
208# @ebuild-function java-pkg_doexamples
209#
210# Installs given arguments to /usr/share/doc/${PF}/examples
211# If you give it only one parameter and it is a directory it will install
212# everything in that directory to the examples directory.
213#
214# @example
215# java-pkg_doexamples demo
216# java-pkg_doexamples demo/* examples/*
217#
218# @param --subdir - If the examples need a certain directory structure
219# @param $* - list of files to install
220# ------------------------------------------------------------------------------
221java-pkg_doexamples() {
222 debug-print-function ${FUNCNAME} $*
223
224 [[ ${#} -lt 1 ]] && die "At least one argument needed"
225
226 java-pkg_check-phase install
227
228 local dest=/usr/share/doc/${PF}/examples
229 if [[ ${1} == --subdir ]]; then
230 local dest=${dest}/${2}
231 dodir ${dest}
232 shift 2
233 fi
234
235 if [[ ${#} = 1 && -d ${1} ]]; then
236 ( # dont want to pollute calling env
237 insinto "${dest}"
238 doins -r ${1}/*
239 ) || die "Installing examples failed"
240 else
241 ( # dont want to pollute calling env
242 insinto "${dest}"
243 doins -r "$@"
244 ) || die "Installing examples failed"
245 fi
246}
151 247
152# ----------------------------------------------------------------------------- 248# -----------------------------------------------------------------------------
153# @ebuild-function java-pkg_dojar 249# @ebuild-function java-pkg_dojar
154# 250#
155# Installs any number of jars. 251# Installs any number of jars.
174 # Create JARDEST if it doesn't exist 270 # Create JARDEST if it doesn't exist
175 dodir ${JAVA_PKG_JARDEST} 271 dodir ${JAVA_PKG_JARDEST}
176 272
177 local jar 273 local jar
178 # for each jar 274 # for each jar
179 for jar in "$@"; do 275 for jar in "${@}"; do
180 local jar_basename=$(basename "${jar}") 276 local jar_basename=$(basename "${jar}")
181 277
182 java-pkg_check-versioned-jar ${jar_basename} 278 java-pkg_check-versioned-jar ${jar_basename}
183 279
184 # check if it exists 280 # check if it exists
185 if [[ -e "${jar}" ]] ; then 281 if [[ -e "${jar}" ]] ; then
282 # Don't overwrite if jar has already been installed with the same
283 # name
284 local dest="${D}${JAVA_PKG_JARDEST}/${jar_basename}"
285 if [[ -e "${dest}" ]]; then
286 ewarn "Overwriting ${dest}"
287 fi
288
186 # install it into JARDEST if it's a non-symlink 289 # install it into JARDEST if it's a non-symlink
187 if [[ ! -L "${jar}" ]] ; then 290 if [[ ! -L "${jar}" ]] ; then
291 #but first check class version when in strict mode.
292 is-java-strict && java-pkg_verify-classes "${jar}"
293
188 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 294 INSDESTTREE="${JAVA_PKG_JARDEST}" \
189 doins "${jar}" || die "failed to install ${jar}" 295 doins "${jar}" || die "failed to install ${jar}"
190 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 296 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
191 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}" 297 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}"
192 # make a symlink to the original jar if it's symlink 298 # make a symlink to the original jar if it's symlink
202 done 308 done
203 309
204 java-pkg_do_write_ 310 java-pkg_do_write_
205} 311}
206 312
313# ------------------------------------------------------------------------------
314# @internal-function depend-java-query
315#
316# Wrapper for the depend-java-query binary to enable passing USE in env.
317# Using env variables keeps this eclass working with java-config versions that
318# do not handle use flags.
319# ------------------------------------------------------------------------------
207 320
321depend-java-query() {
322 # Used to have a which call here but it caused endless loops for some people
323 # that had some weird bashrc voodoo for which.
324 USE="${USE}" /usr/bin/depend-java-query "${@}"
325}
208 326
209# ------------------------------------------------------------------------------ 327# ------------------------------------------------------------------------------
210# @ebuild-function java-pkg_regjar 328# @ebuild-function java-pkg_regjar
211# 329#
212# Records an already installed jar in the package.env 330# Records an already installed jar in the package.env
243 [[ ${#} -lt 1 ]] && die "at least one argument needed" 361 [[ ${#} -lt 1 ]] && die "at least one argument needed"
244 362
245 java-pkg_init_paths_ 363 java-pkg_init_paths_
246 364
247 local jar jar_dir jar_file 365 local jar jar_dir jar_file
248 for jar in "$@"; do 366 for jar in "${@}"; do
249 # TODO use java-pkg_check-versioned-jar 367 # TODO use java-pkg_check-versioned-jar
250 if [[ -e "${jar}" ]]; then 368 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
369 [[ -d "${jar}" || -d "${D}${jar}" ]] \
370 && die "Called ${FUNCNAME} on a directory $*"
371
372 #check that class version correct when in strict mode
373 is-java-strict && java-pkg_verify-classes "${jar}"
374
251 # nelchael: we should strip ${D} in this case too, here's why: 375 # nelchael: we should strip ${D} in this case too, here's why:
252 # imagine such call: 376 # imagine such call:
253 # java-pkg_regjar ${D}/opt/java/*.jar 377 # java-pkg_regjar ${D}/opt/java/*.jar
254 # such call will fall into this case (-e ${jar}) and will 378 # such call will fall into this case (-e ${jar}) and will
255 # record paths with ${D} in package.env 379 # record paths with ${D} in package.env
256 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 380 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 381 else
382 if [[ ${jar} = *\** ]]; then
383 eerror "The argument ${jar} to ${FUNCNAME}"
384 eerror "has * in it. If you want it to glob in"
385 eerror '${D} add ${D} to the argument.'
386 fi
387 debug-print "${jar} or ${D}${jar} not found"
260 die "${jar} does not exist" 388 die "${jar} does not exist"
261 fi 389 fi
262 done 390 done
263 391
264 java-pkg_do_write_ 392 java-pkg_do_write_
265} 393}
266
267 394
268# ------------------------------------------------------------------------------ 395# ------------------------------------------------------------------------------
269# @ebuild-function java-pkg_newjar 396# @ebuild-function java-pkg_newjar
270# 397#
271# Installs a jar with a new name 398# Installs a jar with a new name
282 local original_jar="${1}" 409 local original_jar="${1}"
283 local new_jar="${2:-${PN}.jar}" 410 local new_jar="${2:-${PN}.jar}"
284 local new_jar_dest="${T}/${new_jar}" 411 local new_jar_dest="${T}/${new_jar}"
285 412
286 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 413 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
287 [[ ! -f ${original_jar} ]] && die "${original_jar} does not exist!" 414 [[ ! -f ${original_jar} ]] \
415 && die "${original_jar} does not exist or is not a file!"
288 416
289 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 417 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
290 cp "${original_jar}" "${new_jar_dest}" \ 418 cp "${original_jar}" "${new_jar_dest}" \
291 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 419 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
292 java-pkg_dojar "${new_jar_dest}" 420 java-pkg_dojar "${new_jar_dest}"
319# @param $@ - JNI libraries to install 447# @param $@ - JNI libraries to install
320# ------------------------------------------------------------------------------ 448# ------------------------------------------------------------------------------
321java-pkg_doso() { 449java-pkg_doso() {
322 debug-print-function ${FUNCNAME} $* 450 debug-print-function ${FUNCNAME} $*
323 451
324 [[ ${#} -lt 1 ]] && "At least one argument required for ${FUNCNAME}"
325 java-pkg_check-phase install 452 java-pkg_check-phase install
326 453
327 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 454 [[ ${#} -lt 1 ]] && die "${FUNCNAME} requires at least one argument"
328 455
329 java-pkg_init_paths_ 456 java-pkg_init_paths_
330 457
331 local lib 458 local lib
332 # for each lib 459 # for each lib
335 if [[ -e "${lib}" ]] ; then 462 if [[ -e "${lib}" ]] ; then
336 # install if it isn't a symlink 463 # install if it isn't a symlink
337 if [[ ! -L "${lib}" ]] ; then 464 if [[ ! -L "${lib}" ]] ; then
338 INSDESTTREE="${JAVA_PKG_LIBDEST}" \ 465 INSDESTTREE="${JAVA_PKG_LIBDEST}" \
339 INSOPTIONS="${LIBOPTIONS}" \ 466 INSOPTIONS="${LIBOPTIONS}" \
340 doins "${lib}" || "failed to install ${lib}" 467 doins "${lib}" || die "failed to install ${lib}"
341 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 468 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
342 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 469 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
343 # otherwise make a symlink to the symlink's origin 470 # otherwise make a symlink to the symlink's origin
344 else 471 else
345 # TODO use dosym
346 ln -s "$(readlink "${lib}")" "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")" 472 dosym "$(readlink "${lib}")" "${JAVA_PKG_LIBDEST}/${lib##*/}"
347 debug-print "${lib} is a symlink, linking accordanly" 473 debug-print "${lib} is a symlink, linking accordantly"
348 fi 474 fi
349 # otherwise die 475 # otherwise die
350 else 476 else
351 die "${lib} does not exist" 477 die "${lib} does not exist"
352 fi 478 fi
368java-pkg_regso() { 494java-pkg_regso() {
369 debug-print-function ${FUNCNAME} $* 495 debug-print-function ${FUNCNAME} $*
370 496
371 java-pkg_check-phase install 497 java-pkg_check-phase install
372 498
373 [[ ${#} -lt 1 ]] && "at least one argument needed" 499 [[ ${#} -lt 1 ]] && die "${FUNCNAME} requires at least one argument"
374 500
375 java-pkg_init_paths_ 501 java-pkg_init_paths_
376 502
377 local lib target_dir 503 local lib target_dir
378 for lib in "$@" ; do 504 for lib in "$@" ; do
445# ------------------------------------------------------------------------------ 571# ------------------------------------------------------------------------------
446# @ebuild-function java-pkg_dojavadoc 572# @ebuild-function java-pkg_dojavadoc
447# 573#
448# Installs javadoc documentation. This should be controlled by the doc use flag. 574# Installs javadoc documentation. This should be controlled by the doc use flag.
449# 575#
576# @param $1: optional --symlink creates to symlink like this for html
577# documentation bundles.
450# @param $1: - The javadoc root directory. 578# @param $2: - The javadoc root directory.
451# 579#
452# @example: 580# @example:
453# java-pkg_dojavadoc docs/api 581# java-pkg_dojavadoc docs/api
582# java-pkg_dojavadoc --symlink apidocs docs/api
454# 583#
455# ------------------------------------------------------------------------------ 584# ------------------------------------------------------------------------------
456java-pkg_dojavadoc() { 585java-pkg_dojavadoc() {
586 debug-print-function ${FUNCNAME} $*
587
588 # For html documentation bundles that link to Javadoc
589 local symlink
590 if [[ ${1} = --symlink ]]; then
591 symlink=${2}
592 shift 2
593 fi
594
457 local dir="$1" 595 local dir="$1"
596 local dest=/usr/share/doc/${PF}/html
597
598 # QA checks
458 599
459 java-pkg_check-phase install 600 java-pkg_check-phase install
460 601
461 [[ -z "${dir}" ]] && die "Must specify a directory!" 602 [[ -z "${dir}" ]] && die "Must specify a directory!"
462 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!" 603 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!"
604 if [[ ! -e "${dir}/index.html" ]]; then
605 local msg="No index.html in javadoc directory"
606 ewarn "${msg}"
607 is-java-strict && die "${msg}"
608 fi
609
610 if [[ -e ${D}/${dest}/api ]]; then
611 eerror "${dest} already exists. Will not overwrite."
612 die "${dest}"
613 fi
614
615 # Renaming to match our directory layout
463 616
464 local dir_to_install="${dir}" 617 local dir_to_install="${dir}"
465 if [[ "$(basename "${dir}")" != "api" ]]; then 618 if [[ "$(basename "${dir}")" != "api" ]]; then
466 dir_to_install="${T}/api" 619 dir_to_install="${T}/api"
467 # TODO use doins 620 # TODO use doins
468 cp -r "${dir}" "${dir_to_install}" || die "cp failed" 621 cp -r "${dir}" "${dir_to_install}" || die "cp failed"
469 fi 622 fi
470 623
624 # Actual installation
625
471 java-pkg_dohtml -r ${dir_to_install} 626 java-pkg_dohtml -r "${dir_to_install}"
627
628 # Let's make a symlink to the directory we have everything else under
629 dosym ${dest}/api "${JAVA_PKG_SHAREPATH}/api" || die
630
631 if [[ ${symlink} ]]; then
632 debug-print "symlinking ${dest}/{api,${symlink}}"
633 dosym ${dest}/{api,${symlink}} || die
634 fi
472} 635}
473 636
474# ------------------------------------------------------------------------------ 637# ------------------------------------------------------------------------------
475# @ebuild-function java-pkg_dosrc 638# @ebuild-function java-pkg_dosrc
476# 639#
492# FIXME apparently this fails if you give it an empty directories 655# FIXME apparently this fails if you give it an empty directories
493java-pkg_dosrc() { 656java-pkg_dosrc() {
494 debug-print-function ${FUNCNAME} $* 657 debug-print-function ${FUNCNAME} $*
495 658
496 [ ${#} -lt 1 ] && die "At least one argument needed" 659 [ ${#} -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 660
501 java-pkg_check-phase install 661 java-pkg_check-phase install
502 662
503 [[ ${#} -lt 1 ]] && die "At least one argument needed" 663 [[ ${#} -lt 1 ]] && die "At least one argument needed"
664
665 if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
666 local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
667 java-pkg_announce-qa-violation ${msg}
668 fi
504 669
505 java-pkg_init_paths_ 670 java-pkg_init_paths_
506 671
507 local zip_name="${PN}-src.zip" 672 local zip_name="${PN}-src.zip"
508 local zip_path="${T}/${zip_name}" 673 local zip_path="${T}/${zip_name}"
509 local dir 674 local dir
510 for dir in ${@}; do 675 for dir in "${@}"; do
511 local dir_parent=$(dirname "${dir}") 676 local dir_parent=$(dirname "${dir}")
512 local dir_name=$(basename "${dir}") 677 local dir_name=$(basename "${dir}")
513 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 678 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
514 zip -q -r ${zip_path} ${dir_name} -i '*.java' 679 zip -q -r ${zip_path} ${dir_name} -i '*.java'
515 local result=$? 680 local result=$?
540# @param $1 - filename of launcher to create 705# @param $1 - filename of launcher to create
541# @param $2 - options, as follows: 706# @param $2 - options, as follows:
542# --main the.main.class.too.start 707# --main the.main.class.too.start
543# --jar /the/jar/too/launch.jar or just <name>.jar 708# --jar /the/jar/too/launch.jar or just <name>.jar
544# --java_args 'Extra arguments to pass to java' 709# --java_args 'Extra arguments to pass to java'
545# --pkg_args 'Extra arguments too pass to the package' 710# --pkg_args 'Extra arguments to pass to the package'
546# --pwd 711# --pwd Directory the launcher changes to before executing java
547# -into 712# -into Directory to install the launcher to, instead of /usr/bin
548# -pre 713# -pre Prepend contents of this file to the launcher
549# ------------------------------------------------------------------------------ 714# ------------------------------------------------------------------------------
550java-pkg_dolauncher() { 715java-pkg_dolauncher() {
551 debug-print-function ${FUNCNAME} $* 716 debug-print-function ${FUNCNAME} $*
552 717
553 java-pkg_check-phase install 718 java-pkg_check-phase install
565 local var_tmp="${T}/launcher_variables_tmp" 730 local var_tmp="${T}/launcher_variables_tmp"
566 local target_dir pre 731 local target_dir pre
567 732
568 # Process the other the rest of the arguments 733 # Process the other the rest of the arguments
569 while [[ -n "${1}" && -n "${2}" ]]; do 734 while [[ -n "${1}" && -n "${2}" ]]; do
570 local var=${1} value=${2} 735 local var="${1}" value="${2}"
571 if [[ "${var:0:2}" == "--" ]]; then 736 if [[ "${var:0:2}" == "--" ]]; then
572 local var=${var:2} 737 local var=${var:2}
573 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}" 738 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
574 local gjl_${var}="${value}" 739 local gjl_${var}="${value}"
575 elif [[ "${var}" == "-into" ]]; then 740 elif [[ "${var}" == "-into" ]]; then
594 fi 759 fi
595 fi 760 fi
596 761
597 # Write the actual script 762 # Write the actual script
598 echo "#!/bin/bash" > "${target}" 763 echo "#!/bin/bash" > "${target}"
599 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 764 if [[ -n "${pre}" ]]; then
765 if [[ -f "${pre}" ]]; then
766 cat "${pre}" >> "${target}"
767 else
768 die "-pre specified file '${pre}' does not exist"
769 fi
770 fi
600 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 771 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
601 cat "${var_tmp}" >> "${target}" 772 cat "${var_tmp}" >> "${target}"
602 rm -f "${var_tmp}" 773 rm -f "${var_tmp}"
603 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 774 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
604 775
696# Example: get a specific jar from xerces slot 2, and name it diffrently 867# 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 868# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
698# Example: get junit.jar which is needed only for building 869# Example: get junit.jar which is needed only for building
699# java-pkg_jar-from --build-only junit junit.jar 870# java-pkg_jar-from --build-only junit junit.jar
700# 871#
701# @param $1 - (optional) "--build-only" makes the jar(s) not added into 872# @param $opt
702# package.env DEPEND line. 873# --build-only - makes the jar(s) not added into package.env DEPEND line.
703# @param $1 - Package to get jars from. 874# (assumed automatically when called inside src_test)
875# --with-dependencies - get jars also from requested package's dependencies
876# transitively.
877# --virtual - Packages passed to this function are to be handled as virtuals
878# and will not have individual jar dependencies recorded.
879# --into $dir - symlink jar(s) into $dir (must exist) instead of .
880# @param $1 - Package to get jars from, or comma-separated list of packages in
881# case other parameters are not used.
704# @param $2 - jar from package. If not specified, all jars will be used. 882# @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 883# @param $3 - When a single jar is specified, destination filename of the
706# symlink. Defaults to the name of the jar. 884# symlink. Defaults to the name of the jar.
707# ------------------------------------------------------------------------------ 885# ------------------------------------------------------------------------------
708# TODO could probably be cleaned up a little 886# TODO could probably be cleaned up a little
709java-pkg_jar-from() { 887java-pkg_jar-from() {
710 debug-print-function ${FUNCNAME} $* 888 debug-print-function ${FUNCNAME} $*
711 889
712 local build_only="" 890 local build_only=""
891 local destdir="."
892 local deep=""
893 local virtual=""
894 local record_jar=""
713 895
896 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
897
898 while [[ "${1}" == --* ]]; do
714 if [[ "${1}" = "--build-only" ]]; then 899 if [[ "${1}" = "--build-only" ]]; then
715 build_only="true" 900 build_only="build"
901 elif [[ "${1}" = "--with-dependencies" ]]; then
902 deep="--with-dependencies"
903 elif [[ "${1}" = "--virtual" ]]; then
904 virtual="true"
905 elif [[ "${1}" = "--into" ]]; then
906 destdir="${2}"
907 shift
908 else
909 die "java-pkg_jar-from called with unknown parameter: ${1}"
910 fi
716 shift 911 shift
717 fi 912 done
718 913
719 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 914 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
720 915
721 [[ -z ${target_pkg} ]] && die "Must specify a package" 916 [[ -z ${target_pkg} ]] && die "Must specify a package"
917
918 if [[ "${EAPI}" == "1" ]]; then
919 target_pkg="${target_pkg//:/-}"
920 fi
722 921
723 # default destjar to the target jar 922 # default destjar to the target jar
724 [[ -z "${destjar}" ]] && destjar="${target_jar}" 923 [[ -z "${destjar}" ]] && destjar="${target_jar}"
725 924
726 local error_msg="There was a problem getting the classpath for ${target_pkg}." 925 local error_msg="There was a problem getting the classpath for ${target_pkg}."
727 local classpath 926 local classpath
728 classpath="$(java-config --classpath=${target_pkg})" 927 classpath="$(java-config ${deep} --classpath=${target_pkg})"
729 [[ $? != 0 ]] && die ${error_msg} 928 [[ $? != 0 ]] && die ${error_msg}
929
930 # When we have commas this functions is called to bring jars from multiple
931 # packages. This affects recording of dependencencies performed later
932 # which expects one package only, so we do it here.
933 if [[ ${target_pkg} = *,* ]]; then
934 for pkg in ${target_pkg//,/ }; do
935 java-pkg_ensure-dep "${build_only}" "${pkg}"
936 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
937 done
938 # setting this disables further record-jar_ calls later
939 record_jar="true"
940 else
941 java-pkg_ensure-dep "${build_only}" "${target_pkg}"
942 fi
943
944 # Record the entire virtual as a dependency so that
945 # no jars are missed.
946 if [[ -z "${build_only}" && -n "${virtual}" ]]; then
947 java-pkg_record-jar_ "${target_pkg}"
948 # setting this disables further record-jars_ calls later
949 record_jar="true"
950 fi
951
952 pushd ${destdir} > /dev/null \
953 || die "failed to change directory to ${destdir}"
730 954
731 local jar 955 local jar
732 for jar in ${classpath//:/ }; do 956 for jar in ${classpath//:/ }; do
733 local jar_name=$(basename "${jar}") 957 local jar_name=$(basename "${jar}")
734 if [[ ! -f "${jar}" ]] ; then 958 if [[ ! -f "${jar}" ]] ; then
738 # If no specific target jar was indicated, link it 962 # If no specific target jar was indicated, link it
739 if [[ -z "${target_jar}" ]] ; then 963 if [[ -z "${target_jar}" ]] ; then
740 [[ -f "${target_jar}" ]] && rm "${target_jar}" 964 [[ -f "${target_jar}" ]] && rm "${target_jar}"
741 ln -snf "${jar}" \ 965 ln -snf "${jar}" \
742 || die "Failed to make symlink from ${jar} to ${jar_name}" 966 || die "Failed to make symlink from ${jar} to ${jar_name}"
967 if [[ -z "${record_jar}" ]]; then
968 if [[ -z "${build_only}" ]]; then
743 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}" 969 java-pkg_record-jar_ "${target_pkg}" "${jar}"
970 else
971 java-pkg_record-jar_ --build-only "${target_pkg}" "${jar}"
972 fi
973 fi
744 # otherwise, if the current jar is the target jar, link it 974 # otherwise, if the current jar is the target jar, link it
745 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 975 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
746 [[ -f "${destjar}" ]] && rm "${destjar}" 976 [[ -f "${destjar}" ]] && rm "${destjar}"
747 ln -snf "${jar}" "${destjar}" \ 977 ln -snf "${jar}" "${destjar}" \
748 || die "Failed to make symlink from ${jar} to ${destjar}" 978 || die "Failed to make symlink from ${jar} to ${destjar}"
979 if [[ -z "${record_jar}" ]]; then
980 if [[ -z "${build_only}" ]]; then
749 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}" 981 java-pkg_record-jar_ "${target_pkg}" "${jar}"
982 else
983 java-pkg_record-jar_ --build-only "${target_jar}" "${jar}"
984 fi
985 fi
986 popd > /dev/null
750 return 0 987 return 0
751 fi 988 fi
752 done 989 done
990 popd > /dev/null
753 # if no target was specified, we're ok 991 # if no target was specified, we're ok
754 if [[ -z "${target_jar}" ]] ; then 992 if [[ -z "${target_jar}" ]] ; then
755 return 0 993 return 0
756 # otherwise, die bitterly 994 # otherwise, die bitterly
757 else 995 else
781# Example: Get the classpath for xerces-2 and xalan, 1019# Example: Get the classpath for xerces-2 and xalan,
782# java-pkg_getjars xerces-2,xalan 1020# java-pkg_getjars xerces-2,xalan
783# Example Return: 1021# Example Return:
784# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 1022# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
785# 1023#
786# @param $1 - (optional) "--build-only" makes the jar(s) not added into 1024# @param $opt
787# package.env DEPEND line. 1025# --build-only - makes the jar(s) not added into package.env DEPEND line.
1026# (assumed automatically when called inside src_test)
1027# --with-dependencies - get jars also from requested package's dependencies
1028# transitively.
788# @param $2 - list of packages to get jars from 1029# @param $1 - list of packages to get jars from
789# (passed to java-config --classpath) 1030# (passed to java-config --classpath)
790# ------------------------------------------------------------------------------ 1031# ------------------------------------------------------------------------------
791java-pkg_getjars() { 1032java-pkg_getjars() {
792 debug-print-function ${FUNCNAME} $* 1033 debug-print-function ${FUNCNAME} $*
793 1034
794 [[ ${#} -lt 1 || ${#} -gt 2 ]] && die "${FUNCNAME} takes only one or two arguments" 1035 local build_only=""
1036 local deep=""
795 1037
1038 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1039
1040 while [[ "${1}" == --* ]]; do
796 if [[ "${1}" = "--build-only" ]]; then 1041 if [[ "${1}" = "--build-only" ]]; then
797 local build_only="true" 1042 build_only="build"
1043 elif [[ "${1}" = "--with-dependencies" ]]; then
1044 deep="--with-dependencies"
1045 else
1046 die "java-pkg_jar-from called with unknown parameter: ${1}"
1047 fi
798 shift 1048 shift
799 fi 1049 done
800 1050
1051 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
1052
1053
801 local classpath pkgs="${1}" 1054 local pkgs="${1}"
1055
1056 if [[ "${EAPI}" == "1" ]]; then
1057 pkgs="${pkgs//:/-}"
1058 fi
1059
802 jars="$(java-config --classpath=${pkgs})" 1060 jars="$(java-config ${deep} --classpath=${pkgs})"
803 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed" 1061 [[ $? != 0 ]] && die "java-config --classpath=${pkgs} failed"
804 debug-print "${pkgs}:${jars}" 1062 debug-print "${pkgs}:${jars}"
805 1063
806 if [[ -z "${classpath}" ]]; then 1064 for pkg in ${pkgs//,/ }; do
807 classpath="${jars}" 1065 java-pkg_ensure-dep "${build_only}" "${pkg}"
808 else 1066 done
809 classpath="${classpath}:${jars}"
810 fi
811 1067
812 # Only record jars that aren't build-only 1068 for pkg in ${pkgs//,/ }; do
813 if [[ -z "${build_only}" ]]; then 1069 if [[ -z "${build_only}" ]]; then
814 oldifs="${IFS}"
815 IFS=","
816 for pkg in ${pkgs}; do
817 java-pkg_record-jar_ "${pkg}" 1070 java-pkg_record-jar_ "${pkg}"
1071 else
1072 java-pkg_record-jar_ --build-only "${pkg}"
1073 fi
818 done 1074 done
819 IFS="${oldifs}"
820 fi
821 1075
822 echo "${classpath}" 1076 echo "${jars}"
823} 1077}
824 1078
825# ------------------------------------------------------------------------------ 1079# ------------------------------------------------------------------------------
826# @ebuild-function java-pkg_getjar 1080# @ebuild-function java-pkg_getjar
827# 1081#
834# @example 1088# @example
835# java-pkg_getjar xerces-2 xml-apis.jar 1089# java-pkg_getjar xerces-2 xml-apis.jar
836# @example-return 1090# @example-return
837# /usr/share/xerces-2/lib/xml-apis.jar 1091# /usr/share/xerces-2/lib/xml-apis.jar
838# 1092#
839# @param $1 - (optional) "--build-only" makes the jar not added into 1093# @param $opt
840# package.env DEPEND line. 1094# --build-only - makes the jar not added into package.env DEPEND line.
1095# --virtual - Packages passed to this function are to be handled as virtuals
1096# and will not have individual jar dependencies recorded.
841# @param $1 - package to use 1097# @param $1 - package to use
842# @param $2 - jar to get 1098# @param $2 - jar to get
843# ------------------------------------------------------------------------------ 1099# ------------------------------------------------------------------------------
844java-pkg_getjar() { 1100java-pkg_getjar() {
845 debug-print-function ${FUNCNAME} $* 1101 debug-print-function ${FUNCNAME} $*
846 1102
847 local build_only="" 1103 local build_only=""
1104 local virtual=""
1105 local record_jar=""
848 1106
1107 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1108
1109 while [[ "${1}" == --* ]]; do
849 if [[ "${1}" = "--build-only" ]]; then 1110 if [[ "${1}" = "--build-only" ]]; then
850 build_only="true" 1111 build_only="build"
1112 elif [[ "${1}" == "--virtual" ]]; then
1113 virtual="true"
1114 else
1115 die "java-pkg_getjar called with unknown parameter: ${1}"
1116 fi
851 shift 1117 shift
852 fi 1118 done
1119
1120 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
853 1121
854 local pkg="${1}" target_jar="${2}" jar 1122 local pkg="${1}" target_jar="${2}" jar
1123
1124 if [[ "${EAPI}" == "1" ]]; then
1125 pkg="${pkg//:/-}"
1126 fi
1127
855 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 1128 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
856 [[ -z ${target_jar} ]] && die "Must specify jar to get" 1129 [[ -z ${target_jar} ]] && die "Must specify jar to get"
857 1130
858 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?" 1131 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
859 local classpath 1132 local classpath
860 classpath=$(java-config --classpath=${pkg}) 1133 classpath=$(java-config --classpath=${pkg})
861 [[ $? != 0 ]] && die ${error_msg} 1134 [[ $? != 0 ]] && die ${error_msg}
862 1135
1136 java-pkg_ensure-dep "${build_only}" "${pkg}"
1137
1138 # Record the package(Virtual) as a dependency and then set build_only
1139 # So that individual jars are not recorded.
1140 if [[ -n "${virtual}" ]]; then
1141 if [[ -z "${build_only}" ]]; then
1142 java-pkg_record-jar_ "${pkg}"
1143 else
1144 java-pkg_record-jar_ --build-only "${pkg}"
1145 fi
1146 record_jar="true"
1147 fi
1148
863 for jar in ${classpath//:/ }; do 1149 for jar in ${classpath//:/ }; do
864 if [[ ! -f "${jar}" ]] ; then 1150 if [[ ! -f "${jar}" ]] ; then
865 die "Installation problem with jar ${jar} in ${pkg} - is it installed?" 1151 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
866 fi 1152 fi
867 1153
868 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then 1154 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
869 # Only record jars that aren't build-only 1155 # Only record jars that aren't build-only
870 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" "${jar}" 1156 if [[ -z "${record_jar}" ]]; then
1157 if [[ -z "${build_only}" ]]; then
1158 java-pkg_record-jar_ "${pkg}" "${jar}"
1159 else
1160 java-pkg_record-jar_ --build-only "${pkg}" "${jar}"
1161 fi
1162 fi
871 echo "${jar}" 1163 echo "${jar}"
872 return 0 1164 return 0
873 fi 1165 fi
874 done 1166 done
875 1167
876 die "Could not find ${target_jar} in ${pkg}" 1168 die "Could not find ${target_jar} in ${pkg}"
877 return 1 1169 return 1
1170}
1171
1172# ------------------------------------------------------------------------------
1173# @ebuild-function java-pkg_register-dependency
1174#
1175# Registers runtime dependency on a package, list of packages, or a single jar
1176# from a package, into package.env DEPEND line. Can only be called in
1177# src_install phase.
1178# Intended for binary packages where you don't need to symlink the jars or get
1179# their classpath during build. As such, the dependencies only need to be
1180# specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1181#
1182# @param $1 - comma-separated list of packages, or a single package
1183# @param $2 - if param $1 is a single package, optionally specify the jar
1184# to depend on
1185#
1186# Example: Record the dependency on whole xerces-2 and xalan,
1187# java-pkg_register-dependency xerces-2,xalan
1188# Example: Record the dependency on ant.jar from ant-core
1189# java-pkg_register-dependency ant-core ant.jar
1190#
1191# Note: Passing both list of packages as the first parameter AND specifying the
1192# jar as the second is not allowed and will cause the function to die. We assume
1193# that there's more chance one passes such combination as a mistake, than that
1194# there are more packages providing identically named jar without class
1195# collisions.
1196# ------------------------------------------------------------------------------
1197java-pkg_register-dependency() {
1198 debug-print-function ${FUNCNAME} $*
1199
1200 java-pkg_check-phase install
1201
1202 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1203
1204 local pkgs="${1}"
1205 local jar="${2}"
1206
1207 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1208
1209 if [[ "${EAPI}" == "1" ]]; then
1210 pkgs="${pkgs//:/-}"
1211 fi
1212
1213 if [[ -z "${jar}" ]]; then
1214 for pkg in ${pkgs//,/ }; do
1215 java-pkg_ensure-dep runtime "${pkg}"
1216 java-pkg_record-jar_ "${pkg}"
1217 done
1218 else
1219 [[ ${pkgs} == *,* ]] && \
1220 die "${FUNCNAME} called with both package list and jar name"
1221 java-pkg_ensure-dep runtime "${pkgs}"
1222 java-pkg_record-jar_ "${pkgs}" "${jar}"
1223 fi
1224
1225 java-pkg_do_write_
1226}
1227
1228# ------------------------------------------------------------------------------
1229# @ebuild-function java-pkg_register-optional-dependency
1230#
1231# Registers optional runtime dependency on a package, list of packages, or a
1232# single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be
1233# called in src_install phase.
1234# Intended for packages that can use other packages when those are in classpath.
1235# Will be put on classpath by launcher if they are installed. Typical case is
1236# JDBC implementations for various databases. It's better than having USE flag
1237# for each implementation triggering hard dependency.
1238#
1239# @param $1 - comma-separated list of packages, or a single package
1240# @param $2 - if param $1 is a single package, optionally specify the jar
1241# to depend on
1242#
1243# Example: Record the optional dependency on some jdbc providers
1244# java-pkg_register-optional-dependency jdbc-jaybird,jtds-1.2,jdbc-mysql
1245#
1246# Note: Passing both list of packages as the first parameter AND specifying the
1247# jar as the second is not allowed and will cause the function to die. We assume
1248# that there's more chance one passes such combination as a mistake, than that
1249# there are more packages providing identically named jar without class
1250# collisions.
1251# ------------------------------------------------------------------------------
1252java-pkg_register-optional-dependency() {
1253 debug-print-function ${FUNCNAME} $*
1254
1255 java-pkg_check-phase install
1256
1257 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1258
1259 local pkgs="${1}"
1260 local jar="${2}"
1261
1262 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1263
1264 if [[ "${EAPI}" == "1" ]]; then
1265 pkgs="${pkgs//:/-}"
1266 fi
1267
1268 if [[ -z "${jar}" ]]; then
1269 for pkg in ${pkgs//,/ }; do
1270 java-pkg_record-jar_ --optional "${pkg}"
1271 done
1272 else
1273 [[ ${pkgs} == *,* ]] && \
1274 die "${FUNCNAME} called with both package list and jar name"
1275 java-pkg_record-jar_ --optional "${pkgs}" "${jar}"
1276 fi
1277
1278 java-pkg_do_write_
1279}
1280
1281# ------------------------------------------------------------------------------
1282# @ebuild-function java-pkg_register-environment-variable
1283#
1284# Register an arbitrary environment variable into package.env. The gjl launcher
1285# for this package or any package depending on this will export it into
1286# environement before executing java command.
1287# Must only be called in src_install phase.
1288#
1289# @param $1 - variable name
1290# @param $2 - variable value
1291# ------------------------------------------------------------------------------
1292JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
1293JAVA_PKG_EXTRA_ENV_VARS=""
1294java-pkg_register-environment-variable() {
1295 debug-print-function ${FUNCNAME} $*
1296
1297 java-pkg_check-phase install
1298
1299 [[ ${#} != 2 ]] && die "${FUNCNAME} takes two arguments"
1300
1301 echo "${1}=\"${2}\"" >> ${JAVA_PKG_EXTRA_ENV}
1302 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
1303
1304 java-pkg_do_write_
878} 1305}
879 1306
880# This function reads stdin, and based on that input, figures out how to 1307# This function reads stdin, and based on that input, figures out how to
881# populate jars from the filesystem. 1308# populate jars from the filesystem.
882# Need to figure out a good way of making use of this, ie be able to use a 1309# Need to figure out a good way of making use of this, ie be able to use a
923# 1350#
924# Various other functions to use from an ebuild 1351# Various other functions to use from an ebuild
925# ------------------------------------------------------------------------------ 1352# ------------------------------------------------------------------------------
926 1353
927# ------------------------------------------------------------------------------ 1354# ------------------------------------------------------------------------------
928# @ebuild-function java-pkg_need 1355# @ebuild-function java-pkg_find-normal-jars
929# 1356#
930# Adds virtual dependencies, which can optionally be controlled by a USE flag. 1357# Find the files with suffix .jar file in the given directory or $WORKDIR
931# Currently supported virtuals are:
932# javamail
933# jdbc-stdext
934# jaf
935# jdbc-rowset
936# jms
937# 1358#
938# @param $1 - Optionally indicate that the dependencies are controlled by 1359# @param $1 - The directory to search for jar files (default: ${WORKDIR})
939# a use flag by specifying '--use' Requires $2.
940# @param $2 - USE flag which will enable the dependencies.
941# @param $@ - virtual packages to add depenedencies for
942# ------------------------------------------------------------------------------ 1360# ------------------------------------------------------------------------------
943# TODO rewrite to parse a line based declaration file instead -- karltk 1361java-pkg_find-normal-jars() {
944#java-pkg_need() { 1362 local dir=$1
945# debug-print-function ${FUNCNAME} $* 1363 [[ "${dir}" ]] || dir="${WORKDIR}"
946# local useflag 1364 local found
947# if [[ ${1} == "--use" ]]; then 1365 for jar in $(find "${dir}" -name "*.jar" -type f); do
948# useflag="${2}" 1366 echo "${jar}"
949# shift 2 1367 found="true"
950# fi
951#
952# if [[ -z ${1} ]]; then
953# die "Must specify at least one virtual package."
954# fi
955#
956# local depstr newdepstr
957#
958# for virtual in ${@}; do
959# if has ${virtual} ${JAVA_PKG_VNEED}; then
960# debug-print "Already registered virtual ${virtual}"
961# continue
962# fi
963# case ${virtual} in
964# javamail)
965# debug-print "java-pkg_need: adding javamail dependencies"
966# newdepstr="|| ( dev-java/gnu-javamail dev-java/sun-javamail-bin )"
967# ;;
968# jdbc-stdext)
969# debug-print "java-pkg_need: adding jdbc-stdext dependencies"
970# newdepstr="|| ( >=virtual/jdk-1.4 dev-java/jdbc2-stdext )"
971# ;;
972# jaf)
973# debug-print "java-pkg_need: adding jaf dependencies"
974# newdepstr="|| ( dev-java/gnu-jaf dev-java/sun-jaf-bin )"
975# ;;
976# jdbc-rowset)
977# debug-print "java-pkg_need: adding jdbc-rowset dependencies"
978# newdepstr="|| ( >=virtual/jdk-1.5 dev-java/sun-jdbc-rowset )"
979# ;;
980# jms)
981# debug-print "java-pkg_need: adding jms dependencies"
982# newdepstr="|| ( dev-java/sun-jms dev-java/openjms )"
983# ;;
984# *)
985# die "Invalid virtual: ${virtual}"
986# esac
987#
988# export JAVA_PKG_VNEED="${JAVA_PKG_VNEED} ${virtual}"
989#
990# if [[ -n ${useflag} ]]; then
991# depstr="${depstr} ${useflag}? ( ${newdepstr} )"
992# else
993# depstr="${depstr} ${newdepstr}"
994# fi
995# done 1368 done
996# 1369 [[ "${found}" ]]
997# [[ -z ${JAVA_PKG_NV_DEPEND} ]] && export JAVA_PKG_NV_DEPEND="${DEPEND}" 1370 return $?
998# [[ -z ${JAVA_PKG_NV_RDEPEND} ]] && export JAVA_PKG_NV_RDEPEND="${RDEPEND}" 1371}
999#
1000# export DEPEND="${DEPEND} ${depstr}"
1001# export RDEPEND="${RDEPEND} ${depstr}"
1002#}
1003 1372
1373# ------------------------------------------------------------------------------
1374# @ebuild-function java-pkg_ensure-no-bundled-jars
1375#
1376# 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 1377# This function should be called after WORKDIR has been populated with symlink
1005# TODO document 1378# to system jar files or bundled jars removed.
1379# ------------------------------------------------------------------------------
1006java-pkg_ensure-no-bundled-jars() { 1380java-pkg_ensure-no-bundled-jars() {
1007 debug-print-function ${FUNCNAME} $* 1381 debug-print-function ${FUNCNAME} $*
1008 pushd ${WORKDIR} >/dev/null 2>/dev/null
1009 1382
1010 local bundled_jars=$(find . -name "*.jar" -type f) 1383 local bundled_jars=$(java-pkg_find-normal-jars)
1011 if [[ -n ${bundled_jars} ]]; then 1384 if [[ -n ${bundled_jars} ]]; then
1012 echo "Bundled jars found:" 1385 echo "Bundled jars found:"
1013 local jar 1386 local jar
1014 for jar in ${bundled_jars}; do 1387 for jar in ${bundled_jars}; do
1015 echo $(pwd)${jar/./} 1388 echo $(pwd)${jar/./}
1016 done 1389 done
1017 die "Bundled jars found!" 1390 die "Bundled jars found!"
1018
1019 fi 1391 fi
1020 popd >/dev/null 2>/dev/null
1021} 1392}
1022 1393
1023# ------------------------------------------------------------------------------ 1394# ------------------------------------------------------------------------------
1024# @internal-function java-pkg_ensure-vm-version-sufficient 1395# @internal-function java-pkg_ensure-vm-version-sufficient
1025# 1396#
1174# @ebuild-function java-pkg_get-target 1545# @ebuild-function java-pkg_get-target
1175# 1546#
1176# Determines what target version should be used, for passing to -target. 1547# 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 1548# If you don't care about lower versions, you can set _WANT_TARGET to the
1178# version of your JDK. 1549# 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# 1550#
1183# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1551# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1184# ------------------------------------------------------------------------------ 1552# ------------------------------------------------------------------------------
1185java-pkg_get-target() { 1553java-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}")} 1554 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1199} 1555}
1200 1556
1201java-pkg_get-javac() { 1557java-pkg_get-javac() {
1202 debug-print-function ${FUNCNAME} $* 1558 debug-print-function ${FUNCNAME} $*
1203 1559
1292 die "No GCJ support found!" 1648 die "No GCJ support found!"
1293 fi 1649 fi
1294} 1650}
1295 1651
1296java-pkg_ensure-test() { 1652java-pkg_ensure-test() {
1297 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} && ! use test; then 1653 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \
1654 && hasq test ${IUSE} && ! use test;
1655 then
1298 eerror "You specified FEATURES=test, but USE=test is needed" 1656 eerror "You specified FEATURES=test, but USE=test is needed"
1299 eerror "to pull in the additional dependencies for testing" 1657 eerror "to pull in the additional dependencies for testing"
1300 die "Need USE=test enabled" 1658 die "Need USE=test enabled"
1301 fi 1659 fi
1302} 1660}
1303 1661
1304# ------------------------------------------------------------------------------ 1662# ------------------------------------------------------------------------------
1663# @ebuild-function java-pkg_register-ant-task
1664#
1665# Register this package as ant task, so that ant will load it when no specific
1666# ANT_TASKS are specified. Note that even without this registering, all packages
1667# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1668# packages, but can be also used by other ebuilds that used to symlink their
1669# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1670# compatibility.
1671#
1672# @param --version x.y Register only for ant version x.y (otherwise for any ant
1673# version). Used by the ant-* packages to prevent loading of mismatched
1674# ant-core ant tasks after core was updated, before the tasks are updated,
1675# without a need for blockers.
1676# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1677# ------------------------------------------------------------------------------
1678java-pkg_register-ant-task() {
1679 local TASKS_DIR="tasks"
1680
1681 # check for --version x.y parameters
1682 while [[ -n "${1}" && -n "${2}" ]]; do
1683 local var="${1#--}"
1684 local val="${2}"
1685 if [[ "${var}" == "version" ]]; then
1686 TASKS_DIR="tasks-${val}"
1687 else
1688 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1689 fi
1690 shift 2
1691 done
1692
1693 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1694
1695 dodir /usr/share/ant/${TASKS_DIR}
1696 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1697}
1698
1699# ------------------------------------------------------------------------------
1700# @internal-function java-pkg_ant-tasks-depend
1701#
1702# Translates the WANT_ANT_TASKS variable into valid dependencies.
1703# ------------------------------------------------------------------------------
1704java-pkg_ant-tasks-depend() {
1705 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1706
1707 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1708 local DEP=""
1709 for i in ${WANT_ANT_TASKS}
1710 do
1711 if [[ ${i} = ant-* ]]; then
1712 DEP="${DEP}dev-java/${i} "
1713 elif [[ ${i} = */*:* ]]; then
1714 DEP="${DEP}${i} "
1715 else
1716 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1717 return 1
1718 fi
1719 done
1720 echo ${DEP}
1721 return 0
1722 else
1723 return 0
1724 fi
1725}
1726
1727# ------------------------------------------------------------------------------
1728# @ebuild-function ejunit
1729#
1730# Junit wrapper function. Makes it easier to run the tests and checks for
1731# dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner.
1732#
1733# Examples:
1734# ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1735# ejunit org.blinkenlights.jid3.test.AllTests
1736#
1737# @param $1 - -cp or -classpath
1738# @param $2 - classpath; junit and recorded dependencies get appended
1739# @param $@ - the rest of the parameters are passed to java
1740# ------------------------------------------------------------------------------
1741ejunit() {
1742 debug-print-function ${FUNCNAME} $*
1743
1744 local pkgs
1745 if [[ -f ${JAVA_PKG_DEPEND_FILE} ]]; then
1746 for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
1747 pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
1748 done
1749 fi
1750
1751 local cp=$(java-pkg_getjars --with-dependencies junit${pkgs})
1752 if [[ ${1} = -cp || ${1} = -classpath ]]; then
1753 cp="${2}:${cp}"
1754 shift 2
1755 else
1756 cp=".:${cp}"
1757 fi
1758
1759 local runner=junit.textui.TestRunner
1760 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}"
1761 java -cp "${cp}" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
1762}
1763
1764# ------------------------------------------------------------------------------
1305# @section-end helper 1765# @section-end helper
1306# ------------------------------------------------------------------------------ 1766# ------------------------------------------------------------------------------
1767
1768# ------------------------------------------------------------------------------
1769# @eclass-src_prepare
1770#
1771# src_prepare Searches for bundled jars
1772# Don't call directly, but via java-pkg-2_src_prepare!
1773# ------------------------------------------------------------------------------
1774
1775java-utils-2_src_prepare() {
1776 [[ ${EBUILD_PHASE} == prepare ]] &&
1777 java-pkg_func-exists java_prepare && java_prepare
1778
1779 # Remember that eant will call this unless called via Portage
1780 if [[ ! -e "${T}/java-utils-2_src_prepare-run" ]] && is-java-strict; then
1781 echo "Searching for bundled jars:"
1782 java-pkg_find-normal-jars || echo "None found."
1783 echo "Searching for bundled classes (no output if none found):"
1784 find "${WORKDIR}" -name "*.class"
1785 echo "Search done."
1786 fi
1787 touch "${T}/java-utils-2_src_prepare-run"
1788}
1789
1790# ------------------------------------------------------------------------------
1791# @eclass-pkg_preinst
1792#
1793# pkg_preinst Searches for missing and unneeded dependencies
1794# Don't call directly, but via java-pkg-2_pkg_preinst!
1795# ------------------------------------------------------------------------------
1796
1797java-utils-2_pkg_preinst() {
1798 if is-java-strict; then
1799 if has_version dev-java/java-dep-check; then
1800 [[ -e "${JAVA_PKG_ENV}" ]] || return
1801 local output=$(GENTOO_VM= java-dep-check --image "${D}" "${JAVA_PKG_ENV}")
1802 if [[ ${output} && has_version <=dev-java/java-dep-check-0.2 ]]; then
1803 ewarn "Possibly unneeded dependencies found in package.env:"
1804 for dep in ${output}; do
1805 ewarn "\t${dep}"
1806 done
1807 fi
1808 if [[ ${output} && has_version >dev-java/java-dep-check-0.2 ]]; then
1809 ewarn "${output}"
1810 fi
1811 else
1812 eerror "Install dev-java/java-dep-check for dependency checking"
1813 fi
1814 fi
1815}
1307 1816
1308# ------------------------------------------------------------------------------ 1817# ------------------------------------------------------------------------------
1309# @section-begin build 1818# @section-begin build
1310# @section-summary Build functions 1819# @section-summary Build functions
1311# 1820#
1315 1824
1316# ------------------------------------------------------------------------------ 1825# ------------------------------------------------------------------------------
1317# @ebuild-function eant 1826# @ebuild-function eant
1318# 1827#
1319# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1828# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1320# compiler. 1829# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1321# 1830# variables:
1831# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1832# gentoo.classpath property. Be sure to call
1833# java-ant_rewrite-classpath in src_unpack.
1834# EANT_NEEDS_TOOLS - add tools.jar to the gentoo.classpath. Should only be used
1835# for build-time purposes, the dependency is not recorded to
1836# package.env!
1837# JAVA_PKG_NO_BUNDLED_SEARCH - Don't search for bundled jars or class files
1838# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1322# ------------------------------------------------------------------------------ 1839# ------------------------------------------------------------------------------
1323eant() { 1840eant() {
1324 debug-print-function ${FUNCNAME} $* 1841 debug-print-function ${FUNCNAME} $*
1325 1842
1326 # FIXME get this working 1843 if [[ ${EBUILD_PHASE} = compile ]]; then
1327# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then 1844 java-ant-2_src_configure
1845 java-utils-2_src_prepare
1846 fi
1847
1848 if ! hasq java-ant-2 ${INHERITED}; then
1849 local msg="You should inherit java-ant-2 when using eant"
1328# java-pkg_announce-qa-violation \ 1850 java-pkg_announce-qa-violation "${msg}"
1329# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1330# fi 1851 fi
1331 1852
1332 local antflags 1853 local antflags="-Dnoget=true -Dmaven.mode.offline=true -Dbuild.sysclasspath=ignore"
1854
1333 java-pkg_init-compiler_ 1855 java-pkg_init-compiler_
1334 local compiler="${GENTOO_COMPILER}" 1856 local compiler="${GENTOO_COMPILER}"
1335 1857
1336 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1858 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})" 1859 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})"
1339 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1860 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1340 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1861 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1341 fi 1862 fi
1342 1863
1343 if [[ ${compiler} != "javac" ]]; then 1864 if [[ ${compiler} != "javac" ]]; then
1344 antflags="-Dbuild.compiler=${build_compiler}" 1865 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1345 # Figure out any extra stuff to put on the classpath for compilers aside 1866 # Figure out any extra stuff to put on the classpath for compilers aside
1346 # from javac 1867 # from javac
1347 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to 1868 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1348 # java-config -p 1869 # java-config -p
1349 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1870 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 1871 if [[ -n ${build_compiler_deps} ]]; then
1351 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})" 1872 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1352 fi 1873 fi
1353 fi 1874 fi
1354 1875
1876 for arg in "${@}"; do
1877 if [[ ${arg} = -lib ]]; then
1355 if is-java-strict; then 1878 if is-java-strict; then
1356 einfo "Disabling system classpath for ant" 1879 eerror "You should not use the -lib argument to eant because it will fail"
1357 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1880 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1881 eerror "or ant properties to make dependencies available."
1882 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1883 eerror "split ant (>=dev-java/ant-core-1.7)."
1884 die "eant -lib is deprecated/forbidden"
1885 else
1886 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1887 echo "more info."
1888 fi
1358 fi 1889 fi
1890 done
1359 1891
1360 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1892 # parse WANT_ANT_TASKS for atoms
1361 antflags="${antflags} -debug" 1893 local want_ant_tasks
1894 for i in ${WANT_ANT_TASKS}; do
1895 if [[ ${i} = */*:* ]]; then
1896 i=${i#*/}
1897 i=${i%:0}
1898 want_ant_tasks+="${i/:/-} "
1899 else
1900 want_ant_tasks+="${i} "
1901 fi
1902 done
1903 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1904 ANT_TASKS="${ANT_TASKS:-${want_ant_tasks% }}"
1905
1906 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1907 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1908
1909 # if ant-tasks is not set by ebuild or forced, use none
1910 ANT_TASKS="${ANT_TASKS:-none}"
1911
1912 # at this point, ANT_TASKS should be "all", "none" or explicit list
1913 if [[ "${ANT_TASKS}" == "all" ]]; then
1914 einfo "Using all available ANT_TASKS"
1915 elif [[ "${ANT_TASKS}" == "none" ]]; then
1916 einfo "Disabling all optional ANT_TASKS"
1917 else
1918 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1919 fi
1920
1921 export ANT_TASKS
1922
1923 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1924 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1925
1926 local gcp="${EANT_GENTOO_CLASSPATH}"
1927 local getjarsarg=""
1928
1929 if [[ ${EBUILD_PHASE} = "test" ]]; then
1930 antflags="${antflags} -DJunit.present=true"
1931 [[ ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1932 getjarsarg="--with-dependencies"
1933 fi
1934
1935 local cp
1936
1937 for atom in ${gcp}; do
1938 cp="${cp}:$(java-pkg_getjars ${getjarsarg} ${atom})"
1939 done
1940
1941 [[ -n "${EANT_NEEDS_TOOLS}" ]] && cp="${cp}:$(java-config --tools)"
1942
1943 if [[ ${cp} ]]; then
1944 # It seems ant does not like single quotes around ${cp}
1945 cp=${cp#:}
1946 [[ ${EANT_GENTOO_CLASSPATH_EXTRA} ]] && \
1947 cp="${cp}:${EANT_GENTOO_CLASSPATH_EXTRA}"
1948 antflags="${antflags} -Dgentoo.classpath=\"${cp}\""
1362 fi 1949 fi
1363 1950
1364 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1951 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1952 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
1365 ant ${antflags} "${@}" || die "eant failed" 1953 ant ${antflags} "${@}" || die "eant failed"
1366
1367} 1954}
1368 1955
1369# ------------------------------------------------------------------------------ 1956# ------------------------------------------------------------------------------
1370# @ebuild-function ejavac 1957# @ebuild-function ejavac
1371# 1958#
1440# ------------------------------------------------------------------------------ 2027# ------------------------------------------------------------------------------
1441use_doc() { 2028use_doc() {
1442 use doc && echo ${@:-javadoc} 2029 use doc && echo ${@:-javadoc}
1443} 2030}
1444 2031
2032
1445# ------------------------------------------------------------------------------ 2033# ------------------------------------------------------------------------------
1446# @section-end build 2034# @section-end build
1447# ------------------------------------------------------------------------------ 2035# ------------------------------------------------------------------------------
1448 2036
1449# ------------------------------------------------------------------------------ 2037# ------------------------------------------------------------------------------
1465# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will 2053# 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. 2054# call it during each of the phases of the merge process.
1467# 2055#
1468# ----------------------------------------------------------------------------- 2056# -----------------------------------------------------------------------------
1469java-pkg_init() { 2057java-pkg_init() {
2058 debug-print-function ${FUNCNAME} $*
1470 unset JAVAC 2059 unset JAVAC
1471 unset JAVA_HOME 2060 unset JAVA_HOME
2061
2062 java-config --help >/dev/null || {
2063 eerror ""
2064 eerror "Can't run java-config --help"
2065 eerror "Have you upgraded python recently but haven't"
2066 eerror "run python-updater yet?"
2067 die "Can't run java-config --help"
2068 }
2069
2070 # People do all kinds of weird things.
2071 # http://forums.gentoo.org/viewtopic-p-3943166.html
2072 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
2073 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
2074 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
2075 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
2076 ewarn "sun-jdk vms and and as such break configure scripts that"
2077 ewarn "use it (for example app-office/openoffice) so we filter it out."
2078 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
2079 ewarn "make.conf for example) to silence this warning or"
2080 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
2081 fi
2082
2083 if [[ -z ${accept} ]]; then
2084 # export _JAVA_OPTIONS= doesn't work because it will show up in java
2085 # -version output
2086 unset _JAVA_OPTIONS
2087 # phase hooks make this run many times without this
2088 I_WANT_GLOBAL_JAVA_OPTIONS="true"
2089 fi
2090
2091 if java-pkg_func-exists ant_src_unpack; then
2092 java-pkg_announce-qa-violation "Using old ant_src_unpack. Should be src_unpack"
2093 fi
2094
1472 java-pkg_init_paths_ 2095 java-pkg_init_paths_
1473 java-pkg_switch-vm 2096 java-pkg_switch-vm
1474 PATH=${JAVA_HOME}/bin:${PATH} 2097 PATH=${JAVA_HOME}/bin:${PATH}
1475 2098
1476 # TODO we will probably want to set JAVAC and JAVACFLAGS 2099 # TODO we will probably want to set JAVAC and JAVACFLAGS
1477 2100
1478 # Do some QA checks 2101 # Do some QA checks
1479 java-pkg_check-jikes 2102 java-pkg_check-jikes
2103
2104 # Can't use unset here because Portage does not save the unset
2105 # see https://bugs.gentoo.org/show_bug.cgi?id=189417#c11
1480 2106
1481 # When users have crazy classpaths some packages can fail to compile. 2107 # When users have crazy classpaths some packages can fail to compile.
1482 # and everything should work with empty CLASSPATH. 2108 # and everything should work with empty CLASSPATH.
1483 # This also helps prevent unexpected dependencies on random things 2109 # This also helps prevent unexpected dependencies on random things
1484 # from the CLASSPATH. 2110 # from the CLASSPATH.
1485 unset CLASSPATH 2111 export CLASSPATH=
2112
2113 # Unset external ANT_ stuff
2114 export ANT_TASKS=
2115 export ANT_OPTS=
2116 export ANT_RESPECT_JAVA_HOME=
1486} 2117}
1487 2118
1488# ------------------------------------------------------------------------------ 2119# ------------------------------------------------------------------------------
1489# @function-internal java-pkg-init-compiler_ 2120# @function-internal java-pkg-init-compiler_
1490# 2121#
1581 done 2212 done
1582 2213
1583 # If it hasn't been defined already, default to javac 2214 # If it hasn't been defined already, default to javac
1584 if [[ -z ${GENTOO_COMPILER} ]]; then 2215 if [[ -z ${GENTOO_COMPILER} ]]; then
1585 if [[ -n ${compilers} ]]; then 2216 if [[ -n ${compilers} ]]; then
1586 einfo "No suitable compiler found: defaulting javac for compilation" 2217 einfo "No suitable compiler found: defaulting to JDK default for compilation"
1587 else 2218 else
1588 # probably don't need to notify users about the default. 2219 # probably don't need to notify users about the default.
1589 :;#einfo "Defaulting to javac for compilation" 2220 :;#einfo "Defaulting to javac for compilation"
1590 fi 2221 fi
2222 if java-config -g GENTOO_COMPILER 2> /dev/null; then
2223 export GENTOO_COMPILER=$(java-config -g GENTOO_COMPILER)
2224 else
1591 export GENTOO_COMPILER=javac 2225 export GENTOO_COMPILER=javac
2226 fi
1592 else 2227 else
1593 einfo "Using ${GENTOO_COMPILER} for compilation" 2228 einfo "Using ${GENTOO_COMPILER} for compilation"
1594 fi 2229 fi
1595 2230
1596} 2231}
1612 fi 2247 fi
1613 2248
1614 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}" 2249 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}"
1615 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/" 2250 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/"
1616 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env" 2251 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env"
2252 JAVA_PKG_VIRTUALS_PATH="${DESTTREE}/share/java-config-2/virtuals"
2253 JAVA_PKG_VIRTUAL_PROVIDER="${D}/${JAVA_PKG_VIRTUALS_PATH}/${JAVA_PKG_NAME}"
1617 2254
1618 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib" 2255 [[ -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}" 2256 [[ -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" 2257 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps"
1621 2258
1634# Writes the package.env out to disk. 2271# Writes the package.env out to disk.
1635# 2272#
1636# ------------------------------------------------------------------------------ 2273# ------------------------------------------------------------------------------
1637# TODO change to do-write, to match everything else 2274# TODO change to do-write, to match everything else
1638java-pkg_do_write_() { 2275java-pkg_do_write_() {
2276 debug-print-function ${FUNCNAME} $*
1639 java-pkg_init_paths_ 2277 java-pkg_init_paths_
1640 # Create directory for package.env 2278 # Create directory for package.env
1641 dodir "${JAVA_PKG_SHAREPATH}" 2279 dodir "${JAVA_PKG_SHAREPATH}"
1642 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 2280 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f \
2281 "${JAVA_PKG_DEPEND_FILE}" || -f \
2282 "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]]; then
1643 # Create package.env 2283 # Create package.env
1644 ( 2284 (
1645 echo "DESCRIPTION=\"${DESCRIPTION}\"" 2285 echo "DESCRIPTION=\"${DESCRIPTION}\""
1646 echo "GENERATION=\"2\"" 2286 echo "GENERATION=\"2\""
2287 echo "SLOT=\"${SLOT}\""
2288 echo "CATEGORY=\"${CATEGORY}\""
2289 echo "PVR=\"${PVR}\""
1647 2290
1648 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\"" 2291 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
1649 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 2292 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1650 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 2293 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1651 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 2294 [[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
2295 && echo "DEPEND=\"$(cat "${JAVA_PKG_DEPEND_FILE}" | uniq | tr '\n' ':')\""
2296 [[ -f "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]] \
2297 && 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 ! 2298 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
2299 [[ -f "${JAVA_PKG_BUILD_DEPEND_FILE}" ]] \
2300 && echo "BUILD_DEPEND=\"$(cat "${JAVA_PKG_BUILD_DEPEND_FILE}" | uniq | tr '\n' ':')\""
1653 ) > "${JAVA_PKG_ENV}" 2301 ) > "${JAVA_PKG_ENV}"
1654 2302
1655 # register target/source 2303 # register target/source
1656 local target="$(java-pkg_get-target)" 2304 local target="$(java-pkg_get-target)"
1657 local source="$(java-pkg_get-source)" 2305 local source="$(java-pkg_get-source)"
1667 2315
1668 2316
1669 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}" 2317 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
1670 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}" 2318 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
1671 2319
2320 # extra env variables
2321 if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
2322 cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}" || die
2323 # nested echo to remove leading/trailing spaces
2324 echo "ENV_VARS=\"$(echo ${JAVA_PKG_EXTRA_ENV_VARS})\"" \
2325 >> "${JAVA_PKG_ENV}" || die
2326 fi
2327
1672 # Strip unnecessary leading and trailing colons 2328 # Strip unnecessary leading and trailing colons
1673 # TODO try to cleanup if possible 2329 # TODO try to cleanup if possible
1674 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 2330 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
2331 else
2332 debug-print "JAVA_PKG_CLASSPATH, JAVA_PKG_LIBRARY, JAVA_PKG_DEPEND_FILE"
2333 debug-print "or JAVA_PKG_OPTIONAL_DEPEND_FILE not defined so can't"
2334 debug-print "write package.env."
1675 fi 2335 fi
1676} 2336}
1677 2337
1678# ------------------------------------------------------------------------------ 2338# ------------------------------------------------------------------------------
1679# @internal-function java-pkg_record-jar_ 2339# @internal-function java-pkg_record-jar_
1680# 2340#
1681# Record a dependency to the package.env 2341# Record an (optional) dependency to the package.env
1682# 2342# @param --optional - record dependency as optional
2343# @param --build - record dependency as build_only
2344# @param $1 - package to record
2345# @param $2 - (optional) jar of package to record
1683# ------------------------------------------------------------------------------ 2346# ------------------------------------------------------------------------------
1684JAVA_PKG_DEPEND="${T}/java-pkg-depend" 2347JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2348JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
2349JAVA_PKG_BUILD_DEPEND_FILE="${T}/java-pkg-build-depend"
1685 2350
1686java-pkg_record-jar_() { 2351java-pkg_record-jar_() {
1687 debug-print-function ${FUNCNAME} $* 2352 debug-print-function ${FUNCNAME} $*
2353
2354 local depend_file="${JAVA_PKG_DEPEND_FILE}"
2355 case "${1}" in
2356 "--optional") depend_file="${JAVA_PKG_OPTIONAL_DEPEND_FILE}"; shift;;
2357 "--build-only") depend_file="${JAVA_PKG_BUILD_DEPEND_FILE}"; shift;;
2358 esac
1688 2359
1689 local pkg=${1} jar=${2} append 2360 local pkg=${1} jar=${2} append
1690 if [[ -z "${jar}" ]]; then 2361 if [[ -z "${jar}" ]]; then
1691 append="${pkg}" 2362 append="${pkg}"
1692 else 2363 else
1693 append="$(basename ${jar})@${pkg}" 2364 append="$(basename ${jar})@${pkg}"
1694 fi 2365 fi
1695 2366
1696 echo ${append} >> ${JAVA_PKG_DEPEND} 2367 echo "${append}" >> "${depend_file}"
1697} 2368}
1698 2369
1699# ------------------------------------------------------------------------------ 2370# ------------------------------------------------------------------------------
1700# @internal-function java-pkg_append_ 2371# @internal-function java-pkg_append_
1701# 2372#
1745# 2416#
1746# @return 0 - function is declared 2417# @return 0 - function is declared
1747# @return 1 - function is undeclared 2418# @return 1 - function is undeclared
1748# ------------------------------------------------------------------------------ 2419# ------------------------------------------------------------------------------
1749java-pkg_func-exists() { 2420java-pkg_func-exists() {
1750 if [[ -n "$(declare -f ${1})" ]]; then 2421 declare -F ${1} > /dev/null
1751 return 0
1752 else
1753 return 1
1754 fi
1755} 2422}
1756 2423
1757# ------------------------------------------------------------------------------ 2424# ------------------------------------------------------------------------------
1758# @internal-function java-pkg_setup-vm 2425# @internal-function java-pkg_setup-vm
1759# 2426#
1760# Sets up the environment for a specific VM 2427# Sets up the environment for a specific VM
1761# 2428#
1762# ------------------------------------------------------------------------------ 2429# ------------------------------------------------------------------------------
1763java-pkg_setup-vm() { 2430java-pkg_setup-vm() {
1764 debug-print-function ${FUNCNAME} $* 2431 debug-print-function ${FUNCNAME} $*
2432
2433 export LANG="C" LC_ALL="C"
1765 2434
1766 local vendor="$(java-pkg_get-vm-vendor)" 2435 local vendor="$(java-pkg_get-vm-vendor)"
1767 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then 2436 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1768 addpredict "/dev/random" 2437 addpredict "/dev/random"
1769 elif [[ "${vendor}" == "ibm" ]]; then 2438 elif [[ "${vendor}" == "ibm" ]]; then
1770 addpredict "/proc/self/maps" 2439 addpredict "/proc/self/maps"
1771 addpredict "/proc/cpuinfo" 2440 addpredict "/proc/cpuinfo"
1772 export LANG="C" LC_ALL="C"
1773 elif [[ "${vendor}" == "jrockit" ]]; then 2441 elif [[ "${vendor}" == "jrockit" ]]; then
1774 addpredict "/proc/cpuinfo" 2442 addpredict "/proc/cpuinfo"
1775 fi 2443 fi
1776} 2444}
1777 2445
1832# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 2500# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1833# verify that the current VM is sufficient. 2501# verify that the current VM is sufficient.
1834# Setup the environment for the VM being used. 2502# Setup the environment for the VM being used.
1835# ------------------------------------------------------------------------------ 2503# ------------------------------------------------------------------------------
1836java-pkg_switch-vm() { 2504java-pkg_switch-vm() {
2505 debug-print-function ${FUNCNAME} $*
2506
1837 if java-pkg_needs-vm; then 2507 if java-pkg_needs-vm; then
1838 # Use the VM specified by JAVA_PKG_FORCE_VM 2508 # Use the VM specified by JAVA_PKG_FORCE_VM
1839 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then 2509 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1840 # If you're forcing the VM, I hope you know what your doing... 2510 # If you're forcing the VM, I hope you know what your doing...
2511 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1841 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 2512 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1842 # if we're allowed to switch the vm... 2513 # if we're allowed to switch the vm...
1843 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 2514 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}" 2515 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
1845 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1846 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1847 else
1848 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2516 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1849 fi
1850 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then 2517 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
1851 eerror "Unable to determine VM for building from dependencies:" 2518 eerror "Unable to determine VM for building from dependencies:"
1852 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}" 2519 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
1853 echo "VNEED: ${JAVA_PKG_VNEED}"
1854 die "Failed to determine VM for building." 2520 die "Failed to determine VM for building."
1855 else 2521 else
1856 export GENTOO_VM 2522 export GENTOO_VM
1857 fi 2523 fi
1858 # otherwise just make sure the current VM is sufficient 2524 # otherwise just make sure the current VM is sufficient
1878 2544
1879 #TODO If you know a better solution let us know. 2545 #TODO If you know a better solution let us know.
1880 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 2546 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1881 2547
1882 local tann="${T}/announced-vm" 2548 local tann="${T}/announced-vm"
2549 # With the hooks we should only get here once from pkg_setup but better safe than sorry
2550 # if people have for example modified eclasses some where
1883 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 2551 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)" 2552 einfo "Using: $(java-config -f)"
1889 [[ ! -f "${tann}" ]] && touch "${tann}" 2553 [[ ! -f "${tann}" ]] && touch "${tann}"
1890 fi
1891 fi 2554 fi
1892 2555
1893 else 2556 else
1894 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!" 2557 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!"
1895 fi 2558 fi
1925 einfo "Classes" 2588 einfo "Classes"
1926 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR}," 2589 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1927 fi 2590 fi
1928} 2591}
1929 2592
1930# TODO document 2593# ------------------------------------------------------------------------------
2594# @internal-function java-pkg_verify-classes
2595#
1931# Verify that the classes were compiled for the right source / target 2596# Verify that the classes were compiled for the right source / target. Dies if
2597# not.
2598# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2599# ------------------------------------------------------------------------------
1932java-pkg_verify-classes() { 2600java-pkg_verify-classes() {
1933 ebegin "Verifying java class versions"
1934 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 2601 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1935 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 2602
2603 local version_verify="/usr/bin/class-version-verify.py"
2604
2605 if [[ ! -x "${version_verify}" ]]; then
2606 version_verify="/usr/$(get_libdir)/javatoolkit/bin/class-version-verify.py"
2607 fi
2608
2609 if [[ ! -x "${version_verify}" ]]; then
2610 ewarn "Unable to perform class version checks as"
2611 ewarn "class-version-verify.py is unavailable"
2612 ewarn "Please install dev-java/javatoolkit."
2613 return
2614 fi
2615
2616 local target=$(java-pkg_get-target)
2617 local result
2618 local log="${T}/class-version-verify.log"
2619 if [[ -n "${1}" ]]; then
2620 ${version_verify} -v -t ${target} "${1}" > "${log}"
1936 result=$? 2621 result=$?
1937 eend ${result}
1938 if [[ ${result} == 0 ]]; then
1939 einfo "All good"
1940 else 2622 else
1941 ewarn "Possible problem" 2623 ebegin "Verifying java class versions (target: ${target})"
1942 die "Bad class files found" 2624 ${version_verify} -v -t ${target} -r "${D}" > "${log}"
2625 result=$?
2626 eend ${result}
2627 fi
2628 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2629 if [[ ${result} != 0 ]]; then
2630 eerror "Incorrect bytecode version found"
2631 [[ -n "${1}" ]] && eerror "in file: ${1}"
2632 eerror "See ${log} for more details."
2633 die "Incorrect bytecode found"
2634 fi
2635}
2636
2637# ----------------------------------------------------------------------------
2638# @internal-function java-pkg_ensure-dep
2639# Check that a package being used in jarfrom, getjars and getjar is contained
2640# within DEPEND or RDEPEND.
2641# @param $1 - empty - check both vars; "runtime" or "build" - check only
2642# RDEPEND, resp. DEPEND
2643# @param $2 - Package name and slot.
2644
2645java-pkg_ensure-dep() {
2646 debug-print-function ${FUNCNAME} $*
2647
2648 local limit_to="${1}"
2649 local target_pkg="${2}"
2650 local dev_error=""
2651
2652 local stripped_pkg=$(echo "${target_pkg}" | sed \
2653 's/-[0-9]*\(\.[0-9]\)*$//')
2654
2655 debug-print "Matching against: ${stripped_pkg}"
2656
2657 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2658 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2659 dev_error="${dev_error} declared in DEPEND."
2660 if is-java-strict; then
2661 eerror "${dev_error}"
2662 die "${dev_error}"
2663 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2664 eerror "${dev_error}"
2665 elog "Because you have this package installed the package will"
2666 elog "build without problems, but please report this to"
2667 elog "http://bugs.gentoo.org"
2668 fi
2669 fi
2670
2671 if [[ ${limit_to} != build ]]; then
2672 if [[ ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2673 if [[ ! ( ${PDEPEND} =~ "${stripped_pkg}" ) ]]; then
2674 dev_error="The ebuild is attempting to use ${target_pkg},"
2675 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND"
2676 dev_error="${dev_error} or PDEPEND."
2677 if is-java-strict; then
2678 eerror "${dev_error}"
2679 die "${dev_error}"
2680 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2681 eerror "${dev_error}"
2682 elog "The package will build without problems, but may fail to run"
2683 elog "if you don't have ${target_pkg} installed, so please report"
2684 elog "this to http://bugs.gentoo.org"
2685 fi
2686 fi
2687 fi
1943 fi 2688 fi
1944} 2689}
1945 2690
1946# ------------------------------------------------------------------------------ 2691# ------------------------------------------------------------------------------
1947# @section-end internal 2692# @section-end internal
1948# ------------------------------------------------------------------------------ 2693# ------------------------------------------------------------------------------
1949 2694
1950java-pkg_check-phase() { 2695java-pkg_check-phase() {
1951 local phase=${1} 2696 local phase=${1}
1952 local funcname=${2} 2697 local funcname=${FUNCNAME[1]}
1953 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then 2698 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
1954 java-pkg_announce-qa-violation \
1955 "${funcname} used outside of src_${phase}" 2699 local msg="${funcname} used outside of src_${phase}"
2700 java-pkg_announce-qa-violation "${msg}"
1956 fi 2701 fi
1957} 2702}
1958 2703
1959java-pkg_check-versioned-jar() { 2704java-pkg_check-versioned-jar() {
1960 local jar=${1} 2705 local jar=${1}
1969 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2714 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1970 fi 2715 fi
1971} 2716}
1972 2717
1973java-pkg_announce-qa-violation() { 2718java-pkg_announce-qa-violation() {
1974 if is-java-strict; then 2719 local nodie
2720 if [[ ${1} == "--nodie" ]]; then
2721 nodie="true"
2722 shift
2723 fi
1975 echo "Java QA Notice: $@" >&2 2724 echo "Java QA Notice: $@" >&2
1976 increment-qa-violations 2725 increment-qa-violations
1977 fi 2726 [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
1978} 2727}
1979 2728
1980increment-qa-violations() { 2729increment-qa-violations() {
1981 let "JAVA_PKG_QA_VIOLATIONS+=1" 2730 let "JAVA_PKG_QA_VIOLATIONS+=1"
1982 export JAVA_PKG_QA_VIOLATIONS 2731 export JAVA_PKG_QA_VIOLATIONS
1985is-java-strict() { 2734is-java-strict() {
1986 [[ -n ${JAVA_PKG_STRICT} ]] 2735 [[ -n ${JAVA_PKG_STRICT} ]]
1987 return $? 2736 return $?
1988} 2737}
1989 2738
2739
1990# ------------------------------------------------------------------------------ 2740# ------------------------------------------------------------------------------
1991# @eclass-end 2741# @eclass-end
1992# ------------------------------------------------------------------------------ 2742# ------------------------------------------------------------------------------

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

  ViewVC Help
Powered by ViewVC 1.1.20