/[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.3 Revision 1.40
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.40 2007/01/10 09:52:51 betelgeuse Exp $
9 10
10 11
11# ----------------------------------------------------------------------------- 12# -----------------------------------------------------------------------------
12# @eclass-begin 13# @eclass-begin
13# @eclass-shortdesc Java Utility eclass 14# @eclass-shortdesc Java Utility eclass
14# @eclass-maintainer java@gentoo.org 15# @eclass-maintainer java@gentoo.org
15# 16#
16# This eclass provides functionality which is used by 17# This eclass provides functionality which is used by
17# java-pkg.eclass and java-pkg-opt.eclass as well as from ebuilds. 18# java-pkg.eclass and java-pkg-opt.eclass as well as from ebuilds.
18# 19#
19# @warning 20# @warning
20# You probably don't want to inherit this directly from an ebuild. Instead, 21# You probably don't want to inherit this directly from an ebuild. Instead,
21# you should inherit java-ant for Ant-based Java packages, java-pkg for other 22# you should inherit java-ant for Ant-based Java packages, java-pkg for other
22# Java packages, or java-pkg-opt for packages that have optional Java support. 23# Java packages, or java-pkg-opt for packages that have optional Java support.
23# 24#
24# ----------------------------------------------------------------------------- 25# -----------------------------------------------------------------------------
25 26
26inherit eutils versionator multilib 27inherit eutils versionator multilib
28
29IUSE="elibc_FreeBSD"
27 30
28# ----------------------------------------------------------------------------- 31# -----------------------------------------------------------------------------
29# @section-begin variables 32# @section-begin variables
30# @section-title Variables 33# @section-title Variables
31# 34#
33# ----------------------------------------------------------------------------- 36# -----------------------------------------------------------------------------
34 37
35# Make sure we use java-config-2 38# Make sure we use java-config-2
36export WANT_JAVA_CONFIG="2" 39export WANT_JAVA_CONFIG="2"
37 40
41# TODO document
42JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1"
43
38# ----------------------------------------------------------------------------- 44# -----------------------------------------------------------------------------
39# @variable-internal JAVA_PKG_E_DEPEND 45# @variable-internal JAVA_PKG_E_DEPEND
40# 46#
41# This is a convience variable to be used from the other java eclasses. This is 47# This is a convience variable to be used from the other java eclasses. This is
42# the version of java-config we want to use. We also need a recent version 48# the version of java-config we want to use. We also need a recent version
43# portage, that includes phase hooks. 49# portage, that includes phase hooks.
44# ----------------------------------------------------------------------------- 50# -----------------------------------------------------------------------------
45JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 >=sys-apps/portage-2.1_pre1" 51JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 ${JAVA_PKG_PORTAGE_DEP}"
46 52
47# ----------------------------------------------------------------------------- 53# -----------------------------------------------------------------------------
48# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 54# @variable-external JAVA_PKG_ALLOW_VM_CHANGE
49# @variable-default yes 55# @variable-default yes
50# 56#
97# ----------------------------------------------------------------------------- 103# -----------------------------------------------------------------------------
98 104
99# ----------------------------------------------------------------------------- 105# -----------------------------------------------------------------------------
100# @variable-internal JAVA_PKG_COMPILER_DIR 106# @variable-internal JAVA_PKG_COMPILER_DIR
101# @default /usr/share/java-config-2/compiler 107# @default /usr/share/java-config-2/compiler
102# 108#
103# Directory where compiler settings are saved, without trailing slash. 109# Directory where compiler settings are saved, without trailing slash.
104# Probably shouldn't touch this variable. 110# Probably shouldn't touch this variable.
105# ----------------------------------------------------------------------------- 111# -----------------------------------------------------------------------------
106JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"} 112JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"}
107 113
117 123
118# ----------------------------------------------------------------------------- 124# -----------------------------------------------------------------------------
119# @variable-external JAVA_PKG_FORCE_COMPILER 125# @variable-external JAVA_PKG_FORCE_COMPILER
120# 126#
121# Explicitly set a list of compilers to use. This is normally read from 127# Explicitly set a list of compilers to use. This is normally read from
122# JAVA_PKG_COMPILERS_CONF. 128# JAVA_PKG_COMPILERS_CONF.
123# 129#
124# @note This should only be used internally or for testing. 130# @note This should only be used internally or for testing.
125# @example Use jikes and javac, in that order 131# @example Use jikes and javac, in that order
126# JAVA_PKG_FORCE_COMPILER="jikes javac" 132# JAVA_PKG_FORCE_COMPILER="jikes javac"
127# ----------------------------------------------------------------------------- 133# -----------------------------------------------------------------------------
147# @ebuild-function java-pkg_dojar 153# @ebuild-function java-pkg_dojar
148# 154#
149# Installs any number of jars. 155# Installs any number of jars.
150# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default. 156# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default.
151# You can use java-pkg_jarinto to change this path. 157# You can use java-pkg_jarinto to change this path.
152# You should never install a jar with a package version in the filename. 158# You should never install a jar with a package version in the filename.
153# Instead, use java-pkg_newjar defined below. 159# Instead, use java-pkg_newjar defined below.
154# 160#
155# @example 161# @example
156# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar 162# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar
157# 163#
168 # Create JARDEST if it doesn't exist 174 # Create JARDEST if it doesn't exist
169 dodir ${JAVA_PKG_JARDEST} 175 dodir ${JAVA_PKG_JARDEST}
170 176
171 local jar 177 local jar
172 # for each jar 178 # for each jar
173 for jar in "$@"; do 179 for jar in ${@}; do
174 local jar_basename=$(basename "${jar}") 180 local jar_basename=$(basename "${jar}")
175 181
176 java-pkg_check-versioned-jar ${jar_basename} 182 java-pkg_check-versioned-jar ${jar_basename}
177 183
178 # check if it exists 184 # check if it exists
197 203
198 java-pkg_do_write_ 204 java-pkg_do_write_
199} 205}
200 206
201 207
208# ------------------------------------------------------------------------------
209# @internal-function depend-java-query
210#
211# 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
213# do not handle use flags.
214# ------------------------------------------------------------------------------
215
216depend-java-query() {
217 USE="${USE}" $(which depend-java-query) "${@}"
218}
202 219
203# ------------------------------------------------------------------------------ 220# ------------------------------------------------------------------------------
204# @ebuild-function java-pkg_regjar 221# @ebuild-function java-pkg_regjar
205# 222#
206# Records an already installed jar in the package.env 223# Records an already installed jar in the package.env
207# This would mostly be used if the package has make or a custom script to 224# This would mostly be used if the package has make or a custom script to
208# install things. 225# install things.
209# 226#
210# Example: 227# Example:
211# java-pkg-regjar ${D}/opt/foo/lib/foo.jar 228# java-pkg_regjar ${D}/opt/foo/lib/foo.jar
229#
230# WARNING:
231# if you want to use shell expansion, you have to use ${D}/... as the for in
232# this function will not be able to expand the path, here's an example:
233#
234# java-pkg_regjar /opt/my-java/lib/*.jar
235#
236# will not work, because:
237# * the `for jar in "$@"` can't expand the path to jar file names, as they
238# don't exist yet
239# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar'
240# doesn't exist
241#
242# you have to use it as:
243#
244# java-pkg_regjar ${D}/opt/my-java/lib/*.jar
212# 245#
213# @param $@ - jars to record 246# @param $@ - jars to record
214# ------------------------------------------------------------------------------ 247# ------------------------------------------------------------------------------
215# TODO fix me! 248# TODO should we be making sure the jar is present on ${D} or wherever?
216java-pkg_regjar() { 249java-pkg_regjar() {
217 debug-print-function ${FUNCNAME} $* 250 debug-print-function ${FUNCNAME} $*
218 251
219 java-pkg_check-phase install 252 java-pkg_check-phase install
220 253
221 [[ ${#} -lt 1 ]] && die "at least one argument needed" 254 [[ ${#} -lt 1 ]] && die "at least one argument needed"
222 255
223 java-pkg_init_paths_ 256 java-pkg_init_paths_
224 257
225 local jar jar_dir jar_file 258 local jar jar_dir jar_file
226 for jar in "$@"; do 259 for jar in ${@}; do
227 # TODO use java-pkg_check-versioned-jar 260 # TODO use java-pkg_check-versioned-jar
228 if [[ -e "${jar}" ]]; then
229 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar}"
230 elif [[ -e "${D}${jar}" ]]; then 261 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
262 [[ -d "${jar}" || -d "${D}${jar}" ]] \
263 && die "Called ${FUNCNAME} on a directory $*"
264 # nelchael: we should strip ${D} in this case too, here's why:
265 # imagine such call:
266 # java-pkg_regjar ${D}/opt/java/*.jar
267 # such call will fall into this case (-e ${jar}) and will
268 # record paths with ${D} in package.env
231 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 269 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
232 else 270 else
233 die "${jar} does not exist" 271 die "${jar} does not exist"
234 fi 272 fi
235 done 273 done
236 274
237 java-pkg_do_write_ 275 java-pkg_do_write_
238} 276}
239 277
240
241# ------------------------------------------------------------------------------ 278# ------------------------------------------------------------------------------
242# @ebuild-function java-pkg_newjar 279# @ebuild-function java-pkg_newjar
243# 280#
244# Installs a jar with a new name 281# Installs a jar with a new name
245# 282#
255 local original_jar="${1}" 292 local original_jar="${1}"
256 local new_jar="${2:-${PN}.jar}" 293 local new_jar="${2:-${PN}.jar}"
257 local new_jar_dest="${T}/${new_jar}" 294 local new_jar_dest="${T}/${new_jar}"
258 295
259 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 296 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
260 [[ ! -f ${original_jar} ]] && die "${new_jar} does not exist!" 297 [[ ! -f ${original_jar} ]] && die "${original_jar} does not exist!"
261 298
262 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 299 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
263 cp "${original_jar}" "${new_jar_dest}" \ 300 cp "${original_jar}" "${new_jar_dest}" \
264 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 301 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
265 java-pkg_dojar "${new_jar_dest}" 302 java-pkg_dojar "${new_jar_dest}"
266} 303}
267 304
268
269# ------------------------------------------------------------------------------ 305# ------------------------------------------------------------------------------
270# @ebuild-function java-pkg_addcp 306# @ebuild-function java-pkg_addcp
271# 307#
272# Add something to the package's classpath. For jars, you should use dojar, 308# Add something to the package's classpath. For jars, you should use dojar,
273# newjar, or regjar. This is typically used to add directories to the classpath. 309# newjar, or regjar. This is typically used to add directories to the classpath.
278java-pkg_addcp() { 314java-pkg_addcp() {
279 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}" 315 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
280 java-pkg_do_write_ 316 java-pkg_do_write_
281} 317}
282 318
283
284# ------------------------------------------------------------------------------ 319# ------------------------------------------------------------------------------
285# @ebuild-function java-pkg_doso 320# @ebuild-function java-pkg_doso
286# 321#
287# Installs any number of JNI libraries 322# Installs any number of JNI libraries
288# They will be installed into /usr/lib by default, but java-pkg_sointo 323# They will be installed into /usr/lib by default, but java-pkg_sointo
289# can be used change this path 324# can be used change this path
290# 325#
291# Example: 326# Example:
346 java-pkg_check-phase install 381 java-pkg_check-phase install
347 382
348 [[ ${#} -lt 1 ]] && "at least one argument needed" 383 [[ ${#} -lt 1 ]] && "at least one argument needed"
349 384
350 java-pkg_init_paths_ 385 java-pkg_init_paths_
351 386
352 local lib target_dir 387 local lib target_dir
353 for lib in "$@" ; do 388 for lib in "$@" ; do
354 # Check the absolute path of the lib 389 # Check the absolute path of the lib
355 if [[ -e "${lib}" ]] ; then 390 if [[ -e "${lib}" ]] ; then
356 target_dir="$(java-pkg_expand_dir_ ${lib})" 391 target_dir="$(java-pkg_expand_dir_ ${lib})"
404# ------------------------------------------------------------------------------ 439# ------------------------------------------------------------------------------
405java-pkg_dohtml() { 440java-pkg_dohtml() {
406 debug-print-function ${FUNCNAME} $* 441 debug-print-function ${FUNCNAME} $*
407 442
408 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 443 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
409 # TODO-nichoj find out what exactly -f package-list does 444
445 # from /usr/lib/portage/bin/dohtml -h
446 # -f Set list of allowed extensionless file names.
410 dohtml -f package-list "$@" 447 dohtml -f package-list "$@"
448
411 # this probably shouldn't be here but it provides 449 # this probably shouldn't be here but it provides
412 # a reasonable way to catch # docs for all of the 450 # a reasonable way to catch # docs for all of the
413 # old ebuilds. 451 # old ebuilds.
414 java-pkg_recordjavadoc 452 java-pkg_recordjavadoc
415} 453}
416 454
417# TODO document 455# ------------------------------------------------------------------------------
456# @ebuild-function java-pkg_dojavadoc
457#
458# Installs javadoc documentation. This should be controlled by the doc use flag.
459#
460# @param $1: - The javadoc root directory.
461#
462# @example:
463# java-pkg_dojavadoc docs/api
464#
465# ------------------------------------------------------------------------------
418java-pkg_dojavadoc() { 466java-pkg_dojavadoc() {
419 local dir="$1" 467 local dir="$1"
420 468
421 java-pkg_check-phase install 469 java-pkg_check-phase install
422 470
434} 482}
435 483
436# ------------------------------------------------------------------------------ 484# ------------------------------------------------------------------------------
437# @ebuild-function java-pkg_dosrc 485# @ebuild-function java-pkg_dosrc
438# 486#
439# Installs a zip containing the source for a package, so it can used in 487# Installs a zip containing the source for a package, so it can used in
440# from IDEs like eclipse and netbeans. 488# from IDEs like eclipse and netbeans.
441# 489#
442# Ebuild needs to DEPEND on app-arch/zip to use this. 490# Ebuild needs to DEPEND on app-arch/zip to use this.
443# 491#
444# It also should be controlled by USE=source. 492# It also should be controlled by USE=source.
445# 493#
446# @example: 494# @example:
447# java-pkg_dosrc src/* 495# java-pkg_dosrc src/*
448# 496#
449# ------------------------------------------------------------------------------ 497# ------------------------------------------------------------------------------
450# TODO change so it the arguments it takes are the base directories containing 498# TODO change so it the arguments it takes are the base directories containing
451# source -nichoj 499# source -nichoj
452# TODO should we be able to handle multiple calls to dosrc? -nichoj 500# TODO should we be able to handle multiple calls to dosrc? -nichoj
453# TODO maybe we can take an existing zip/jar? -nichoj 501# TODO maybe we can take an existing zip/jar? -nichoj
454# FIXME apparently this fails if you give it an empty directories 502# FIXME apparently this fails if you give it an empty directories
455java-pkg_dosrc() { 503java-pkg_dosrc() {
456 debug-print-function ${FUNCNAME} $* 504 debug-print-function ${FUNCNAME} $*
457 505
458 [ ${#} -lt 1 ] && die "At least one argument needed" 506 [ ${#} -lt 1 ] && die "At least one argument needed"
459 if ! hasq source ${IUSE}; then 507 if ! hasq source ${IUSE}; then
460 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE" 508 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
461 fi 509 fi
462 510
463 java-pkg_check-phase install 511 java-pkg_check-phase install
464 512
465 [[ ${#} -lt 1 ]] && die "At least one argument needed" 513 [[ ${#} -lt 1 ]] && die "At least one argument needed"
466 514
467 java-pkg_init_paths_ 515 java-pkg_init_paths_
468 516
469 local zip_name="${PN}-src.zip" 517 local zip_name="${PN}-src.zip"
470 local zip_path="${T}/${zip_name}" 518 local zip_path="${T}/${zip_name}"
494# @ebuild-function java-pkg_dolauncher 542# @ebuild-function java-pkg_dolauncher
495# 543#
496# Make a wrapper script to lauch/start this package 544# Make a wrapper script to lauch/start this package
497# If necessary, the wrapper will switch to the appropriate VM. 545# If necessary, the wrapper will switch to the appropriate VM.
498# 546#
547# Can be called without parameters if the package installs only one jar
548# that has the Main-class attribute set. The wrapper will be named ${PN}.
549#
499# @param $1 - filename of launcher to create 550# @param $1 - filename of launcher to create
500# @param $2 - options, as follows: 551# @param $2 - options, as follows:
501# --main the.main.class.too.start 552# --main the.main.class.too.start
502# --jar /the/jar/too/launch.jar 553# --jar /the/jar/too/launch.jar or just <name>.jar
503# --java_args 'Extra arguments to pass too jave' 554# --java_args 'Extra arguments to pass to java'
504# --pkg_args 'extra arguments too pass too the package' 555# --pkg_args 'Extra arguments too pass to the package'
505# --pwd 556# --pwd
506# -into 557# -into
507# -pre 558# -pre
508# ------------------------------------------------------------------------------ 559# ------------------------------------------------------------------------------
509java-pkg_dolauncher() { 560java-pkg_dolauncher() {
510 debug-print-function ${FUNCNAME} $* 561 debug-print-function ${FUNCNAME} $*
511 562
512 java-pkg_check-phase install 563 java-pkg_check-phase install
513
514 [[ ${#} -lt 1 ]] && die "Need at least one argument"
515
516 java-pkg_init_paths_ 564 java-pkg_init_paths_
517 565
566 if [[ ${#} = 0 ]]; then
567 local name="${PN}"
568 else
518 local name="${1}" 569 local name="${1}"
570 shift
571 fi
572
519 # TODO rename to launcher 573 # TODO rename to launcher
520 local target="${T}/${name}" 574 local target="${T}/${name}"
575 local var_tmp="${T}/launcher_variables_tmp"
521 local target_dir pre 576 local target_dir pre
522 shift
523 577
524 echo "#!/bin/bash" > "${target}" 578 # Process the other the rest of the arguments
525 while [[ -n "${1}" && -n "${2}" ]]; do 579 while [[ -n "${1}" && -n "${2}" ]]; do
526 local var=${1} value=${2} 580 local var="${1}" value="${2}"
527 if [[ "${var:0:2}" == "--" ]]; then 581 if [[ "${var:0:2}" == "--" ]]; then
582 local var=${var:2}
528 echo "gjl_${var:2}=\"${value}\"" >> "${target}" 583 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
584 local gjl_${var}="${value}"
529 elif [[ "${var}" == "-into" ]]; then 585 elif [[ "${var}" == "-into" ]]; then
530 target_dir="${value}" 586 target_dir="${value}"
531 elif [[ "${var}" == "-pre" ]]; then 587 elif [[ "${var}" == "-pre" ]]; then
532 pre="${value}" 588 pre="${value}"
533 fi 589 fi
534 shift 2 590 shift 2
535 done 591 done
592
593 # Test if no --jar and --main arguments were given and
594 # in that case check if the package only installs one jar
595 # and use that jar.
596 if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
597 local cp="${JAVA_PKG_CLASSPATH}"
598 if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
599 echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
600 else
601 local msg="Not enough information to create a launcher given."
602 msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
603 die "${msg}"
604 fi
605 fi
606
607 # Write the actual script
608 echo "#!/bin/bash" > "${target}"
609 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}"
536 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 610 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
537 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 611 cat "${var_tmp}" >> "${target}"
612 rm -f "${var_tmp}"
538 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 613 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
539 614
540 if [[ -n "${into}" ]]; then 615 if [[ -n "${target_dir}" ]]; then
541 DESTTREE="${target_dir}" dobin "${target}" 616 DESTTREE="${target_dir}" dobin "${target}"
542 local ret=$? 617 local ret=$?
543 return ${ret} 618 return ${ret}
544 else 619 else
545 dobin "${target}" 620 dobin "${target}"
573 echo "dowar: warning, skipping directory ${war}" 648 echo "dowar: warning, skipping directory ${war}"
574 continue 649 continue
575 else 650 else
576 warpath="${war}" 651 warpath="${war}"
577 fi 652 fi
578 653
579 # Install those files like you mean it 654 # Install those files like you mean it
580 INSOPTIONS="-m 0644" \ 655 INSOPTIONS="-m 0644" \
581 INSDESTTREE=${JAVA_PKG_WARDEST} \ 656 INSDESTTREE=${JAVA_PKG_WARDEST} \
582 doins ${warpath} 657 doins ${warpath}
583 done 658 done
618# @ebuild-function java-pkg_jar-from 693# @ebuild-function java-pkg_jar-from
619# 694#
620# Makes a symlink to a jar from a certain package 695# Makes a symlink to a jar from a certain package
621# A lot of java packages include dependencies in a lib/ directory 696# A lot of java packages include dependencies in a lib/ directory
622# You can use this function to replace these bundled dependencies. 697# You can use this function to replace these bundled dependencies.
698# The dependency is recorded into package.env DEPEND line, unless "--build-only"
699# is passed as the very first argument, for jars that have to be present only
700# at build time and are not needed on runtime (junit testing etc).
623# 701#
624# Example: get all jars from xerces slot 2 702# Example: get all jars from xerces slot 2
625# java-pkg_jar-from xerces-2 703# java-pkg_jar-from xerces-2
626# Example: get a specific jar from xerces slot 2 704# Example: get a specific jar from xerces slot 2
627# java-pkg_jar-from xerces-2 xml-apis.jar 705# java-pkg_jar-from xerces-2 xml-apis.jar
628# Example get a specific jar from xerces slot 2, and name it diffrently 706# Example: get a specific jar from xerces slot 2, and name it diffrently
629# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 707# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
708# Example: get junit.jar which is needed only for building
709# java-pkg_jar-from --build-only junit junit.jar
630# 710#
711# @param $1 - (optional) "--build-only" makes the jar(s) not added into
712# package.env DEPEND line.
631# @param $1 - Package to get jars from. 713# @param $1 - Package to get jars from.
632# @param $2 - jar from package. If not specified, all jars will be used. 714# @param $2 - jar from package. If not specified, all jars will be used.
633# @param $3 - When a single jar is specified, destination filename of the 715# @param $3 - When a single jar is specified, destination filename of the
634# symlink. Defaults to the name of the jar. 716# symlink. Defaults to the name of the jar.
635# ------------------------------------------------------------------------------ 717# ------------------------------------------------------------------------------
636# TODO could probably be cleaned up a little 718# TODO could probably be cleaned up a little
637java-pkg_jar-from() { 719java-pkg_jar-from() {
638 debug-print-function ${FUNCNAME} $* 720 debug-print-function ${FUNCNAME} $*
639 721
722 local build_only=""
723
724 if [[ "${1}" = "--build-only" ]]; then
725 build_only="true"
726 shift
727 fi
728
640 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 729 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
641 730
642 [[ -z ${target_pkg} ]] && die "Must specify a package" 731 [[ -z ${target_pkg} ]] && die "Must specify a package"
643 732
644 # default destjar to the target jar 733 # default destjar to the target jar
645 [[ -z "${destjar}" ]] && destjar="${target_jar}" 734 [[ -z "${destjar}" ]] && destjar="${target_jar}"
646 735
736 local error_msg="There was a problem getting the classpath for ${target_pkg}."
737 local classpath
647 local classpath="$(java-config --classpath=${target_pkg})" 738 classpath="$(java-config --classpath=${target_pkg})"
648 [[ $? != 0 ]] && die "There was a problem getting the classpath for ${target_pkg}" 739 [[ $? != 0 ]] && die ${error_msg}
649 740
650 local jar 741 local jar
651 for jar in ${classpath//:/ }; do 742 for jar in ${classpath//:/ }; do
652 local jar_name=$(basename "${jar}") 743 local jar_name=$(basename "${jar}")
653 if [[ ! -f "${jar}" ]] ; then 744 if [[ ! -f "${jar}" ]] ; then
657 # If no specific target jar was indicated, link it 748 # If no specific target jar was indicated, link it
658 if [[ -z "${target_jar}" ]] ; then 749 if [[ -z "${target_jar}" ]] ; then
659 [[ -f "${target_jar}" ]] && rm "${target_jar}" 750 [[ -f "${target_jar}" ]] && rm "${target_jar}"
660 ln -snf "${jar}" \ 751 ln -snf "${jar}" \
661 || die "Failed to make symlink from ${jar} to ${jar_name}" 752 || die "Failed to make symlink from ${jar} to ${jar_name}"
662 java-pkg_record-jar_ "${target_pkg}" "${jar}" 753 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
663 # otherwise, if the current jar is the target jar, link it 754 # otherwise, if the current jar is the target jar, link it
664 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 755 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
665 [[ -f "${destjar}" ]] && rm "${destjar}" 756 [[ -f "${destjar}" ]] && rm "${destjar}"
666 ln -snf "${jar}" "${destjar}" \ 757 ln -snf "${jar}" "${destjar}" \
667 || die "Failed to make symlink from ${jar} to ${destjar}" 758 || die "Failed to make symlink from ${jar} to ${destjar}"
668 java-pkg_record-jar_ "${target_pkg}" "${jar}" 759 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
669 return 0 760 return 0
670 fi 761 fi
671 done 762 done
672 # if no target was specified, we're ok 763 # if no target was specified, we're ok
673 if [[ -z "${target_jar}" ]] ; then 764 if [[ -z "${target_jar}" ]] ; then
690# ------------------------------------------------------------------------------ 781# ------------------------------------------------------------------------------
691# @ebuild-function java-pkg_getjars 782# @ebuild-function java-pkg_getjars
692# 783#
693# Get the classpath provided by any number of packages 784# Get the classpath provided by any number of packages
694# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'. 785# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
786# The providing packages are recorded as dependencies into package.env DEPEND
787# line, unless "--build-only" is passed as the very first argument, for jars
788# that have to be present only at build time and are not needed on runtime
789# (junit testing etc).
695# 790#
696# Example: Get the classpath for xerces-2, 791# Example: Get the classpath for xerces-2 and xalan,
697# java-pkg_getjars xerces-2 xalan 792# java-pkg_getjars xerces-2,xalan
698# Example Return: 793# Example Return:
699# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 794# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
700# 795#
796# @param $1 - (optional) "--build-only" makes the jar(s) not added into
797# package.env DEPEND line.
701# @param $@ - list of packages to get jars from 798# @param $2 - list of packages to get jars from
799# (passed to java-config --classpath)
702# ------------------------------------------------------------------------------ 800# ------------------------------------------------------------------------------
703java-pkg_getjars() { 801java-pkg_getjars() {
704 debug-print-function ${FUNCNAME} $* 802 debug-print-function ${FUNCNAME} $*
705 803
706 [[ ${#} -lt 1 ]] && die "At least one argument needed" 804 if [[ "${1}" = "--build-only" ]]; then
805 local build_only="true"
806 shift
807 fi
707 808
708 # NOTE could probably just pass $@ to java-config --classpath. and return it 809 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --build-only"
810
709 local classpath pkg 811 local classpath pkgs="${1}"
710 for pkg in ${@//,/ }; do
711 #for pkg in $(echo "$@" | tr ',' ' '); do
712 jars="$(java-config --classpath=${pkg})" 812 jars="$(java-config --classpath=${pkgs})"
813 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed"
713 debug-print "${pkg}:${jars}" 814 debug-print "${pkgs}:${jars}"
714 # TODO should we ensure jars exist? 815
715 if [[ -z "${classpath}" ]]; then 816 if [[ -z "${classpath}" ]]; then
716 classpath="${jars}" 817 classpath="${jars}"
717 else 818 else
718 classpath="${classpath}:${jars}" 819 classpath="${classpath}:${jars}"
719 fi 820 fi
821
822 # Only record jars that aren't build-only
823 if [[ -z "${build_only}" ]]; then
824 oldifs="${IFS}"
825 IFS=","
826 for pkg in ${pkgs}; do
720 java-pkg_record-jar_ "${pkg}" 827 java-pkg_record-jar_ "${pkg}"
721 done 828 done
829 IFS="${oldifs}"
830 fi
831
722 echo "${classpath}" 832 echo "${classpath}"
723} 833}
724 834
725# ------------------------------------------------------------------------------ 835# ------------------------------------------------------------------------------
726# @ebuild-function java-pkg_getjar 836# @ebuild-function java-pkg_getjar
727# 837#
728# Get the filename of a single jar from a package 838# Get the filename of a single jar from a package
839# The providing package is recorded as runtime dependency into package.env
840# DEPEND line, unless "--build-only" is passed as the very first argument, for
841# jars that have to be present only at build time and are not needed on runtime
842# (junit testing etc).
729# 843#
730# @example 844# @example
731# java-pkg_getjar xerces-2 xml-apis.jar 845# java-pkg_getjar xerces-2 xml-apis.jar
732# @example-return 846# @example-return
733# /usr/share/xerces-2/lib/xml-apis.jar 847# /usr/share/xerces-2/lib/xml-apis.jar
734# 848#
849# @param $1 - (optional) "--build-only" makes the jar not added into
850# package.env DEPEND line.
735# @param $1 - package to use 851# @param $1 - package to use
736# @param $2 - jar to get 852# @param $2 - jar to get
737# ------------------------------------------------------------------------------ 853# ------------------------------------------------------------------------------
738java-pkg_getjar() { 854java-pkg_getjar() {
739 debug-print-function ${FUNCNAME} $* 855 debug-print-function ${FUNCNAME} $*
856
857 local build_only=""
858
859 if [[ "${1}" = "--build-only" ]]; then
860 build_only="true"
861 shift
862 fi
740 863
741 local pkg="${1}" target_jar="${2}" jar 864 local pkg="${1}" target_jar="${2}" jar
742 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 865 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
743 [[ -z ${target_jar} ]] && die "Must specify jar to get" 866 [[ -z ${target_jar} ]] && die "Must specify jar to get"
744 867
745 # TODO check that package is actually installed 868 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
869 local classpath
746 local classpath=$(java-config --classpath=${pkg}) 870 classpath=$(java-config --classpath=${pkg})
747 [[ $? != 0 ]] && die "There could not find classpath for ${pkg}. Are you sure its installed?" 871 [[ $? != 0 ]] && die ${error_msg}
872
748 for jar in ${classpath//:/ }; do 873 for jar in ${classpath//:/ }; do
749 if [[ ! -f "${jar}" ]] ; then 874 if [[ ! -f "${jar}" ]] ; then
750 die "Installation problems with jars in ${pkg} - is it installed?" 875 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
751 fi 876 fi
752 877
753 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then 878 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
754 java-pkg_record-jar_ "${pkg}" "${jar}" 879 # Only record jars that aren't build-only
880 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" "${jar}"
755 echo "${jar}" 881 echo "${jar}"
756 return 0 882 return 0
757 fi 883 fi
758 done 884 done
759 885
760 die "Could not find ${target_jar} in ${pkg}" 886 die "Could not find ${target_jar} in ${pkg}"
761 return 1 887 return 1
762} 888}
763 889
764# This function reads stdin, and based on that input, figures out how to 890# This function reads stdin, and based on that input, figures out how to
778# line="${line// /}" 904# line="${line// /}"
779# 905#
780# # format: path=jarinfo 906# # format: path=jarinfo
781# local path=${line%%=*} 907# local path=${line%%=*}
782# local jarinfo=${line##*=} 908# local jarinfo=${line##*=}
783# 909#
784# # format: jar@package 910# # format: jar@package
785# local jar=${jarinfo%%@*}.jar 911# local jar=${jarinfo%%@*}.jar
786# local package=${jarinfo##*@} 912# local package=${jarinfo##*@}
787# if [[ -n ${replace_only} ]]; then 913# if [[ -n ${replace_only} ]]; then
788# [[ ! -f $path ]] && die "No jar exists at ${path}" 914# [[ ! -f $path ]] && die "No jar exists at ${path}"
801# @section-end query 927# @section-end query
802# ------------------------------------------------------------------------------ 928# ------------------------------------------------------------------------------
803 929
804# ------------------------------------------------------------------------------ 930# ------------------------------------------------------------------------------
805# @section-begin helper 931# @section-begin helper
806# @section-summary Helper functions 932# @section-summary Helper functions
807# 933#
808# Various other functions to use from an ebuild 934# Various other functions to use from an ebuild
809# ------------------------------------------------------------------------------ 935# ------------------------------------------------------------------------------
810 936
811# ------------------------------------------------------------------------------ 937# ------------------------------------------------------------------------------
817# jdbc-stdext 943# jdbc-stdext
818# jaf 944# jaf
819# jdbc-rowset 945# jdbc-rowset
820# jms 946# jms
821# 947#
822# @param $1 - Optionally indicate that the dependencies are controlled by 948# @param $1 - Optionally indicate that the dependencies are controlled by
823# a use flag by specifying '--use' Requires $2. 949# a use flag by specifying '--use' Requires $2.
824# @param $2 - USE flag which will enable the dependencies. 950# @param $2 - USE flag which will enable the dependencies.
825# @param $@ - virtual packages to add depenedencies for 951# @param $@ - virtual packages to add depenedencies for
826# ------------------------------------------------------------------------------ 952# ------------------------------------------------------------------------------
827# TODO rewrite to parse a line based declaration file instead -- karltk 953# TODO rewrite to parse a line based declaration file instead -- karltk
883# 1009#
884# export DEPEND="${DEPEND} ${depstr}" 1010# export DEPEND="${DEPEND} ${depstr}"
885# export RDEPEND="${RDEPEND} ${depstr}" 1011# export RDEPEND="${RDEPEND} ${depstr}"
886#} 1012#}
887 1013
1014# ------------------------------------------------------------------------------
1015# @ebuild-function java-pkg_find-normal-jars
1016#
1017# Find the files with suffix .jar file in the given directory or $WORKDIR
1018#
1019# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1020# ------------------------------------------------------------------------------
1021java-pkg_find-normal-jars() {
1022 local dir=$1
1023 [[ "${dir}" ]] || dir="${WORKDIR}"
1024 local found
1025 for jar in $(find "${dir}" -name "*.jar" -type f); do
1026 echo "${jar}"
1027 found="true"
1028 done
1029 [[ "${found}" ]]
1030 return $?
1031}
1032
1033# ------------------------------------------------------------------------------
1034# @ebuild-function java-pkg_ensure-no-bundled-jars
1035#
1036# Try to locate bundled jar files in ${WORKDIR} and die if found.
888# This should be used after S has been populated with symlinks to jars 1037# This function should be called after WORKDIR has been populated with symlink
889# TODO document 1038# to system jar files or bundled jars removed.
1039# ------------------------------------------------------------------------------
890java-pkg_ensure-no-bundled-jars() { 1040java-pkg_ensure-no-bundled-jars() {
891 debug-print-function ${FUNCNAME} $* 1041 debug-print-function ${FUNCNAME} $*
892 pushd ${WORKDIR} >/dev/null 2>/dev/null
893 1042
894 local bundled_jars=$(find . -name "*.jar" -type f) 1043 local bundled_jars=$(java-pkg_find-normal-jars)
895 if [[ -n ${bundled_jars} ]]; then 1044 if [[ -n ${bundled_jars} ]]; then
896 echo "Bundled jars found:" 1045 echo "Bundled jars found:"
897 local jar 1046 local jar
898 for jar in ${bundled_jars}; do 1047 for jar in ${bundled_jars}; do
899 echo $(pwd)${jar/./} 1048 echo $(pwd)${jar/./}
900 done 1049 done
901 die "Bundled jars found!" 1050 die "Bundled jars found!"
902
903 fi 1051 fi
904 popd >/dev/null 2>/dev/null
905} 1052}
906 1053
907# ------------------------------------------------------------------------------ 1054# ------------------------------------------------------------------------------
908# @internal-function java-pkg_ensure-vm-version-sufficient 1055# @internal-function java-pkg_ensure-vm-version-sufficient
909# 1056#
921 fi 1068 fi
922} 1069}
923 1070
924# ------------------------------------------------------------------------------ 1071# ------------------------------------------------------------------------------
925# @internal-function java-pkg_is-vm-version-sufficient 1072# @internal-function java-pkg_is-vm-version-sufficient
926# 1073#
927# @return zero - VM is sufficient 1074# @return zero - VM is sufficient
928# @return non-zero - VM is not sufficient 1075# @return non-zero - VM is not sufficient
929# ------------------------------------------------------------------------------ 1076# ------------------------------------------------------------------------------
930java-pkg_is-vm-version-sufficient() { 1077java-pkg_is-vm-version-sufficient() {
931 debug-print-function ${FUNCNAME} $* 1078 debug-print-function ${FUNCNAME} $*
951 die "Active Java VM too old" 1098 die "Active Java VM too old"
952 fi 1099 fi
953} 1100}
954 1101
955# ------------------------------------------------------------------------------ 1102# ------------------------------------------------------------------------------
956# @internal-function java-pkg_is-vm-version-eq 1103# @internal-function java-pkg_is-vm-version-eq
957# 1104#
958# @param $@ - VM version to compare current VM to 1105# @param $@ - VM version to compare current VM to
959# @return zero - VM versions are equal 1106# @return zero - VM versions are equal
960# @return non-zero - VM version are not equal 1107# @return non-zero - VM version are not equal
961# ------------------------------------------------------------------------------ 1108# ------------------------------------------------------------------------------
962java-pkg_is-vm-version-eq() { 1109java-pkg_is-vm-version-eq() {
992# 1139#
993# @param $@ - VM version to compare current to 1140# @param $@ - VM version to compare current to
994# ------------------------------------------------------------------------------ 1141# ------------------------------------------------------------------------------
995java-pkg_ensure-vm-version-ge() { 1142java-pkg_ensure-vm-version-ge() {
996 debug-print-function ${FUNCNAME} $* 1143 debug-print-function ${FUNCNAME} $*
997 1144
998 if ! java-pkg_is-vm-version-ge "$@" ; then 1145 if ! java-pkg_is-vm-version-ge "$@" ; then
999 debug-print "vm is not suffient" 1146 debug-print "vm is not suffient"
1000 eerror "This package requires a Java VM version >= $@" 1147 eerror "This package requires a Java VM version >= $@"
1001 einfo "Please use java-config -S to set the correct one" 1148 einfo "Please use java-config -S to set the correct one"
1002 die "Active Java VM too old" 1149 die "Active Java VM too old"
1003 fi 1150 fi
1004} 1151}
1005 1152
1006# ------------------------------------------------------------------------------ 1153# ------------------------------------------------------------------------------
1007# @internal-function java-pkg_is-vm-version-ge 1154# @internal-function java-pkg_is-vm-version-ge
1008# 1155#
1009# @param $@ - VM version to compare current VM to 1156# @param $@ - VM version to compare current VM to
1010# @return zero - current VM version is greater than checked version 1157# @return zero - current VM version is greater than checked version
1011# @return non-zero - current VM version is not greater than checked version 1158# @return non-zero - current VM version is not greater than checked version
1012# ------------------------------------------------------------------------------ 1159# ------------------------------------------------------------------------------
1013java-pkg_is-vm-version-ge() { 1160java-pkg_is-vm-version-ge() {
1027 return 1 1174 return 1
1028 fi 1175 fi
1029 fi 1176 fi
1030} 1177}
1031 1178
1179java-pkg_set-current-vm() {
1180 export GENTOO_VM=${1}
1181}
1182
1183java-pkg_get-current-vm() {
1184 echo ${GENTOO_VM}
1185}
1186
1187java-pkg_current-vm-matches() {
1188 hasq $(java-pkg_get-current-vm) ${@}
1189 return $?
1190}
1191
1032# ------------------------------------------------------------------------------ 1192# ------------------------------------------------------------------------------
1033# @ebuild-function java-pkg_get-source 1193# @ebuild-function java-pkg_get-source
1034# 1194#
1035# Determines what source version should be used, for passing to -source. 1195# Determines what source version should be used, for passing to -source.
1036# Unless you want to break things you probably shouldn't set _WANT_SOURCE 1196# Unless you want to break things you probably shouldn't set _WANT_SOURCE
1037# 1197#
1038# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE 1198# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1039# ------------------------------------------------------------------------------ 1199# ------------------------------------------------------------------------------
1044# ------------------------------------------------------------------------------ 1204# ------------------------------------------------------------------------------
1045# @ebuild-function java-pkg_get-target 1205# @ebuild-function java-pkg_get-target
1046# 1206#
1047# Determines what target version should be used, for passing to -target. 1207# Determines what target version should be used, for passing to -target.
1048# If you don't care about lower versions, you can set _WANT_TARGET to the 1208# If you don't care about lower versions, you can set _WANT_TARGET to the
1049# version of your JDK. 1209# version of your JDK.
1050# Remember doing this will mostly like cause things to break.
1051# Doesn't allow it to be lower then the one in depend.
1052# Doesn't allow it to be higher then the active vm.
1053# 1210#
1054# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1211# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1055# ------------------------------------------------------------------------------ 1212# ------------------------------------------------------------------------------
1056java-pkg_get-target() { 1213java-pkg_get-target() {
1057 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")
1058 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then
1059 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)"
1060 if version_is_at_least "${min}" "${JAVA_PKG_WANT_TARGET}" && version_is_at_least "${JAVA_PKG_WANT_TARGET}" "${max}"; then
1061 echo ${JAVA_PKG_WANT_TARGET}
1062 else
1063 echo ${min}
1064 fi
1065 else
1066 echo ${min}
1067 fi
1068
1069 #echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND}")} 1214 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1070} 1215}
1071 1216
1072java-pkg_get-javac() { 1217java-pkg_get-javac() {
1073 debug-print-function ${FUNCNAME} $* 1218 debug-print-function ${FUNCNAME} $*
1074 1219
1075 java-pkg_init-compiler_ 1220
1076 local compiler="${GENTOO_COMPILER}" 1221 local compiler="${GENTOO_COMPILER}"
1077 1222
1078 local compiler_executable 1223 local compiler_executable
1079 if [[ "${compiler}" = "javac" ]]; then 1224 if [[ "${compiler}" = "javac" ]]; then
1080 # nothing fancy needs to be done for javac 1225 # nothing fancy needs to be done for javac
1088 unset JAVAC 1233 unset JAVAC
1089 # try to get value of JAVAC 1234 # try to get value of JAVAC
1090 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1235 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1091 export JAVAC=${old_javac} 1236 export JAVAC=${old_javac}
1092 1237
1093 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1238 if [[ -z ${compiler_executable} ]]; then
1094 1239 echo "JAVAC is empty or undefined in ${compiler_env}"
1240 return 1
1241 fi
1242
1095 # check that it's executable 1243 # check that it's executable
1096 if [[ ! -x ${compiler_executable} ]]; then 1244 if [[ ! -x ${compiler_executable} ]]; then
1097 eerror "Could not find ${compiler_executable}!"
1098 die "${compiler_executable} doesn't exist, or isn't executable" 1245 echo "${compiler_executable} doesn't exist, or isn't executable"
1246 return 1
1099 fi 1247 fi
1100 else 1248 else
1101 eerror "Could not find environment file for ${compiler}" 1249 echo "Could not find environment file for ${compiler}"
1102 die "Could not find ${compiler_env}" 1250 return 1
1103 fi 1251 fi
1104 fi 1252 fi
1105 echo ${compiler_executable} 1253 echo ${compiler_executable}
1106} 1254}
1107 1255
1108# ------------------------------------------------------------------------------ 1256# ------------------------------------------------------------------------------
1109# @ebuild-function java-pkg_javac-args 1257# @ebuild-function java-pkg_javac-args
1110# 1258#
1111# If an ebuild uses javac directly, instead of using ejavac, it should call this 1259# If an ebuild uses javac directly, instead of using ejavac, it should call this
1112# to know what -source/-target to use. 1260# to know what -source/-target to use.
1113# 1261#
1114# @return string - arguments to pass to javac, complete with -target and -source 1262# @return string - arguments to pass to javac, complete with -target and -source
1117 debug-print-function ${FUNCNAME} $* 1265 debug-print-function ${FUNCNAME} $*
1118 1266
1119 local want_source="$(java-pkg_get-source)" 1267 local want_source="$(java-pkg_get-source)"
1120 local want_target="$(java-pkg_get-target)" 1268 local want_target="$(java-pkg_get-target)"
1121 1269
1122 local source_str="-source ${want_source}" 1270 local source_str="-source ${want_source}"
1123 local target_str="-target ${want_target}" 1271 local target_str="-target ${want_target}"
1124 1272
1125 debug-print "want source: ${want_source}" 1273 debug-print "want source: ${want_source}"
1126 debug-print "want target: ${want_target}" 1274 debug-print "want target: ${want_target}"
1127 1275
1128 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1276 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1129 debug-print "could not find valid -source/-target values" 1277 debug-print "could not find valid -source/-target values for javac"
1130 die "Could not find valid -source/-target values" 1278 echo "Could not find valid -source/-target values for javac"
1279 return 1
1131 else 1280 else
1132 if java-pkg_is-vm-version-ge "1.4"; then 1281 if java-pkg_is-vm-version-ge "1.4"; then
1133 echo "${source_str} ${target_str}" 1282 echo "${source_str} ${target_str}"
1134 else 1283 else
1135 echo "${target_str}" 1284 echo "${target_str}"
1139 1288
1140# TODO document 1289# TODO document
1141java-pkg_get-jni-cflags() { 1290java-pkg_get-jni-cflags() {
1142 local flags="-I${JAVA_HOME}/include" 1291 local flags="-I${JAVA_HOME}/include"
1143 1292
1144 # TODO figure out how to cope with other things than linux... 1293 local platform="linux"
1294 use elibc_FreeBSD && platform="freebsd"
1295
1296 # TODO do a check that the directories are valid
1145 flags="${flags} -I${JAVA_HOME}/include/linux" 1297 flags="${flags} -I${JAVA_HOME}/include/${platform}"
1146 1298
1147 echo ${flags} 1299 echo ${flags}
1300}
1301
1302java-pkg_ensure-gcj() {
1303 if ! built_with_use sys-devel/gcc gcj ; then
1304 ewarn
1305 ewarn "You must build gcc with the gcj support to build with gcj"
1306 ewarn
1307 ebeep 5
1308 die "No GCJ support found!"
1309 fi
1310}
1311
1312java-pkg_ensure-test() {
1313 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \
1314 && hasq test ${IUSE} && ! use test;
1315 then
1316 eerror "You specified FEATURES=test, but USE=test is needed"
1317 eerror "to pull in the additional dependencies for testing"
1318 die "Need USE=test enabled"
1319 fi
1148} 1320}
1149 1321
1150# ------------------------------------------------------------------------------ 1322# ------------------------------------------------------------------------------
1151# @section-end helper 1323# @section-end helper
1152# ------------------------------------------------------------------------------ 1324# ------------------------------------------------------------------------------
1167# 1339#
1168# ------------------------------------------------------------------------------ 1340# ------------------------------------------------------------------------------
1169eant() { 1341eant() {
1170 debug-print-function ${FUNCNAME} $* 1342 debug-print-function ${FUNCNAME} $*
1171 1343
1172 local antflags 1344 # FIXME get this working
1345# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then
1346# java-pkg_announce-qa-violation \
1347# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1348# fi
1349
1350 local antflags="-Dnoget=true"
1173 java-pkg_init-compiler_ 1351 java-pkg_init-compiler_
1174 local compiler="${GENTOO_COMPILER}" 1352 local compiler="${GENTOO_COMPILER}"
1175 1353
1176 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1354 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1177 1355
1179 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1357 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1180 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1358 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1181 fi 1359 fi
1182 1360
1183 if [[ ${compiler} != "javac" ]]; then 1361 if [[ ${compiler} != "javac" ]]; then
1184 antflags="-Dbuild.compiler=${build_compiler}" 1362 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1185 # Figure out any extra stuff to put on the classpath for compilers aside 1363 # Figure out any extra stuff to put on the classpath for compilers aside
1186 # from javac 1364 # from javac
1187 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to 1365 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1188 # java-config -p 1366 # java-config -p
1189 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1367 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})"
1190 if [[ -n ${build_compiler_deps} ]]; then 1368 if [[ -n ${build_compiler_deps} ]]; then
1191 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})" 1369 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1192 fi 1370 fi
1193 fi 1371 fi
1194 1372
1373 if is-java-strict; then
1374 einfo "Disabling system classpath for ant"
1375 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1376 fi
1377
1195 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1378 if [[ -n ${JAVA_PKG_DEBUG} ]]; then
1196 antflags="${antflags} -debug" 1379 antflags="${antflags} -debug"
1197 fi 1380 fi
1198 1381
1199 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1382 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1200 ant ${antflags} "${@}" || die "eant failed" 1383 ant ${antflags} "${@}" || die "eant failed"
1201 1384
1202} 1385}
1203 1386
1204# ------------------------------------------------------------------------------ 1387# ------------------------------------------------------------------------------
1205# @ebuild-function ejavac 1388# @ebuild-function ejavac
1206# 1389#
1207# Javac wrapper function. Will use the appropriate compiler, based on 1390# Javac wrapper function. Will use the appropriate compiler, based on
1208# /etc/java-config/compilers.conf 1391# /etc/java-config/compilers.conf
1209# 1392#
1210# @param $@ - Arguments to be passed to the compiler 1393# @param $@ - Arguments to be passed to the compiler
1211# ------------------------------------------------------------------------------ 1394# ------------------------------------------------------------------------------
1212ejavac() { 1395ejavac() {
1213 debug-print-function ${FUNCNAME} $* 1396 debug-print-function ${FUNCNAME} $*
1214 1397
1398 java-pkg_init-compiler_
1399
1400 local compiler_executable
1215 local compiler_executable=$(java-pkg_get-javac) 1401 compiler_executable=$(java-pkg_get-javac)
1402 if [[ ${?} != 0 ]]; then
1403 eerror "There was a problem determining compiler: ${compiler_executable}"
1404 die "get-javac failed"
1405 fi
1216 1406
1407 local javac_args
1408 javac_args="$(java-pkg_javac-args)"
1409 if [[ ${?} != 0 ]]; then
1410 eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
1411 die "java-pkg_javac-args failed"
1412 fi
1413
1217 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 1414 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1218 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 1415 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1219} 1416}
1220 1417
1221# ------------------------------------------------------------------------------ 1418# ------------------------------------------------------------------------------
1222# @ebuild-function java-pkg_filter-compiler 1419# @ebuild-function java-pkg_filter-compiler
1223# 1420#
1224# Used to prevent the use of some compilers. Should be used in src_compile. 1421# Used to prevent the use of some compilers. Should be used in src_compile.
1225# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER 1422# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
1226# 1423#
1227# @param $@ - compilers to filter 1424# @param $@ - compilers to filter
1228# ------------------------------------------------------------------------------ 1425# ------------------------------------------------------------------------------
1229java-pkg_filter-compiler() { 1426java-pkg_filter-compiler() {
1230 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@" 1427 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@"
1231} 1428}
1232 1429
1233# ------------------------------------------------------------------------------ 1430# ------------------------------------------------------------------------------
1431# @ebuild-function java-pkg_force-compiler
1432#
1433# Used to force the use of particular compilers. Should be used in src_compile.
1434# A common use of this would be to force ecj-3.1 to be used on amd64, to avoid
1435# OutOfMemoryErrors that may come up.
1436#
1437# @param $@ - compilers to force
1438# ------------------------------------------------------------------------------
1439java-pkg_force-compiler() {
1440 JAVA_PKG_FORCE_COMPILER="$@"
1441}
1442
1443# ------------------------------------------------------------------------------
1234# @ebuild-function use_doc 1444# @ebuild-function use_doc
1235# 1445#
1236# Helper function for getting ant to build javadocs. If the user has USE=doc, 1446# Helper function for getting ant to build javadocs. If the user has USE=doc,
1237# then 'javadoc' or the argument are returned. Otherwise, there is no return. 1447# then 'javadoc' or the argument are returned. Otherwise, there is no return.
1238# 1448#
1239# The output of this should be passed to ant. 1449# The output of this should be passed to ant.
1240# 1450#
1241# Example: build javadocs by calling 'javadoc' target 1451# Example: build javadocs by calling 'javadoc' target
1242# eant $(use_doc) 1452# eant $(use_doc)
1243# Example: build javadocs by calling 'apidoc' target 1453# Example: build javadocs by calling 'apidoc' target
1248# ------------------------------------------------------------------------------ 1458# ------------------------------------------------------------------------------
1249use_doc() { 1459use_doc() {
1250 use doc && echo ${@:-javadoc} 1460 use doc && echo ${@:-javadoc}
1251} 1461}
1252 1462
1463
1253# ------------------------------------------------------------------------------ 1464# ------------------------------------------------------------------------------
1254# @section-end build 1465# @section-end build
1255# ------------------------------------------------------------------------------ 1466# ------------------------------------------------------------------------------
1256 1467
1257# ------------------------------------------------------------------------------ 1468# ------------------------------------------------------------------------------
1258# @section-begin internal 1469# @section-begin internal
1259# @section-summary Internal functions 1470# @section-summary Internal functions
1260# 1471#
1261# Do __NOT__ use any of these from an ebuild! These are only to be used from 1472# Do __NOT__ use any of these from an ebuild! These are only to be used from
1262# within the java eclasses. 1473# within the java eclasses.
1263# ------------------------------------------------------------------------------ 1474# ------------------------------------------------------------------------------
1264 1475
1265# ----------------------------------------------------------------------------- 1476# -----------------------------------------------------------------------------
1266# @function-internal java-pkg_init 1477# @function-internal java-pkg_init
1267# 1478#
1268# The purpose of this function, as the name might imply, is to initialize the 1479# The purpose of this function, as the name might imply, is to initialize the
1269# Java environment. It ensures that that there aren't any environment variables 1480# Java environment. It ensures that that there aren't any environment variables
1270# that'll muss things up. It initializes some variables, which are used 1481# that'll muss things up. It initializes some variables, which are used
1271# internally. And most importantly, it'll switch the VM if necessary. 1482# internally. And most importantly, it'll switch the VM if necessary.
1272# 1483#
1284 # TODO we will probably want to set JAVAC and JAVACFLAGS 1495 # TODO we will probably want to set JAVAC and JAVACFLAGS
1285 1496
1286 # Do some QA checks 1497 # Do some QA checks
1287 java-pkg_check-jikes 1498 java-pkg_check-jikes
1288 1499
1289 # When users have crazy classpaths some packages can fail to compile. 1500 # When users have crazy classpaths some packages can fail to compile.
1290 # and everything should work with empty CLASSPATH. 1501 # and everything should work with empty CLASSPATH.
1291 # This also helps prevent unexpected dependencies on random things 1502 # This also helps prevent unexpected dependencies on random things
1292 # from the CLASSPATH. 1503 # from the CLASSPATH.
1293 unset CLASSPATH 1504 unset CLASSPATH
1294} 1505}
1295 1506
1296# ------------------------------------------------------------------------------ 1507# ------------------------------------------------------------------------------
1297# @function-internal java-pkg-init-compiler_ 1508# @function-internal java-pkg-init-compiler_
1298# 1509#
1299# This function attempts to figure out what compiler should be used. It does 1510# This function attempts to figure out what compiler should be used. It does
1300# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the 1511# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
1301# COMPILERS variable defined there. 1512# COMPILERS variable defined there.
1302# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER 1513# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
1303# 1514#
1304# It will go through the list of compilers, and verify that it supports the 1515# It will go through the list of compilers, and verify that it supports the
1305# target and source that are needed. If it is not suitable, then the next 1516# target and source that are needed. If it is not suitable, then the next
1306# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking 1517# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
1307# isn't done. 1518# isn't done.
1308# 1519#
1330 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1541 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1331 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})" 1542 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
1332 else 1543 else
1333 compilers=${JAVA_PKG_FORCE_COMPILER} 1544 compilers=${JAVA_PKG_FORCE_COMPILER}
1334 fi 1545 fi
1335 1546
1336 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}" 1547 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
1337 1548
1338 # Figure out if we should announce what compiler we're using 1549 # Figure out if we should announce what compiler we're using
1339 local compiler 1550 local compiler
1340 for compiler in ${compilers}; do 1551 for compiler in ${compilers}; do
1343 if [[ ${compiler} = "javac" ]]; then 1554 if [[ ${compiler} = "javac" ]]; then
1344 debug-print "Found javac... breaking" 1555 debug-print "Found javac... breaking"
1345 export GENTOO_COMPILER="javac" 1556 export GENTOO_COMPILER="javac"
1346 break 1557 break
1347 fi 1558 fi
1348 1559
1349 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then 1560 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
1350 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1561 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1351 einfo "Filtering ${compiler}" 1562 einfo "Filtering ${compiler}"
1352 continue 1563 continue
1353 fi 1564 fi
1354 fi 1565 fi
1355 1566
1356 # for non-javac, we need to make sure it supports the right target and 1567 # for non-javac, we need to make sure it supports the right target and
1357 # source 1568 # source
1358 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1569 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1359 if [[ -f ${compiler_env} ]]; then 1570 if [[ -f ${compiler_env} ]]; then
1360 local desired_target="$(java-pkg_get-target)" 1571 local desired_target="$(java-pkg_get-target)"
1442# Writes the package.env out to disk. 1653# Writes the package.env out to disk.
1443# 1654#
1444# ------------------------------------------------------------------------------ 1655# ------------------------------------------------------------------------------
1445# TODO change to do-write, to match everything else 1656# TODO change to do-write, to match everything else
1446java-pkg_do_write_() { 1657java-pkg_do_write_() {
1658 java-pkg_init_paths_
1447 # Create directory for package.env 1659 # Create directory for package.env
1448 dodir "${JAVA_PKG_SHAREPATH}" 1660 dodir "${JAVA_PKG_SHAREPATH}"
1449 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 1661 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then
1450 # Create package.env 1662 # Create package.env
1451 ( 1663 (
1456 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 1668 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1457 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 1669 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1458 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 1670 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\""
1459 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 1671 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1460 ) > "${JAVA_PKG_ENV}" 1672 ) > "${JAVA_PKG_ENV}"
1461 1673
1462 # register target/source 1674 # register target/source
1463 local target="$(java-pkg_get-target)" 1675 local target="$(java-pkg_get-target)"
1464 local source="$(java-pkg_get-source)" 1676 local source="$(java-pkg_get-source)"
1465 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}" 1677 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
1466 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}" 1678 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
1479 # Strip unnecessary leading and trailing colons 1691 # Strip unnecessary leading and trailing colons
1480 # TODO try to cleanup if possible 1692 # TODO try to cleanup if possible
1481 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 1693 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
1482 fi 1694 fi
1483} 1695}
1484
1485 1696
1486# ------------------------------------------------------------------------------ 1697# ------------------------------------------------------------------------------
1487# @internal-function java-pkg_record-jar_ 1698# @internal-function java-pkg_record-jar_
1488# 1699#
1489# Record a dependency to the package.env 1700# Record a dependency to the package.env
1533 fi 1744 fi
1534} 1745}
1535 1746
1536# ------------------------------------------------------------------------------ 1747# ------------------------------------------------------------------------------
1537# @internal-function java-pkg_expand_dir_ 1748# @internal-function java-pkg_expand_dir_
1538# 1749#
1539# Gets the full path of the file/directory's parent. 1750# Gets the full path of the file/directory's parent.
1540# @param $1 - file/directory to find parent directory for 1751# @param $1 - file/directory to find parent directory for
1541# @return - path to $1's parent directory 1752# @return - path to $1's parent directory
1542# ------------------------------------------------------------------------------ 1753# ------------------------------------------------------------------------------
1543java-pkg_expand_dir_() { 1754java-pkg_expand_dir_() {
1570# ------------------------------------------------------------------------------ 1781# ------------------------------------------------------------------------------
1571java-pkg_setup-vm() { 1782java-pkg_setup-vm() {
1572 debug-print-function ${FUNCNAME} $* 1783 debug-print-function ${FUNCNAME} $*
1573 1784
1574 local vendor="$(java-pkg_get-vm-vendor)" 1785 local vendor="$(java-pkg_get-vm-vendor)"
1575 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge 1 5; then 1786 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1576 addpredict "/dev/random" 1787 addpredict "/dev/random"
1577 elif [[ "${vendor}" == "ibm" ]]; then 1788 elif [[ "${vendor}" == "ibm" ]]; then
1578 addpredict "/proc/self/maps" 1789 addpredict "/proc/self/maps"
1579 addpredict "/proc/cpuinfo" 1790 addpredict "/proc/cpuinfo"
1580 export LANG="C" LC_ALL="C" 1791 export LANG="C" LC_ALL="C"
1629# @return - The version of the current VM 1840# @return - The version of the current VM
1630# ------------------------------------------------------------------------------ 1841# ------------------------------------------------------------------------------
1631java-pkg_get-vm-version() { 1842java-pkg_get-vm-version() {
1632 debug-print-function ${FUNCNAME} $* 1843 debug-print-function ${FUNCNAME} $*
1633 1844
1634 java-pkg_get-current-vm | sed -e "s/.*-\([0-9.]\+\).*/\1/" 1845 java-config -g PROVIDES_VERSION
1635} 1846}
1636 1847
1637# ------------------------------------------------------------------------------ 1848# ------------------------------------------------------------------------------
1638# @internal-function java-pkg_switch-vm 1849# @internal-function java-pkg_switch-vm
1639# 1850#
1640# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 1851# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1641# verify that the current VM is sufficient. 1852# verify that the current VM is sufficient.
1642# Setup the environment for the VM being used. 1853# Setup the environment for the VM being used.
1643# ------------------------------------------------------------------------------ 1854# ------------------------------------------------------------------------------
1644java-pkg_switch-vm() { 1855java-pkg_switch-vm() {
1856 debug-print-function ${FUNCNAME} $*
1857
1645 if java-pkg_needs-vm; then 1858 if java-pkg_needs-vm; then
1646 # Use the VM specified by JAVA_PKG_FORCE_VM 1859 # Use the VM specified by JAVA_PKG_FORCE_VM
1647 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then 1860 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1648 # If you're forcing the VM, I hope you know what your doing... 1861 # If you're forcing the VM, I hope you know what your doing...
1862 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1649 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 1863 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1650 # if we're allowed to switch the vm... 1864 # if we're allowed to switch the vm...
1651 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 1865 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1652 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}" 1866 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1653 if [[ -n ${JAVA_PKG_VNEED} ]]; then 1867 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1654 export GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 1868 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1655 else 1869 else
1656 export GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 1870 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1871 fi
1872 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
1873 eerror "Unable to determine VM for building from dependencies:"
1874 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
1875 echo "VNEED: ${JAVA_PKG_VNEED}"
1876 die "Failed to determine VM for building."
1877 else
1878 export GENTOO_VM
1657 fi 1879 fi
1658 # otherwise just make sure the current VM is sufficient 1880 # otherwise just make sure the current VM is sufficient
1659 else 1881 else
1660 java-pkg_ensure-vm-version-sufficient 1882 java-pkg_ensure-vm-version-sufficient
1661 fi 1883 fi
1662 debug-print "Using: $(java-config -f)" 1884 debug-print "Using: $(java-config -f)"
1663 1885
1664 java-pkg_setup-vm 1886 java-pkg_setup-vm
1665 1887
1666 export JAVA=$(java-config -java) 1888 export JAVA=$(java-config --java)
1667 export JAVAC=$(java-config -javac) 1889 export JAVAC=$(java-config --javac)
1668 export JAVACFLAGS="$(java-pkg_javac-args)" 1890 JAVACFLAGS="$(java-pkg_javac-args)"
1891 if [[ ${?} != 0 ]]; then
1892 eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
1893 die "java-pkg_javac-args failed"
1894 fi
1669 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 1895 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
1896 export JAVACFLAGS
1670 1897
1671 export JAVA_HOME="$(java-config -g JAVA_HOME)" 1898 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1672 export JDK_HOME=${JAVA_HOME} 1899 export JDK_HOME=${JAVA_HOME}
1673 1900
1674 #TODO If you know a better solution let us know. 1901 #TODO If you know a better solution let us know.
1675 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 1902 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1676 1903
1677 local tann="${T}/announced-vm" 1904 local tann="${T}/announced-vm"
1678 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 1905 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1679 # Add a check for setup/preinst phase... to avoid duplicate outputs 1906 # Add a check for setup/preinst phase... to avoid duplicate outputs
1680 # for when FEATURES=buildpkg 1907 # for when FEATURES=buildpkg
1681 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]]; 1908 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1706 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2 1933 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2
1707 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2 1934 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2
1708 echo "and of course, the output of emerge --info" >&2 1935 echo "and of course, the output of emerge --info" >&2
1709} 1936}
1710 1937
1938
1939# TODO document
1940# List jars in the source directory, ${S}
1941java-pkg_jar-list() {
1942 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
1943 einfo "Linked Jars"
1944 find "${S}" -type l -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1945 einfo "Jars"
1946 find "${S}" -type f -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1947 einfo "Classes"
1948 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1949 fi
1950}
1951
1952# TODO document
1953# Verify that the classes were compiled for the right source / target
1954java-pkg_verify-classes() {
1955 ebegin "Verifying java class versions"
1956 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1957 class-version-verify.py -t $(java-pkg_get-target) -r ${D}
1958 result=$?
1959 eend ${result}
1960 if [[ ${result} == 0 ]]; then
1961 einfo "All good"
1962 else
1963 ewarn "Possible problem"
1964 die "Bad class files found"
1965 fi
1966}
1967
1711# ------------------------------------------------------------------------------ 1968# ------------------------------------------------------------------------------
1712# @section-end internal 1969# @section-end internal
1713# ------------------------------------------------------------------------------ 1970# ------------------------------------------------------------------------------
1714 1971
1715java-pkg_check-phase() { 1972java-pkg_check-phase() {
1716 local phase=${1} 1973 local phase=${1}
1717 local funcname=${2} 1974 local funcname=${2}
1718 # TODO add check for java-stricter
1719 if [[ ${EBUILD_PHASE} != ${phase} ]]; then 1975 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then
1720 java-pkg_announce-qa-violation \ 1976 java-pkg_announce-qa-violation \
1721 "${funcname} used outside of src_${phase}" 1977 "${funcname} used outside of src_${phase}"
1722 fi 1978 fi
1723} 1979}
1724 1980
1735 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 1991 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1736 fi 1992 fi
1737} 1993}
1738 1994
1739java-pkg_announce-qa-violation() { 1995java-pkg_announce-qa-violation() {
1740 if hasq java-strict ${FEATURES}; then 1996 if is-java-strict; then
1741 echo "Java QA Notice: $@" >&2 1997 echo "Java QA Notice: $@" >&2
1742 increment-qa-violations 1998 increment-qa-violations
1743 fi 1999 fi
1744} 2000}
1745 2001
1746increment-qa-violations() { 2002increment-qa-violations() {
1747 let "JAVA_PKG_QA_VIOLATIONS+=1" 2003 let "JAVA_PKG_QA_VIOLATIONS+=1"
1748 export JAVA_PKG_QA_VIOLATIONS 2004 export JAVA_PKG_QA_VIOLATIONS
1749} 2005}
1750 2006
2007is-java-strict() {
2008 [[ -n ${JAVA_PKG_STRICT} ]]
2009 return $?
2010}
2011
1751# ------------------------------------------------------------------------------ 2012# ------------------------------------------------------------------------------
1752# @eclass-end 2013# @eclass-end
1753# ------------------------------------------------------------------------------ 2014# ------------------------------------------------------------------------------

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.40

  ViewVC Help
Powered by ViewVC 1.1.20