/[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.10 Revision 1.45
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.45 2007/01/20 20:50:33 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#
40 43
41# ----------------------------------------------------------------------------- 44# -----------------------------------------------------------------------------
42# @variable-internal JAVA_PKG_E_DEPEND 45# @variable-internal JAVA_PKG_E_DEPEND
43# 46#
44# 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
45# 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
46# portage, that includes phase hooks. 49# portage, that includes phase hooks.
47# ----------------------------------------------------------------------------- 50# -----------------------------------------------------------------------------
48JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 ${JAVA_PKG_PORTAGE_DEP}" 51JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 ${JAVA_PKG_PORTAGE_DEP}"
49 52
50# ----------------------------------------------------------------------------- 53# -----------------------------------------------------------------------------
100# ----------------------------------------------------------------------------- 103# -----------------------------------------------------------------------------
101 104
102# ----------------------------------------------------------------------------- 105# -----------------------------------------------------------------------------
103# @variable-internal JAVA_PKG_COMPILER_DIR 106# @variable-internal JAVA_PKG_COMPILER_DIR
104# @default /usr/share/java-config-2/compiler 107# @default /usr/share/java-config-2/compiler
105# 108#
106# Directory where compiler settings are saved, without trailing slash. 109# Directory where compiler settings are saved, without trailing slash.
107# Probably shouldn't touch this variable. 110# Probably shouldn't touch this variable.
108# ----------------------------------------------------------------------------- 111# -----------------------------------------------------------------------------
109JAVA_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"}
110 113
120 123
121# ----------------------------------------------------------------------------- 124# -----------------------------------------------------------------------------
122# @variable-external JAVA_PKG_FORCE_COMPILER 125# @variable-external JAVA_PKG_FORCE_COMPILER
123# 126#
124# 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
125# JAVA_PKG_COMPILERS_CONF. 128# JAVA_PKG_COMPILERS_CONF.
126# 129#
127# @note This should only be used internally or for testing. 130# @note This should only be used internally or for testing.
128# @example Use jikes and javac, in that order 131# @example Use jikes and javac, in that order
129# JAVA_PKG_FORCE_COMPILER="jikes javac" 132# JAVA_PKG_FORCE_COMPILER="jikes javac"
130# ----------------------------------------------------------------------------- 133# -----------------------------------------------------------------------------
150# @ebuild-function java-pkg_dojar 153# @ebuild-function java-pkg_dojar
151# 154#
152# Installs any number of jars. 155# Installs any number of jars.
153# 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.
154# You can use java-pkg_jarinto to change this path. 157# You can use java-pkg_jarinto to change this path.
155# 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.
156# Instead, use java-pkg_newjar defined below. 159# Instead, use java-pkg_newjar defined below.
157# 160#
158# @example 161# @example
159# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar 162# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar
160# 163#
171 # Create JARDEST if it doesn't exist 174 # Create JARDEST if it doesn't exist
172 dodir ${JAVA_PKG_JARDEST} 175 dodir ${JAVA_PKG_JARDEST}
173 176
174 local jar 177 local jar
175 # for each jar 178 # for each jar
176 for jar in "$@"; do 179 for jar in ${@}; do
177 local jar_basename=$(basename "${jar}") 180 local jar_basename=$(basename "${jar}")
178 181
179 java-pkg_check-versioned-jar ${jar_basename} 182 java-pkg_check-versioned-jar ${jar_basename}
180 183
181 # check if it exists 184 # check if it exists
182 if [[ -e "${jar}" ]] ; then 185 if [[ -e "${jar}" ]] ; then
186 # Don't overwrite if jar has already been installed with the same
187 # name
188 local dest="${D}${JAVA_PKG_JARDEST}/${jar_basename}"
189 if [[ -e "${dest}" ]]; then
190 ewarn "Overwriting ${dest}"
191 fi
192
183 # install it into JARDEST if it's a non-symlink 193 # install it into JARDEST if it's a non-symlink
184 if [[ ! -L "${jar}" ]] ; then 194 if [[ ! -L "${jar}" ]] ; then
185 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 195 INSDESTTREE="${JAVA_PKG_JARDEST}" \
186 doins "${jar}" || die "failed to install ${jar}" 196 doins "${jar}" || die "failed to install ${jar}"
187 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 197 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
200 210
201 java-pkg_do_write_ 211 java-pkg_do_write_
202} 212}
203 213
204 214
215# ------------------------------------------------------------------------------
216# @internal-function depend-java-query
217#
218# Wrapper for the depend-java-query binary to enable passing USE in env.
219# Using env variables keeps this eclass working with java-config versions that
220# do not handle use flags.
221# ------------------------------------------------------------------------------
222
223depend-java-query() {
224 USE="${USE}" $(which depend-java-query) "${@}"
225}
205 226
206# ------------------------------------------------------------------------------ 227# ------------------------------------------------------------------------------
207# @ebuild-function java-pkg_regjar 228# @ebuild-function java-pkg_regjar
208# 229#
209# Records an already installed jar in the package.env 230# Records an already installed jar in the package.env
222# will not work, because: 243# will not work, because:
223# * the `for jar in "$@"` can't expand the path to jar file names, as they 244# * the `for jar in "$@"` can't expand the path to jar file names, as they
224# don't exist yet 245# don't exist yet
225# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar' 246# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar'
226# doesn't exist 247# doesn't exist
227# 248#
228# you have to use it as: 249# you have to use it as:
229# 250#
230# java-pkg_regjar ${D}/opt/my-java/lib/*.jar 251# java-pkg_regjar ${D}/opt/my-java/lib/*.jar
231# 252#
232# @param $@ - jars to record 253# @param $@ - jars to record
240 [[ ${#} -lt 1 ]] && die "at least one argument needed" 261 [[ ${#} -lt 1 ]] && die "at least one argument needed"
241 262
242 java-pkg_init_paths_ 263 java-pkg_init_paths_
243 264
244 local jar jar_dir jar_file 265 local jar jar_dir jar_file
245 for jar in "$@"; do 266 for jar in ${@}; do
246 # TODO use java-pkg_check-versioned-jar 267 # TODO use java-pkg_check-versioned-jar
247 if [[ -e "${jar}" ]]; then 268 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
269 [[ -d "${jar}" || -d "${D}${jar}" ]] \
270 && die "Called ${FUNCNAME} on a directory $*"
248 # nelchael: we should strip ${D} in this case too, here's why: 271 # nelchael: we should strip ${D} in this case too, here's why:
249 # imagine such call: 272 # imagine such call:
250 # java-pkg_regjar ${D}/opt/java/*.jar 273 # java-pkg_regjar ${D}/opt/java/*.jar
251 # such call will fall into this case (-e ${jar}) and will 274 # such call will fall into this case (-e ${jar}) and will
252 # record paths with ${D} in package.env 275 # record paths with ${D} in package.env
253 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 276 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
254 elif [[ -e "${D}${jar}" ]]; then
255 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
256 else 277 else
257 die "${jar} does not exist" 278 die "${jar} does not exist"
258 fi 279 fi
259 done 280 done
260 281
261 java-pkg_do_write_ 282 java-pkg_do_write_
262} 283}
263
264 284
265# ------------------------------------------------------------------------------ 285# ------------------------------------------------------------------------------
266# @ebuild-function java-pkg_newjar 286# @ebuild-function java-pkg_newjar
267# 287#
268# Installs a jar with a new name 288# Installs a jar with a new name
279 local original_jar="${1}" 299 local original_jar="${1}"
280 local new_jar="${2:-${PN}.jar}" 300 local new_jar="${2:-${PN}.jar}"
281 local new_jar_dest="${T}/${new_jar}" 301 local new_jar_dest="${T}/${new_jar}"
282 302
283 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 303 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
284 [[ ! -f ${original_jar} ]] && die "${original_jar} does not exist!" 304 [[ ! -f ${original_jar} ]] \
305 && die "${original_jar} does not exist or is not a file!"
285 306
286 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 307 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
287 cp "${original_jar}" "${new_jar_dest}" \ 308 cp "${original_jar}" "${new_jar_dest}" \
288 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 309 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
289 java-pkg_dojar "${new_jar_dest}" 310 java-pkg_dojar "${new_jar_dest}"
290} 311}
291 312
292
293# ------------------------------------------------------------------------------ 313# ------------------------------------------------------------------------------
294# @ebuild-function java-pkg_addcp 314# @ebuild-function java-pkg_addcp
295# 315#
296# Add something to the package's classpath. For jars, you should use dojar, 316# Add something to the package's classpath. For jars, you should use dojar,
297# newjar, or regjar. This is typically used to add directories to the classpath. 317# newjar, or regjar. This is typically used to add directories to the classpath.
302java-pkg_addcp() { 322java-pkg_addcp() {
303 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}" 323 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
304 java-pkg_do_write_ 324 java-pkg_do_write_
305} 325}
306 326
307
308# ------------------------------------------------------------------------------ 327# ------------------------------------------------------------------------------
309# @ebuild-function java-pkg_doso 328# @ebuild-function java-pkg_doso
310# 329#
311# Installs any number of JNI libraries 330# Installs any number of JNI libraries
312# They will be installed into /usr/lib by default, but java-pkg_sointo 331# They will be installed into /usr/lib by default, but java-pkg_sointo
313# can be used change this path 332# can be used change this path
314# 333#
315# Example: 334# Example:
370 java-pkg_check-phase install 389 java-pkg_check-phase install
371 390
372 [[ ${#} -lt 1 ]] && "at least one argument needed" 391 [[ ${#} -lt 1 ]] && "at least one argument needed"
373 392
374 java-pkg_init_paths_ 393 java-pkg_init_paths_
375 394
376 local lib target_dir 395 local lib target_dir
377 for lib in "$@" ; do 396 for lib in "$@" ; do
378 # Check the absolute path of the lib 397 # Check the absolute path of the lib
379 if [[ -e "${lib}" ]] ; then 398 if [[ -e "${lib}" ]] ; then
380 target_dir="$(java-pkg_expand_dir_ ${lib})" 399 target_dir="$(java-pkg_expand_dir_ ${lib})"
428# ------------------------------------------------------------------------------ 447# ------------------------------------------------------------------------------
429java-pkg_dohtml() { 448java-pkg_dohtml() {
430 debug-print-function ${FUNCNAME} $* 449 debug-print-function ${FUNCNAME} $*
431 450
432 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 451 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
433 # TODO-nichoj find out what exactly -f package-list does 452
453 # from /usr/lib/portage/bin/dohtml -h
454 # -f Set list of allowed extensionless file names.
434 dohtml -f package-list "$@" 455 dohtml -f package-list "$@"
456
435 # this probably shouldn't be here but it provides 457 # this probably shouldn't be here but it provides
436 # a reasonable way to catch # docs for all of the 458 # a reasonable way to catch # docs for all of the
437 # old ebuilds. 459 # old ebuilds.
438 java-pkg_recordjavadoc 460 java-pkg_recordjavadoc
439} 461}
440 462
441# TODO document 463# ------------------------------------------------------------------------------
464# @ebuild-function java-pkg_dojavadoc
465#
466# Installs javadoc documentation. This should be controlled by the doc use flag.
467#
468# @param $1: - The javadoc root directory.
469#
470# @example:
471# java-pkg_dojavadoc docs/api
472#
473# ------------------------------------------------------------------------------
442java-pkg_dojavadoc() { 474java-pkg_dojavadoc() {
443 local dir="$1" 475 local dir="$1"
444 476
445 java-pkg_check-phase install 477 java-pkg_check-phase install
446 478
458} 490}
459 491
460# ------------------------------------------------------------------------------ 492# ------------------------------------------------------------------------------
461# @ebuild-function java-pkg_dosrc 493# @ebuild-function java-pkg_dosrc
462# 494#
463# Installs a zip containing the source for a package, so it can used in 495# Installs a zip containing the source for a package, so it can used in
464# from IDEs like eclipse and netbeans. 496# from IDEs like eclipse and netbeans.
465# 497#
466# Ebuild needs to DEPEND on app-arch/zip to use this. 498# Ebuild needs to DEPEND on app-arch/zip to use this.
467# 499#
468# It also should be controlled by USE=source. 500# It also should be controlled by USE=source.
469# 501#
470# @example: 502# @example:
471# java-pkg_dosrc src/* 503# java-pkg_dosrc src/*
472# 504#
473# ------------------------------------------------------------------------------ 505# ------------------------------------------------------------------------------
474# TODO change so it the arguments it takes are the base directories containing 506# TODO change so it the arguments it takes are the base directories containing
475# source -nichoj 507# source -nichoj
476# TODO should we be able to handle multiple calls to dosrc? -nichoj 508# TODO should we be able to handle multiple calls to dosrc? -nichoj
477# TODO maybe we can take an existing zip/jar? -nichoj 509# TODO maybe we can take an existing zip/jar? -nichoj
478# FIXME apparently this fails if you give it an empty directories 510# FIXME apparently this fails if you give it an empty directories
479java-pkg_dosrc() { 511java-pkg_dosrc() {
480 debug-print-function ${FUNCNAME} $* 512 debug-print-function ${FUNCNAME} $*
481 513
482 [ ${#} -lt 1 ] && die "At least one argument needed" 514 [ ${#} -lt 1 ] && die "At least one argument needed"
483 if ! hasq source ${IUSE}; then 515 if ! hasq source ${IUSE}; then
484 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE" 516 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
485 fi 517 fi
486 518
487 java-pkg_check-phase install 519 java-pkg_check-phase install
488 520
489 [[ ${#} -lt 1 ]] && die "At least one argument needed" 521 [[ ${#} -lt 1 ]] && die "At least one argument needed"
490 522
491 java-pkg_init_paths_ 523 java-pkg_init_paths_
492 524
493 local zip_name="${PN}-src.zip" 525 local zip_name="${PN}-src.zip"
494 local zip_path="${T}/${zip_name}" 526 local zip_path="${T}/${zip_name}"
518# @ebuild-function java-pkg_dolauncher 550# @ebuild-function java-pkg_dolauncher
519# 551#
520# Make a wrapper script to lauch/start this package 552# Make a wrapper script to lauch/start this package
521# If necessary, the wrapper will switch to the appropriate VM. 553# If necessary, the wrapper will switch to the appropriate VM.
522# 554#
555# Can be called without parameters if the package installs only one jar
556# that has the Main-class attribute set. The wrapper will be named ${PN}.
557#
523# @param $1 - filename of launcher to create 558# @param $1 - filename of launcher to create
524# @param $2 - options, as follows: 559# @param $2 - options, as follows:
525# --main the.main.class.too.start 560# --main the.main.class.too.start
526# --jar /the/jar/too/launch.jar 561# --jar /the/jar/too/launch.jar or just <name>.jar
527# --java_args 'Extra arguments to pass too jave' 562# --java_args 'Extra arguments to pass to java'
528# --pkg_args 'extra arguments too pass too the package' 563# --pkg_args 'Extra arguments to pass to the package'
529# --pwd 564# --pwd Directory the launcher changes to before executing java
530# -into 565# -into Directory to install the launcher to, instead of /usr/bin
531# -pre 566# -pre Prepend contents of this file to the launcher
532# ------------------------------------------------------------------------------ 567# ------------------------------------------------------------------------------
533java-pkg_dolauncher() { 568java-pkg_dolauncher() {
534 debug-print-function ${FUNCNAME} $* 569 debug-print-function ${FUNCNAME} $*
535 570
536 java-pkg_check-phase install 571 java-pkg_check-phase install
537
538 [[ ${#} -lt 1 ]] && die "Need at least one argument"
539
540 java-pkg_init_paths_ 572 java-pkg_init_paths_
541 573
574 if [[ ${#} = 0 ]]; then
575 local name="${PN}"
576 else
542 local name="${1}" 577 local name="${1}"
578 shift
579 fi
580
543 # TODO rename to launcher 581 # TODO rename to launcher
544 local target="${T}/${name}" 582 local target="${T}/${name}"
583 local var_tmp="${T}/launcher_variables_tmp"
545 local target_dir pre 584 local target_dir pre
546 shift
547 585
548 echo "#!/bin/bash" > "${target}" 586 # Process the other the rest of the arguments
549 while [[ -n "${1}" && -n "${2}" ]]; do 587 while [[ -n "${1}" && -n "${2}" ]]; do
550 local var=${1} value=${2} 588 local var="${1}" value="${2}"
551 if [[ "${var:0:2}" == "--" ]]; then 589 if [[ "${var:0:2}" == "--" ]]; then
590 local var=${var:2}
552 echo "gjl_${var:2}=\"${value}\"" >> "${target}" 591 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
592 local gjl_${var}="${value}"
553 elif [[ "${var}" == "-into" ]]; then 593 elif [[ "${var}" == "-into" ]]; then
554 target_dir="${value}" 594 target_dir="${value}"
555 elif [[ "${var}" == "-pre" ]]; then 595 elif [[ "${var}" == "-pre" ]]; then
556 pre="${value}" 596 pre="${value}"
557 fi 597 fi
558 shift 2 598 shift 2
559 done 599 done
600
601 # Test if no --jar and --main arguments were given and
602 # in that case check if the package only installs one jar
603 # and use that jar.
604 if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
605 local cp="${JAVA_PKG_CLASSPATH}"
606 if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
607 echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
608 else
609 local msg="Not enough information to create a launcher given."
610 msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
611 die "${msg}"
612 fi
613 fi
614
615 # Write the actual script
616 echo "#!/bin/bash" > "${target}"
617 if [[ -n "${pre}" ]]; then
618 if [[ -f "${pre}" ]]; then
619 cat "${pre}" >> "${target}"
620 else
621 die "-pre specified file '${pre}' does not exist"
622 fi
623 fi
560 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 624 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
561 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 625 cat "${var_tmp}" >> "${target}"
626 rm -f "${var_tmp}"
562 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 627 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
563 628
564 if [[ -n "${into}" ]]; then 629 if [[ -n "${target_dir}" ]]; then
565 DESTTREE="${target_dir}" dobin "${target}" 630 DESTTREE="${target_dir}" dobin "${target}"
566 local ret=$? 631 local ret=$?
567 return ${ret} 632 return ${ret}
568 else 633 else
569 dobin "${target}" 634 dobin "${target}"
597 echo "dowar: warning, skipping directory ${war}" 662 echo "dowar: warning, skipping directory ${war}"
598 continue 663 continue
599 else 664 else
600 warpath="${war}" 665 warpath="${war}"
601 fi 666 fi
602 667
603 # Install those files like you mean it 668 # Install those files like you mean it
604 INSOPTIONS="-m 0644" \ 669 INSOPTIONS="-m 0644" \
605 INSDESTTREE=${JAVA_PKG_WARDEST} \ 670 INSDESTTREE=${JAVA_PKG_WARDEST} \
606 doins ${warpath} 671 doins ${warpath}
607 done 672 done
642# @ebuild-function java-pkg_jar-from 707# @ebuild-function java-pkg_jar-from
643# 708#
644# Makes a symlink to a jar from a certain package 709# Makes a symlink to a jar from a certain package
645# A lot of java packages include dependencies in a lib/ directory 710# A lot of java packages include dependencies in a lib/ directory
646# You can use this function to replace these bundled dependencies. 711# You can use this function to replace these bundled dependencies.
712# The dependency is recorded into package.env DEPEND line, unless "--build-only"
713# is passed as the very first argument, for jars that have to be present only
714# at build time and are not needed on runtime (junit testing etc).
647# 715#
648# Example: get all jars from xerces slot 2 716# Example: get all jars from xerces slot 2
649# java-pkg_jar-from xerces-2 717# java-pkg_jar-from xerces-2
650# Example: get a specific jar from xerces slot 2 718# Example: get a specific jar from xerces slot 2
651# java-pkg_jar-from xerces-2 xml-apis.jar 719# java-pkg_jar-from xerces-2 xml-apis.jar
652# Example get a specific jar from xerces slot 2, and name it diffrently 720# Example: get a specific jar from xerces slot 2, and name it diffrently
653# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 721# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
722# Example: get junit.jar which is needed only for building
723# java-pkg_jar-from --build-only junit junit.jar
654# 724#
725# @param $1 - (optional) "--build-only" makes the jar(s) not added into
726# package.env DEPEND line.
655# @param $1 - Package to get jars from. 727# @param $1 - Package to get jars from.
656# @param $2 - jar from package. If not specified, all jars will be used. 728# @param $2 - jar from package. If not specified, all jars will be used.
657# @param $3 - When a single jar is specified, destination filename of the 729# @param $3 - When a single jar is specified, destination filename of the
658# symlink. Defaults to the name of the jar. 730# symlink. Defaults to the name of the jar.
659# ------------------------------------------------------------------------------ 731# ------------------------------------------------------------------------------
660# TODO could probably be cleaned up a little 732# TODO could probably be cleaned up a little
661java-pkg_jar-from() { 733java-pkg_jar-from() {
662 debug-print-function ${FUNCNAME} $* 734 debug-print-function ${FUNCNAME} $*
663 735
736 local build_only=""
737
738 if [[ "${1}" = "--build-only" ]]; then
739 build_only="true"
740 shift
741 fi
742
743 if [[ "${1}" = "--with-dependencies" ]]; then
744 local deep="--with-dependencies"
745 shift
746 fi
747
664 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 748 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
665 749
666 [[ -z ${target_pkg} ]] && die "Must specify a package" 750 [[ -z ${target_pkg} ]] && die "Must specify a package"
667 751
668 # default destjar to the target jar 752 # default destjar to the target jar
669 [[ -z "${destjar}" ]] && destjar="${target_jar}" 753 [[ -z "${destjar}" ]] && destjar="${target_jar}"
670 754
755 local error_msg="There was a problem getting the classpath for ${target_pkg}."
756 local classpath
671 local classpath="$(java-config --classpath=${target_pkg})" 757 classpath="$(java-config ${deep} --classpath=${target_pkg})"
672 [[ $? != 0 ]] && die "There was a problem getting the classpath for ${target_pkg}" 758 [[ $? != 0 ]] && die ${error_msg}
673 759
674 local jar 760 local jar
675 for jar in ${classpath//:/ }; do 761 for jar in ${classpath//:/ }; do
676 local jar_name=$(basename "${jar}") 762 local jar_name=$(basename "${jar}")
677 if [[ ! -f "${jar}" ]] ; then 763 if [[ ! -f "${jar}" ]] ; then
681 # If no specific target jar was indicated, link it 767 # If no specific target jar was indicated, link it
682 if [[ -z "${target_jar}" ]] ; then 768 if [[ -z "${target_jar}" ]] ; then
683 [[ -f "${target_jar}" ]] && rm "${target_jar}" 769 [[ -f "${target_jar}" ]] && rm "${target_jar}"
684 ln -snf "${jar}" \ 770 ln -snf "${jar}" \
685 || die "Failed to make symlink from ${jar} to ${jar_name}" 771 || die "Failed to make symlink from ${jar} to ${jar_name}"
686 java-pkg_record-jar_ "${target_pkg}" "${jar}" 772 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
687 # otherwise, if the current jar is the target jar, link it 773 # otherwise, if the current jar is the target jar, link it
688 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 774 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
689 [[ -f "${destjar}" ]] && rm "${destjar}" 775 [[ -f "${destjar}" ]] && rm "${destjar}"
690 ln -snf "${jar}" "${destjar}" \ 776 ln -snf "${jar}" "${destjar}" \
691 || die "Failed to make symlink from ${jar} to ${destjar}" 777 || die "Failed to make symlink from ${jar} to ${destjar}"
692 java-pkg_record-jar_ "${target_pkg}" "${jar}" 778 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
693 return 0 779 return 0
694 fi 780 fi
695 done 781 done
696 # if no target was specified, we're ok 782 # if no target was specified, we're ok
697 if [[ -z "${target_jar}" ]] ; then 783 if [[ -z "${target_jar}" ]] ; then
714# ------------------------------------------------------------------------------ 800# ------------------------------------------------------------------------------
715# @ebuild-function java-pkg_getjars 801# @ebuild-function java-pkg_getjars
716# 802#
717# Get the classpath provided by any number of packages 803# Get the classpath provided by any number of packages
718# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'. 804# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
805# The providing packages are recorded as dependencies into package.env DEPEND
806# line, unless "--build-only" is passed as the very first argument, for jars
807# that have to be present only at build time and are not needed on runtime
808# (junit testing etc).
719# 809#
720# Example: Get the classpath for xerces-2, 810# Example: Get the classpath for xerces-2 and xalan,
721# java-pkg_getjars xerces-2 xalan 811# java-pkg_getjars xerces-2,xalan
722# Example Return: 812# Example Return:
723# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 813# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
724# 814#
815# @param $1 - (optional) "--build-only" makes the jar(s) not added into
816# package.env DEPEND line.
725# @param $@ - list of packages to get jars from 817# @param $2 - list of packages to get jars from
818# (passed to java-config --classpath)
726# ------------------------------------------------------------------------------ 819# ------------------------------------------------------------------------------
727java-pkg_getjars() { 820java-pkg_getjars() {
728 debug-print-function ${FUNCNAME} $* 821 debug-print-function ${FUNCNAME} $*
729 822
730 [[ ${#} -lt 1 ]] && die "At least one argument needed" 823 if [[ "${1}" = "--build-only" ]]; then
824 local build_only="true"
825 shift
826 fi
731 827
732 # NOTE could probably just pass $@ to java-config --classpath. and return it 828 if [[ "${1}" = "--with-dependencies" ]]; then
829 local deep="--with-dependencies"
830 shift
831 fi
832
833 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --build-only"
834
733 local classpath pkg 835 local classpath pkgs="${1}"
734 for pkg in ${@//,/ }; do
735 #for pkg in $(echo "$@" | tr ',' ' '); do
736 jars="$(java-config --classpath=${pkg})" 836 jars="$(java-config ${deep} --classpath=${pkgs})"
837 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed"
737 debug-print "${pkg}:${jars}" 838 debug-print "${pkgs}:${jars}"
738 # TODO should we ensure jars exist? 839
739 if [[ -z "${classpath}" ]]; then 840 if [[ -z "${classpath}" ]]; then
740 classpath="${jars}" 841 classpath="${jars}"
741 else 842 else
742 classpath="${classpath}:${jars}" 843 classpath="${classpath}:${jars}"
743 fi 844 fi
845
846 # Only record jars that aren't build-only
847 if [[ -z "${build_only}" ]]; then
848 oldifs="${IFS}"
849 IFS=","
850 for pkg in ${pkgs}; do
744 java-pkg_record-jar_ "${pkg}" 851 java-pkg_record-jar_ "${pkg}"
745 done 852 done
853 IFS="${oldifs}"
854 fi
855
746 echo "${classpath}" 856 echo "${classpath}"
747} 857}
748 858
749# ------------------------------------------------------------------------------ 859# ------------------------------------------------------------------------------
750# @ebuild-function java-pkg_getjar 860# @ebuild-function java-pkg_getjar
751# 861#
752# Get the filename of a single jar from a package 862# Get the filename of a single jar from a package
863# The providing package is recorded as runtime dependency into package.env
864# DEPEND line, unless "--build-only" is passed as the very first argument, for
865# jars that have to be present only at build time and are not needed on runtime
866# (junit testing etc).
753# 867#
754# @example 868# @example
755# java-pkg_getjar xerces-2 xml-apis.jar 869# java-pkg_getjar xerces-2 xml-apis.jar
756# @example-return 870# @example-return
757# /usr/share/xerces-2/lib/xml-apis.jar 871# /usr/share/xerces-2/lib/xml-apis.jar
758# 872#
873# @param $1 - (optional) "--build-only" makes the jar not added into
874# package.env DEPEND line.
759# @param $1 - package to use 875# @param $1 - package to use
760# @param $2 - jar to get 876# @param $2 - jar to get
761# ------------------------------------------------------------------------------ 877# ------------------------------------------------------------------------------
762java-pkg_getjar() { 878java-pkg_getjar() {
763 debug-print-function ${FUNCNAME} $* 879 debug-print-function ${FUNCNAME} $*
880
881 local build_only=""
882
883 if [[ "${1}" = "--build-only" ]]; then
884 build_only="true"
885 shift
886 fi
764 887
765 local pkg="${1}" target_jar="${2}" jar 888 local pkg="${1}" target_jar="${2}" jar
766 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 889 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
767 [[ -z ${target_jar} ]] && die "Must specify jar to get" 890 [[ -z ${target_jar} ]] && die "Must specify jar to get"
768 891
769 # TODO check that package is actually installed 892 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
893 local classpath
770 local classpath=$(java-config --classpath=${pkg}) 894 classpath=$(java-config --classpath=${pkg})
771 [[ $? != 0 ]] && die "There could not find classpath for ${pkg}. Are you sure its installed?" 895 [[ $? != 0 ]] && die ${error_msg}
896
772 for jar in ${classpath//:/ }; do 897 for jar in ${classpath//:/ }; do
773 if [[ ! -f "${jar}" ]] ; then 898 if [[ ! -f "${jar}" ]] ; then
774 die "Installation problems with jars in ${pkg} - is it installed?" 899 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
775 fi 900 fi
776 901
777 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then 902 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
778 java-pkg_record-jar_ "${pkg}" "${jar}" 903 # Only record jars that aren't build-only
904 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" "${jar}"
779 echo "${jar}" 905 echo "${jar}"
780 return 0 906 return 0
781 fi 907 fi
782 done 908 done
783 909
784 die "Could not find ${target_jar} in ${pkg}" 910 die "Could not find ${target_jar} in ${pkg}"
785 return 1 911 return 1
786} 912}
787 913
788# This function reads stdin, and based on that input, figures out how to 914# This function reads stdin, and based on that input, figures out how to
802# line="${line// /}" 928# line="${line// /}"
803# 929#
804# # format: path=jarinfo 930# # format: path=jarinfo
805# local path=${line%%=*} 931# local path=${line%%=*}
806# local jarinfo=${line##*=} 932# local jarinfo=${line##*=}
807# 933#
808# # format: jar@package 934# # format: jar@package
809# local jar=${jarinfo%%@*}.jar 935# local jar=${jarinfo%%@*}.jar
810# local package=${jarinfo##*@} 936# local package=${jarinfo##*@}
811# if [[ -n ${replace_only} ]]; then 937# if [[ -n ${replace_only} ]]; then
812# [[ ! -f $path ]] && die "No jar exists at ${path}" 938# [[ ! -f $path ]] && die "No jar exists at ${path}"
825# @section-end query 951# @section-end query
826# ------------------------------------------------------------------------------ 952# ------------------------------------------------------------------------------
827 953
828# ------------------------------------------------------------------------------ 954# ------------------------------------------------------------------------------
829# @section-begin helper 955# @section-begin helper
830# @section-summary Helper functions 956# @section-summary Helper functions
831# 957#
832# Various other functions to use from an ebuild 958# Various other functions to use from an ebuild
833# ------------------------------------------------------------------------------ 959# ------------------------------------------------------------------------------
834 960
835# ------------------------------------------------------------------------------ 961# ------------------------------------------------------------------------------
841# jdbc-stdext 967# jdbc-stdext
842# jaf 968# jaf
843# jdbc-rowset 969# jdbc-rowset
844# jms 970# jms
845# 971#
846# @param $1 - Optionally indicate that the dependencies are controlled by 972# @param $1 - Optionally indicate that the dependencies are controlled by
847# a use flag by specifying '--use' Requires $2. 973# a use flag by specifying '--use' Requires $2.
848# @param $2 - USE flag which will enable the dependencies. 974# @param $2 - USE flag which will enable the dependencies.
849# @param $@ - virtual packages to add depenedencies for 975# @param $@ - virtual packages to add depenedencies for
850# ------------------------------------------------------------------------------ 976# ------------------------------------------------------------------------------
851# TODO rewrite to parse a line based declaration file instead -- karltk 977# TODO rewrite to parse a line based declaration file instead -- karltk
907# 1033#
908# export DEPEND="${DEPEND} ${depstr}" 1034# export DEPEND="${DEPEND} ${depstr}"
909# export RDEPEND="${RDEPEND} ${depstr}" 1035# export RDEPEND="${RDEPEND} ${depstr}"
910#} 1036#}
911 1037
1038# ------------------------------------------------------------------------------
1039# @ebuild-function java-pkg_find-normal-jars
1040#
1041# Find the files with suffix .jar file in the given directory or $WORKDIR
1042#
1043# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1044# ------------------------------------------------------------------------------
1045java-pkg_find-normal-jars() {
1046 local dir=$1
1047 [[ "${dir}" ]] || dir="${WORKDIR}"
1048 local found
1049 for jar in $(find "${dir}" -name "*.jar" -type f); do
1050 echo "${jar}"
1051 found="true"
1052 done
1053 [[ "${found}" ]]
1054 return $?
1055}
1056
1057# ------------------------------------------------------------------------------
1058# @ebuild-function java-pkg_ensure-no-bundled-jars
1059#
1060# Try to locate bundled jar files in ${WORKDIR} and die if found.
912# This should be used after S has been populated with symlinks to jars 1061# This function should be called after WORKDIR has been populated with symlink
913# TODO document 1062# to system jar files or bundled jars removed.
1063# ------------------------------------------------------------------------------
914java-pkg_ensure-no-bundled-jars() { 1064java-pkg_ensure-no-bundled-jars() {
915 debug-print-function ${FUNCNAME} $* 1065 debug-print-function ${FUNCNAME} $*
916 pushd ${WORKDIR} >/dev/null 2>/dev/null
917 1066
918 local bundled_jars=$(find . -name "*.jar" -type f) 1067 local bundled_jars=$(java-pkg_find-normal-jars)
919 if [[ -n ${bundled_jars} ]]; then 1068 if [[ -n ${bundled_jars} ]]; then
920 echo "Bundled jars found:" 1069 echo "Bundled jars found:"
921 local jar 1070 local jar
922 for jar in ${bundled_jars}; do 1071 for jar in ${bundled_jars}; do
923 echo $(pwd)${jar/./} 1072 echo $(pwd)${jar/./}
924 done 1073 done
925 die "Bundled jars found!" 1074 die "Bundled jars found!"
926
927 fi 1075 fi
928 popd >/dev/null 2>/dev/null
929} 1076}
930 1077
931# ------------------------------------------------------------------------------ 1078# ------------------------------------------------------------------------------
932# @internal-function java-pkg_ensure-vm-version-sufficient 1079# @internal-function java-pkg_ensure-vm-version-sufficient
933# 1080#
945 fi 1092 fi
946} 1093}
947 1094
948# ------------------------------------------------------------------------------ 1095# ------------------------------------------------------------------------------
949# @internal-function java-pkg_is-vm-version-sufficient 1096# @internal-function java-pkg_is-vm-version-sufficient
950# 1097#
951# @return zero - VM is sufficient 1098# @return zero - VM is sufficient
952# @return non-zero - VM is not sufficient 1099# @return non-zero - VM is not sufficient
953# ------------------------------------------------------------------------------ 1100# ------------------------------------------------------------------------------
954java-pkg_is-vm-version-sufficient() { 1101java-pkg_is-vm-version-sufficient() {
955 debug-print-function ${FUNCNAME} $* 1102 debug-print-function ${FUNCNAME} $*
975 die "Active Java VM too old" 1122 die "Active Java VM too old"
976 fi 1123 fi
977} 1124}
978 1125
979# ------------------------------------------------------------------------------ 1126# ------------------------------------------------------------------------------
980# @internal-function java-pkg_is-vm-version-eq 1127# @internal-function java-pkg_is-vm-version-eq
981# 1128#
982# @param $@ - VM version to compare current VM to 1129# @param $@ - VM version to compare current VM to
983# @return zero - VM versions are equal 1130# @return zero - VM versions are equal
984# @return non-zero - VM version are not equal 1131# @return non-zero - VM version are not equal
985# ------------------------------------------------------------------------------ 1132# ------------------------------------------------------------------------------
986java-pkg_is-vm-version-eq() { 1133java-pkg_is-vm-version-eq() {
1016# 1163#
1017# @param $@ - VM version to compare current to 1164# @param $@ - VM version to compare current to
1018# ------------------------------------------------------------------------------ 1165# ------------------------------------------------------------------------------
1019java-pkg_ensure-vm-version-ge() { 1166java-pkg_ensure-vm-version-ge() {
1020 debug-print-function ${FUNCNAME} $* 1167 debug-print-function ${FUNCNAME} $*
1021 1168
1022 if ! java-pkg_is-vm-version-ge "$@" ; then 1169 if ! java-pkg_is-vm-version-ge "$@" ; then
1023 debug-print "vm is not suffient" 1170 debug-print "vm is not suffient"
1024 eerror "This package requires a Java VM version >= $@" 1171 eerror "This package requires a Java VM version >= $@"
1025 einfo "Please use java-config -S to set the correct one" 1172 einfo "Please use java-config -S to set the correct one"
1026 die "Active Java VM too old" 1173 die "Active Java VM too old"
1027 fi 1174 fi
1028} 1175}
1029 1176
1030# ------------------------------------------------------------------------------ 1177# ------------------------------------------------------------------------------
1031# @internal-function java-pkg_is-vm-version-ge 1178# @internal-function java-pkg_is-vm-version-ge
1032# 1179#
1033# @param $@ - VM version to compare current VM to 1180# @param $@ - VM version to compare current VM to
1034# @return zero - current VM version is greater than checked version 1181# @return zero - current VM version is greater than checked version
1035# @return non-zero - current VM version is not greater than checked version 1182# @return non-zero - current VM version is not greater than checked version
1036# ------------------------------------------------------------------------------ 1183# ------------------------------------------------------------------------------
1037java-pkg_is-vm-version-ge() { 1184java-pkg_is-vm-version-ge() {
1051 return 1 1198 return 1
1052 fi 1199 fi
1053 fi 1200 fi
1054} 1201}
1055 1202
1203java-pkg_set-current-vm() {
1204 export GENTOO_VM=${1}
1205}
1206
1207java-pkg_get-current-vm() {
1208 echo ${GENTOO_VM}
1209}
1210
1211java-pkg_current-vm-matches() {
1212 hasq $(java-pkg_get-current-vm) ${@}
1213 return $?
1214}
1215
1056# ------------------------------------------------------------------------------ 1216# ------------------------------------------------------------------------------
1057# @ebuild-function java-pkg_get-source 1217# @ebuild-function java-pkg_get-source
1058# 1218#
1059# Determines what source version should be used, for passing to -source. 1219# Determines what source version should be used, for passing to -source.
1060# Unless you want to break things you probably shouldn't set _WANT_SOURCE 1220# Unless you want to break things you probably shouldn't set _WANT_SOURCE
1061# 1221#
1062# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE 1222# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1063# ------------------------------------------------------------------------------ 1223# ------------------------------------------------------------------------------
1068# ------------------------------------------------------------------------------ 1228# ------------------------------------------------------------------------------
1069# @ebuild-function java-pkg_get-target 1229# @ebuild-function java-pkg_get-target
1070# 1230#
1071# Determines what target version should be used, for passing to -target. 1231# Determines what target version should be used, for passing to -target.
1072# If you don't care about lower versions, you can set _WANT_TARGET to the 1232# If you don't care about lower versions, you can set _WANT_TARGET to the
1073# version of your JDK. 1233# version of your JDK.
1074# Remember doing this will mostly like cause things to break.
1075# Doesn't allow it to be lower then the one in depend.
1076# Doesn't allow it to be higher then the active vm.
1077# 1234#
1078# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1235# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1079# ------------------------------------------------------------------------------ 1236# ------------------------------------------------------------------------------
1080java-pkg_get-target() { 1237java-pkg_get-target() {
1081 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")
1082 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then
1083 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)"
1084 if version_is_at_least "${min}" "${JAVA_PKG_WANT_TARGET}" && version_is_at_least "${JAVA_PKG_WANT_TARGET}" "${max}"; then
1085 echo ${JAVA_PKG_WANT_TARGET}
1086 else
1087 echo ${min}
1088 fi
1089 else
1090 echo ${min}
1091 fi
1092
1093 #echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND}")} 1238 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1094} 1239}
1095 1240
1096java-pkg_get-javac() { 1241java-pkg_get-javac() {
1097 debug-print-function ${FUNCNAME} $* 1242 debug-print-function ${FUNCNAME} $*
1098 1243
1099 java-pkg_init-compiler_ 1244
1100 local compiler="${GENTOO_COMPILER}" 1245 local compiler="${GENTOO_COMPILER}"
1101 1246
1102 local compiler_executable 1247 local compiler_executable
1103 if [[ "${compiler}" = "javac" ]]; then 1248 if [[ "${compiler}" = "javac" ]]; then
1104 # nothing fancy needs to be done for javac 1249 # nothing fancy needs to be done for javac
1112 unset JAVAC 1257 unset JAVAC
1113 # try to get value of JAVAC 1258 # try to get value of JAVAC
1114 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1259 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1115 export JAVAC=${old_javac} 1260 export JAVAC=${old_javac}
1116 1261
1117 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1262 if [[ -z ${compiler_executable} ]]; then
1118 1263 echo "JAVAC is empty or undefined in ${compiler_env}"
1264 return 1
1265 fi
1266
1119 # check that it's executable 1267 # check that it's executable
1120 if [[ ! -x ${compiler_executable} ]]; then 1268 if [[ ! -x ${compiler_executable} ]]; then
1121 eerror "Could not find ${compiler_executable}!"
1122 die "${compiler_executable} doesn't exist, or isn't executable" 1269 echo "${compiler_executable} doesn't exist, or isn't executable"
1270 return 1
1123 fi 1271 fi
1124 else 1272 else
1125 eerror "Could not find environment file for ${compiler}" 1273 echo "Could not find environment file for ${compiler}"
1126 die "Could not find ${compiler_env}" 1274 return 1
1127 fi 1275 fi
1128 fi 1276 fi
1129 echo ${compiler_executable} 1277 echo ${compiler_executable}
1130} 1278}
1131 1279
1132# ------------------------------------------------------------------------------ 1280# ------------------------------------------------------------------------------
1133# @ebuild-function java-pkg_javac-args 1281# @ebuild-function java-pkg_javac-args
1134# 1282#
1135# If an ebuild uses javac directly, instead of using ejavac, it should call this 1283# If an ebuild uses javac directly, instead of using ejavac, it should call this
1136# to know what -source/-target to use. 1284# to know what -source/-target to use.
1137# 1285#
1138# @return string - arguments to pass to javac, complete with -target and -source 1286# @return string - arguments to pass to javac, complete with -target and -source
1141 debug-print-function ${FUNCNAME} $* 1289 debug-print-function ${FUNCNAME} $*
1142 1290
1143 local want_source="$(java-pkg_get-source)" 1291 local want_source="$(java-pkg_get-source)"
1144 local want_target="$(java-pkg_get-target)" 1292 local want_target="$(java-pkg_get-target)"
1145 1293
1146 local source_str="-source ${want_source}" 1294 local source_str="-source ${want_source}"
1147 local target_str="-target ${want_target}" 1295 local target_str="-target ${want_target}"
1148 1296
1149 debug-print "want source: ${want_source}" 1297 debug-print "want source: ${want_source}"
1150 debug-print "want target: ${want_target}" 1298 debug-print "want target: ${want_target}"
1151 1299
1152 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1300 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1153 debug-print "could not find valid -source/-target values" 1301 debug-print "could not find valid -source/-target values for javac"
1154 die "Could not find valid -source/-target values" 1302 echo "Could not find valid -source/-target values for javac"
1303 return 1
1155 else 1304 else
1156 if java-pkg_is-vm-version-ge "1.4"; then 1305 if java-pkg_is-vm-version-ge "1.4"; then
1157 echo "${source_str} ${target_str}" 1306 echo "${source_str} ${target_str}"
1158 else 1307 else
1159 echo "${target_str}" 1308 echo "${target_str}"
1163 1312
1164# TODO document 1313# TODO document
1165java-pkg_get-jni-cflags() { 1314java-pkg_get-jni-cflags() {
1166 local flags="-I${JAVA_HOME}/include" 1315 local flags="-I${JAVA_HOME}/include"
1167 1316
1317 local platform="linux"
1318 use elibc_FreeBSD && platform="freebsd"
1319
1168 # TODO do a check that the directories are valid 1320 # TODO do a check that the directories are valid
1169 # TODO figure out how to cope with other things than linux...
1170 flags="${flags} -I${JAVA_HOME}/include/linux" 1321 flags="${flags} -I${JAVA_HOME}/include/${platform}"
1171 1322
1172 echo ${flags} 1323 echo ${flags}
1173} 1324}
1174 1325
1175java-pkg_ensure-gcj() { 1326java-pkg_ensure-gcj() {
1180 ebeep 5 1331 ebeep 5
1181 die "No GCJ support found!" 1332 die "No GCJ support found!"
1182 fi 1333 fi
1183} 1334}
1184 1335
1336java-pkg_ensure-test() {
1337 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \
1338 && hasq test ${IUSE} && ! use test;
1339 then
1340 eerror "You specified FEATURES=test, but USE=test is needed"
1341 eerror "to pull in the additional dependencies for testing"
1342 die "Need USE=test enabled"
1343 fi
1344}
1345
1185# ------------------------------------------------------------------------------ 1346# ------------------------------------------------------------------------------
1186# @section-end helper 1347# @section-end helper
1187# ------------------------------------------------------------------------------ 1348# ------------------------------------------------------------------------------
1188 1349
1189# ------------------------------------------------------------------------------ 1350# ------------------------------------------------------------------------------
1197# ------------------------------------------------------------------------------ 1358# ------------------------------------------------------------------------------
1198# @ebuild-function eant 1359# @ebuild-function eant
1199# 1360#
1200# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1361# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1201# compiler. 1362# compiler.
1363# variables:
1364# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1365# gentoo.classpath property. Be sure to call
1366# java-ant_rewrite-classpath in src_unpack.
1202# 1367#
1203# ------------------------------------------------------------------------------ 1368# ------------------------------------------------------------------------------
1204eant() { 1369eant() {
1205 debug-print-function ${FUNCNAME} $* 1370 debug-print-function ${FUNCNAME} $*
1206 1371
1207 local antflags 1372 # FIXME get this working
1373# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then
1374# java-pkg_announce-qa-violation \
1375# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1376# fi
1377
1378 local antflags="-Dnoget=true"
1208 java-pkg_init-compiler_ 1379 java-pkg_init-compiler_
1209 local compiler="${GENTOO_COMPILER}" 1380 local compiler="${GENTOO_COMPILER}"
1210 1381
1211 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1382 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1212 1383
1214 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1385 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1215 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1386 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1216 fi 1387 fi
1217 1388
1218 if [[ ${compiler} != "javac" ]]; then 1389 if [[ ${compiler} != "javac" ]]; then
1219 antflags="-Dbuild.compiler=${build_compiler}" 1390 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1220 # Figure out any extra stuff to put on the classpath for compilers aside 1391 # Figure out any extra stuff to put on the classpath for compilers aside
1221 # from javac 1392 # from javac
1222 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to 1393 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1223 # java-config -p 1394 # java-config -p
1224 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1395 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})"
1229 1400
1230 if is-java-strict; then 1401 if is-java-strict; then
1231 einfo "Disabling system classpath for ant" 1402 einfo "Disabling system classpath for ant"
1232 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1403 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1233 fi 1404 fi
1234 1405
1235 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1406 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} -debug"
1236 antflags="${antflags} -debug" 1407 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1408
1409 local gcp="${EANT_GENTOO_CLASSPATH}"
1410
1411 if [[ "${gcp}" ]]; then
1412 local cp="$(java-pkg_getjars ${gcp})"
1413 # It seems ant does not like single quotes around ${cp}
1414 antflags="${antflags} -Dgentoo.classpath=\"${cp}\""
1237 fi 1415 fi
1238 1416
1239 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1417 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1418 debug-print "Calling ant: ${antflags} ${@}"
1240 ant ${antflags} "${@}" || die "eant failed" 1419 ant ${antflags} "${@}" || die "eant failed"
1241 1420
1242} 1421}
1243 1422
1244# ------------------------------------------------------------------------------ 1423# ------------------------------------------------------------------------------
1245# @ebuild-function ejavac 1424# @ebuild-function ejavac
1246# 1425#
1247# Javac wrapper function. Will use the appropriate compiler, based on 1426# Javac wrapper function. Will use the appropriate compiler, based on
1248# /etc/java-config/compilers.conf 1427# /etc/java-config/compilers.conf
1249# 1428#
1250# @param $@ - Arguments to be passed to the compiler 1429# @param $@ - Arguments to be passed to the compiler
1251# ------------------------------------------------------------------------------ 1430# ------------------------------------------------------------------------------
1252ejavac() { 1431ejavac() {
1253 debug-print-function ${FUNCNAME} $* 1432 debug-print-function ${FUNCNAME} $*
1254 1433
1255 # FIXME using get-javac ends up printing stuff with einfo 1434 java-pkg_init-compiler_
1435
1436 local compiler_executable
1256# local compiler_executable=$(java-pkg_get-javac) 1437 compiler_executable=$(java-pkg_get-javac)
1257 local compiler_executable="javac" 1438 if [[ ${?} != 0 ]]; then
1439 eerror "There was a problem determining compiler: ${compiler_executable}"
1440 die "get-javac failed"
1441 fi
1258 1442
1443 local javac_args
1444 javac_args="$(java-pkg_javac-args)"
1445 if [[ ${?} != 0 ]]; then
1446 eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
1447 die "java-pkg_javac-args failed"
1448 fi
1449
1259 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 1450 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1260 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 1451 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1261} 1452}
1262 1453
1263# ------------------------------------------------------------------------------ 1454# ------------------------------------------------------------------------------
1264# @ebuild-function java-pkg_filter-compiler 1455# @ebuild-function java-pkg_filter-compiler
1265# 1456#
1266# Used to prevent the use of some compilers. Should be used in src_compile. 1457# Used to prevent the use of some compilers. Should be used in src_compile.
1267# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER 1458# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
1268# 1459#
1269# @param $@ - compilers to filter 1460# @param $@ - compilers to filter
1270# ------------------------------------------------------------------------------ 1461# ------------------------------------------------------------------------------
1288# ------------------------------------------------------------------------------ 1479# ------------------------------------------------------------------------------
1289# @ebuild-function use_doc 1480# @ebuild-function use_doc
1290# 1481#
1291# Helper function for getting ant to build javadocs. If the user has USE=doc, 1482# Helper function for getting ant to build javadocs. If the user has USE=doc,
1292# then 'javadoc' or the argument are returned. Otherwise, there is no return. 1483# then 'javadoc' or the argument are returned. Otherwise, there is no return.
1293# 1484#
1294# The output of this should be passed to ant. 1485# The output of this should be passed to ant.
1295# 1486#
1296# Example: build javadocs by calling 'javadoc' target 1487# Example: build javadocs by calling 'javadoc' target
1297# eant $(use_doc) 1488# eant $(use_doc)
1298# Example: build javadocs by calling 'apidoc' target 1489# Example: build javadocs by calling 'apidoc' target
1303# ------------------------------------------------------------------------------ 1494# ------------------------------------------------------------------------------
1304use_doc() { 1495use_doc() {
1305 use doc && echo ${@:-javadoc} 1496 use doc && echo ${@:-javadoc}
1306} 1497}
1307 1498
1499
1308# ------------------------------------------------------------------------------ 1500# ------------------------------------------------------------------------------
1309# @section-end build 1501# @section-end build
1310# ------------------------------------------------------------------------------ 1502# ------------------------------------------------------------------------------
1311 1503
1312# ------------------------------------------------------------------------------ 1504# ------------------------------------------------------------------------------
1313# @section-begin internal 1505# @section-begin internal
1314# @section-summary Internal functions 1506# @section-summary Internal functions
1315# 1507#
1316# Do __NOT__ use any of these from an ebuild! These are only to be used from 1508# Do __NOT__ use any of these from an ebuild! These are only to be used from
1317# within the java eclasses. 1509# within the java eclasses.
1318# ------------------------------------------------------------------------------ 1510# ------------------------------------------------------------------------------
1319 1511
1320# ----------------------------------------------------------------------------- 1512# -----------------------------------------------------------------------------
1321# @function-internal java-pkg_init 1513# @function-internal java-pkg_init
1322# 1514#
1323# The purpose of this function, as the name might imply, is to initialize the 1515# The purpose of this function, as the name might imply, is to initialize the
1324# Java environment. It ensures that that there aren't any environment variables 1516# Java environment. It ensures that that there aren't any environment variables
1325# that'll muss things up. It initializes some variables, which are used 1517# that'll muss things up. It initializes some variables, which are used
1326# internally. And most importantly, it'll switch the VM if necessary. 1518# internally. And most importantly, it'll switch the VM if necessary.
1327# 1519#
1339 # TODO we will probably want to set JAVAC and JAVACFLAGS 1531 # TODO we will probably want to set JAVAC and JAVACFLAGS
1340 1532
1341 # Do some QA checks 1533 # Do some QA checks
1342 java-pkg_check-jikes 1534 java-pkg_check-jikes
1343 1535
1344 # When users have crazy classpaths some packages can fail to compile. 1536 # When users have crazy classpaths some packages can fail to compile.
1345 # and everything should work with empty CLASSPATH. 1537 # and everything should work with empty CLASSPATH.
1346 # This also helps prevent unexpected dependencies on random things 1538 # This also helps prevent unexpected dependencies on random things
1347 # from the CLASSPATH. 1539 # from the CLASSPATH.
1348 unset CLASSPATH 1540 unset CLASSPATH
1349} 1541}
1350 1542
1351# ------------------------------------------------------------------------------ 1543# ------------------------------------------------------------------------------
1352# @function-internal java-pkg-init-compiler_ 1544# @function-internal java-pkg-init-compiler_
1353# 1545#
1354# This function attempts to figure out what compiler should be used. It does 1546# This function attempts to figure out what compiler should be used. It does
1355# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the 1547# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
1356# COMPILERS variable defined there. 1548# COMPILERS variable defined there.
1357# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER 1549# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
1358# 1550#
1359# It will go through the list of compilers, and verify that it supports the 1551# It will go through the list of compilers, and verify that it supports the
1360# target and source that are needed. If it is not suitable, then the next 1552# target and source that are needed. If it is not suitable, then the next
1361# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking 1553# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
1362# isn't done. 1554# isn't done.
1363# 1555#
1385 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1577 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1386 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})" 1578 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
1387 else 1579 else
1388 compilers=${JAVA_PKG_FORCE_COMPILER} 1580 compilers=${JAVA_PKG_FORCE_COMPILER}
1389 fi 1581 fi
1390 1582
1391 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}" 1583 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
1392 1584
1393 # Figure out if we should announce what compiler we're using 1585 # Figure out if we should announce what compiler we're using
1394 local compiler 1586 local compiler
1395 for compiler in ${compilers}; do 1587 for compiler in ${compilers}; do
1398 if [[ ${compiler} = "javac" ]]; then 1590 if [[ ${compiler} = "javac" ]]; then
1399 debug-print "Found javac... breaking" 1591 debug-print "Found javac... breaking"
1400 export GENTOO_COMPILER="javac" 1592 export GENTOO_COMPILER="javac"
1401 break 1593 break
1402 fi 1594 fi
1403 1595
1404 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then 1596 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
1405 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1597 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1406 einfo "Filtering ${compiler}" 1598 einfo "Filtering ${compiler}"
1407 continue 1599 continue
1408 fi 1600 fi
1409 fi 1601 fi
1410 1602
1411 # for non-javac, we need to make sure it supports the right target and 1603 # for non-javac, we need to make sure it supports the right target and
1412 # source 1604 # source
1413 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1605 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1414 if [[ -f ${compiler_env} ]]; then 1606 if [[ -f ${compiler_env} ]]; then
1415 local desired_target="$(java-pkg_get-target)" 1607 local desired_target="$(java-pkg_get-target)"
1497# Writes the package.env out to disk. 1689# Writes the package.env out to disk.
1498# 1690#
1499# ------------------------------------------------------------------------------ 1691# ------------------------------------------------------------------------------
1500# TODO change to do-write, to match everything else 1692# TODO change to do-write, to match everything else
1501java-pkg_do_write_() { 1693java-pkg_do_write_() {
1694 java-pkg_init_paths_
1502 # Create directory for package.env 1695 # Create directory for package.env
1503 dodir "${JAVA_PKG_SHAREPATH}" 1696 dodir "${JAVA_PKG_SHAREPATH}"
1504 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 1697 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then
1505 # Create package.env 1698 # Create package.env
1506 ( 1699 (
1511 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 1704 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1512 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 1705 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1513 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 1706 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\""
1514 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 1707 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1515 ) > "${JAVA_PKG_ENV}" 1708 ) > "${JAVA_PKG_ENV}"
1516 1709
1517 # register target/source 1710 # register target/source
1518 local target="$(java-pkg_get-target)" 1711 local target="$(java-pkg_get-target)"
1519 local source="$(java-pkg_get-source)" 1712 local source="$(java-pkg_get-source)"
1520 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}" 1713 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
1521 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}" 1714 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
1534 # Strip unnecessary leading and trailing colons 1727 # Strip unnecessary leading and trailing colons
1535 # TODO try to cleanup if possible 1728 # TODO try to cleanup if possible
1536 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 1729 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
1537 fi 1730 fi
1538} 1731}
1539
1540 1732
1541# ------------------------------------------------------------------------------ 1733# ------------------------------------------------------------------------------
1542# @internal-function java-pkg_record-jar_ 1734# @internal-function java-pkg_record-jar_
1543# 1735#
1544# Record a dependency to the package.env 1736# Record a dependency to the package.env
1588 fi 1780 fi
1589} 1781}
1590 1782
1591# ------------------------------------------------------------------------------ 1783# ------------------------------------------------------------------------------
1592# @internal-function java-pkg_expand_dir_ 1784# @internal-function java-pkg_expand_dir_
1593# 1785#
1594# Gets the full path of the file/directory's parent. 1786# Gets the full path of the file/directory's parent.
1595# @param $1 - file/directory to find parent directory for 1787# @param $1 - file/directory to find parent directory for
1596# @return - path to $1's parent directory 1788# @return - path to $1's parent directory
1597# ------------------------------------------------------------------------------ 1789# ------------------------------------------------------------------------------
1598java-pkg_expand_dir_() { 1790java-pkg_expand_dir_() {
1625# ------------------------------------------------------------------------------ 1817# ------------------------------------------------------------------------------
1626java-pkg_setup-vm() { 1818java-pkg_setup-vm() {
1627 debug-print-function ${FUNCNAME} $* 1819 debug-print-function ${FUNCNAME} $*
1628 1820
1629 local vendor="$(java-pkg_get-vm-vendor)" 1821 local vendor="$(java-pkg_get-vm-vendor)"
1630 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge 1 5; then 1822 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1631 addpredict "/dev/random" 1823 addpredict "/dev/random"
1632 elif [[ "${vendor}" == "ibm" ]]; then 1824 elif [[ "${vendor}" == "ibm" ]]; then
1633 addpredict "/proc/self/maps" 1825 addpredict "/proc/self/maps"
1634 addpredict "/proc/cpuinfo" 1826 addpredict "/proc/cpuinfo"
1635 export LANG="C" LC_ALL="C" 1827 export LANG="C" LC_ALL="C"
1684# @return - The version of the current VM 1876# @return - The version of the current VM
1685# ------------------------------------------------------------------------------ 1877# ------------------------------------------------------------------------------
1686java-pkg_get-vm-version() { 1878java-pkg_get-vm-version() {
1687 debug-print-function ${FUNCNAME} $* 1879 debug-print-function ${FUNCNAME} $*
1688 1880
1689 java-pkg_get-current-vm | sed -e "s/.*-\([0-9.]\+\).*/\1/" 1881 java-config -g PROVIDES_VERSION
1690} 1882}
1691 1883
1692# ------------------------------------------------------------------------------ 1884# ------------------------------------------------------------------------------
1693# @internal-function java-pkg_switch-vm 1885# @internal-function java-pkg_switch-vm
1694# 1886#
1695# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 1887# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1696# verify that the current VM is sufficient. 1888# verify that the current VM is sufficient.
1697# Setup the environment for the VM being used. 1889# Setup the environment for the VM being used.
1698# ------------------------------------------------------------------------------ 1890# ------------------------------------------------------------------------------
1699java-pkg_switch-vm() { 1891java-pkg_switch-vm() {
1892 debug-print-function ${FUNCNAME} $*
1893
1700 if java-pkg_needs-vm; then 1894 if java-pkg_needs-vm; then
1701 # Use the VM specified by JAVA_PKG_FORCE_VM 1895 # Use the VM specified by JAVA_PKG_FORCE_VM
1702 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then 1896 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1703 # If you're forcing the VM, I hope you know what your doing... 1897 # If you're forcing the VM, I hope you know what your doing...
1898 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1704 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 1899 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1705 # if we're allowed to switch the vm... 1900 # if we're allowed to switch the vm...
1706 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 1901 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1707 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}" 1902 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1708 if [[ -n ${JAVA_PKG_VNEED} ]]; then 1903 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1709 export GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 1904 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1710 else 1905 else
1711 export GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 1906 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1907 fi
1908 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
1909 eerror "Unable to determine VM for building from dependencies:"
1910 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
1911 echo "VNEED: ${JAVA_PKG_VNEED}"
1912 die "Failed to determine VM for building."
1913 else
1914 export GENTOO_VM
1712 fi 1915 fi
1713 # otherwise just make sure the current VM is sufficient 1916 # otherwise just make sure the current VM is sufficient
1714 else 1917 else
1715 java-pkg_ensure-vm-version-sufficient 1918 java-pkg_ensure-vm-version-sufficient
1716 fi 1919 fi
1717 debug-print "Using: $(java-config -f)" 1920 debug-print "Using: $(java-config -f)"
1718 1921
1719 java-pkg_setup-vm 1922 java-pkg_setup-vm
1720 1923
1721 export JAVA=$(java-config --java) 1924 export JAVA=$(java-config --java)
1722 export JAVAC=$(java-config --javac) 1925 export JAVAC=$(java-config --javac)
1723 export JAVACFLAGS="$(java-pkg_javac-args)" 1926 JAVACFLAGS="$(java-pkg_javac-args)"
1927 if [[ ${?} != 0 ]]; then
1928 eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
1929 die "java-pkg_javac-args failed"
1930 fi
1724 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 1931 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
1932 export JAVACFLAGS
1725 1933
1726 export JAVA_HOME="$(java-config -g JAVA_HOME)" 1934 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1727 export JDK_HOME=${JAVA_HOME} 1935 export JDK_HOME=${JAVA_HOME}
1728 1936
1729 #TODO If you know a better solution let us know. 1937 #TODO If you know a better solution let us know.
1730 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 1938 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1731 1939
1732 local tann="${T}/announced-vm" 1940 local tann="${T}/announced-vm"
1733 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 1941 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1734 # Add a check for setup/preinst phase... to avoid duplicate outputs 1942 # Add a check for setup/preinst phase... to avoid duplicate outputs
1735 # for when FEATURES=buildpkg 1943 # for when FEATURES=buildpkg
1736 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]]; 1944 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1780# TODO document 1988# TODO document
1781# Verify that the classes were compiled for the right source / target 1989# Verify that the classes were compiled for the right source / target
1782java-pkg_verify-classes() { 1990java-pkg_verify-classes() {
1783 ebegin "Verifying java class versions" 1991 ebegin "Verifying java class versions"
1784 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 1992 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1785 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 1993 class-version-verify.py -t $(java-pkg_get-target) -r ${D}
1786 result=$? 1994 result=$?
1787 eend ${result} 1995 eend ${result}
1788 if [[ ${result} == 0 ]]; then 1996 if [[ ${result} == 0 ]]; then
1789 einfo "All good" 1997 einfo "All good"
1790 else 1998 else
1791 ewarn "Possible problem" 1999 ewarn "Possible problem"
1792 die "Bad class files found" 2000 die "Bad class files found"
1793 fi 2001 fi
1794} 2002}
1795 2003
1796
1797# ------------------------------------------------------------------------------ 2004# ------------------------------------------------------------------------------
1798# @section-end internal 2005# @section-end internal
1799# ------------------------------------------------------------------------------ 2006# ------------------------------------------------------------------------------
1800 2007
1801java-pkg_check-phase() { 2008java-pkg_check-phase() {
1832 let "JAVA_PKG_QA_VIOLATIONS+=1" 2039 let "JAVA_PKG_QA_VIOLATIONS+=1"
1833 export JAVA_PKG_QA_VIOLATIONS 2040 export JAVA_PKG_QA_VIOLATIONS
1834} 2041}
1835 2042
1836is-java-strict() { 2043is-java-strict() {
1837 hasq java-strict ${FEATURES}; 2044 [[ -n ${JAVA_PKG_STRICT} ]]
1838 return $? 2045 return $?
1839} 2046}
1840 2047
1841# ------------------------------------------------------------------------------ 2048# ------------------------------------------------------------------------------
1842# @eclass-end 2049# @eclass-end

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.45

  ViewVC Help
Powered by ViewVC 1.1.20