/[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.2 Revision 1.43
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.43 2007/01/15 21:03:24 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
179 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
180 # install it into JARDEST if it's a non-symlink 193 # install it into JARDEST if it's a non-symlink
181 if [[ ! -L "${jar}" ]] ; then 194 if [[ ! -L "${jar}" ]] ; then
182 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 195 INSDESTTREE="${JAVA_PKG_JARDEST}" \
183 doins "${jar}" || die "failed to install ${jar}" 196 doins "${jar}" || die "failed to install ${jar}"
184 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 197 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
197 210
198 java-pkg_do_write_ 211 java-pkg_do_write_
199} 212}
200 213
201 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}
202 226
203# ------------------------------------------------------------------------------ 227# ------------------------------------------------------------------------------
204# @ebuild-function java-pkg_regjar 228# @ebuild-function java-pkg_regjar
205# 229#
206# Records an already installed jar in the package.env 230# 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 231# This would mostly be used if the package has make or a custom script to
208# install things. 232# install things.
209# 233#
210# Example: 234# Example:
211# java-pkg-regjar ${D}/opt/foo/lib/foo.jar 235# java-pkg_regjar ${D}/opt/foo/lib/foo.jar
236#
237# WARNING:
238# if you want to use shell expansion, you have to use ${D}/... as the for in
239# this function will not be able to expand the path, here's an example:
240#
241# java-pkg_regjar /opt/my-java/lib/*.jar
242#
243# will not work, because:
244# * the `for jar in "$@"` can't expand the path to jar file names, as they
245# don't exist yet
246# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar'
247# doesn't exist
248#
249# you have to use it as:
250#
251# java-pkg_regjar ${D}/opt/my-java/lib/*.jar
212# 252#
213# @param $@ - jars to record 253# @param $@ - jars to record
214# ------------------------------------------------------------------------------ 254# ------------------------------------------------------------------------------
215# TODO fix me! 255# TODO should we be making sure the jar is present on ${D} or wherever?
216java-pkg_regjar() { 256java-pkg_regjar() {
217 debug-print-function ${FUNCNAME} $* 257 debug-print-function ${FUNCNAME} $*
218 258
219 java-pkg_check-phase install 259 java-pkg_check-phase install
220 260
221 [[ ${#} -lt 1 ]] && die "at least one argument needed" 261 [[ ${#} -lt 1 ]] && die "at least one argument needed"
222 262
223 java-pkg_init_paths_ 263 java-pkg_init_paths_
224 264
225 local jar jar_dir jar_file 265 local jar jar_dir jar_file
226 for jar in "$@"; do 266 for jar in ${@}; do
227 # TODO use java-pkg_check-versioned-jar 267 # 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 268 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
269 [[ -d "${jar}" || -d "${D}${jar}" ]] \
270 && die "Called ${FUNCNAME} on a directory $*"
271 # nelchael: we should strip ${D} in this case too, here's why:
272 # imagine such call:
273 # java-pkg_regjar ${D}/opt/java/*.jar
274 # such call will fall into this case (-e ${jar}) and will
275 # record paths with ${D} in package.env
231 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 276 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
232 else 277 else
233 die "${jar} does not exist" 278 die "${jar} does not exist"
234 fi 279 fi
235 done 280 done
236 281
237 java-pkg_do_write_ 282 java-pkg_do_write_
238} 283}
239 284
240
241# ------------------------------------------------------------------------------ 285# ------------------------------------------------------------------------------
242# @ebuild-function java-pkg_newjar 286# @ebuild-function java-pkg_newjar
243# 287#
244# Installs a jar with a new name 288# Installs a jar with a new name
245# 289#
255 local original_jar="${1}" 299 local original_jar="${1}"
256 local new_jar="${2:-${PN}.jar}" 300 local new_jar="${2:-${PN}.jar}"
257 local new_jar_dest="${T}/${new_jar}" 301 local new_jar_dest="${T}/${new_jar}"
258 302
259 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 303 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
260 [[ ! -f ${original_jar} ]] && die "${new_jar} does not exist!" 304 [[ ! -f ${original_jar} ]] && die "${original_jar} does not exist!"
261 305
262 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 306 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
263 cp "${original_jar}" "${new_jar_dest}" \ 307 cp "${original_jar}" "${new_jar_dest}" \
264 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 308 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
265 java-pkg_dojar "${new_jar_dest}" 309 java-pkg_dojar "${new_jar_dest}"
266} 310}
267 311
268
269# ------------------------------------------------------------------------------ 312# ------------------------------------------------------------------------------
270# @ebuild-function java-pkg_addcp 313# @ebuild-function java-pkg_addcp
271# 314#
272# Add something to the package's classpath. For jars, you should use dojar, 315# 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. 316# newjar, or regjar. This is typically used to add directories to the classpath.
278java-pkg_addcp() { 321java-pkg_addcp() {
279 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}" 322 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
280 java-pkg_do_write_ 323 java-pkg_do_write_
281} 324}
282 325
283
284# ------------------------------------------------------------------------------ 326# ------------------------------------------------------------------------------
285# @ebuild-function java-pkg_doso 327# @ebuild-function java-pkg_doso
286# 328#
287# Installs any number of JNI libraries 329# Installs any number of JNI libraries
288# They will be installed into /usr/lib by default, but java-pkg_sointo 330# They will be installed into /usr/lib by default, but java-pkg_sointo
289# can be used change this path 331# can be used change this path
290# 332#
291# Example: 333# Example:
346 java-pkg_check-phase install 388 java-pkg_check-phase install
347 389
348 [[ ${#} -lt 1 ]] && "at least one argument needed" 390 [[ ${#} -lt 1 ]] && "at least one argument needed"
349 391
350 java-pkg_init_paths_ 392 java-pkg_init_paths_
351 393
352 local lib target_dir 394 local lib target_dir
353 for lib in "$@" ; do 395 for lib in "$@" ; do
354 # Check the absolute path of the lib 396 # Check the absolute path of the lib
355 if [[ -e "${lib}" ]] ; then 397 if [[ -e "${lib}" ]] ; then
356 target_dir="$(java-pkg_expand_dir_ ${lib})" 398 target_dir="$(java-pkg_expand_dir_ ${lib})"
404# ------------------------------------------------------------------------------ 446# ------------------------------------------------------------------------------
405java-pkg_dohtml() { 447java-pkg_dohtml() {
406 debug-print-function ${FUNCNAME} $* 448 debug-print-function ${FUNCNAME} $*
407 449
408 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 450 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
409 # TODO-nichoj find out what exactly -f package-list does 451
452 # from /usr/lib/portage/bin/dohtml -h
453 # -f Set list of allowed extensionless file names.
410 dohtml -f package-list "$@" 454 dohtml -f package-list "$@"
455
411 # this probably shouldn't be here but it provides 456 # this probably shouldn't be here but it provides
412 # a reasonable way to catch # docs for all of the 457 # a reasonable way to catch # docs for all of the
413 # old ebuilds. 458 # old ebuilds.
414 java-pkg_recordjavadoc 459 java-pkg_recordjavadoc
415} 460}
416 461
417# TODO document 462# ------------------------------------------------------------------------------
463# @ebuild-function java-pkg_dojavadoc
464#
465# Installs javadoc documentation. This should be controlled by the doc use flag.
466#
467# @param $1: - The javadoc root directory.
468#
469# @example:
470# java-pkg_dojavadoc docs/api
471#
472# ------------------------------------------------------------------------------
418java-pkg_dojavadoc() { 473java-pkg_dojavadoc() {
419 local dir="$1" 474 local dir="$1"
420 475
421 java-pkg_check-phase install 476 java-pkg_check-phase install
422 477
434} 489}
435 490
436# ------------------------------------------------------------------------------ 491# ------------------------------------------------------------------------------
437# @ebuild-function java-pkg_dosrc 492# @ebuild-function java-pkg_dosrc
438# 493#
439# Installs a zip containing the source for a package, so it can used in 494# Installs a zip containing the source for a package, so it can used in
440# from IDEs like eclipse and netbeans. 495# from IDEs like eclipse and netbeans.
441# 496#
442# Ebuild needs to DEPEND on app-arch/zip to use this. 497# Ebuild needs to DEPEND on app-arch/zip to use this.
443# 498#
444# It also should be controlled by USE=source. 499# It also should be controlled by USE=source.
445# 500#
446# @example: 501# @example:
447# java-pkg_dosrc src/* 502# java-pkg_dosrc src/*
448# 503#
449# ------------------------------------------------------------------------------ 504# ------------------------------------------------------------------------------
450# TODO change so it the arguments it takes are the base directories containing 505# TODO change so it the arguments it takes are the base directories containing
451# source -nichoj 506# source -nichoj
452# TODO should we be able to handle multiple calls to dosrc? -nichoj 507# TODO should we be able to handle multiple calls to dosrc? -nichoj
453# TODO maybe we can take an existing zip/jar? -nichoj 508# TODO maybe we can take an existing zip/jar? -nichoj
454# FIXME apparently this fails if you give it an empty directories 509# FIXME apparently this fails if you give it an empty directories
455java-pkg_dosrc() { 510java-pkg_dosrc() {
456 debug-print-function ${FUNCNAME} $* 511 debug-print-function ${FUNCNAME} $*
457 512
458 [ ${#} -lt 1 ] && die "At least one argument needed" 513 [ ${#} -lt 1 ] && die "At least one argument needed"
459 if ! hasq source ${IUSE}; then 514 if ! hasq source ${IUSE}; then
460 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE" 515 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
461 fi 516 fi
462 517
463 java-pkg_check-phase install 518 java-pkg_check-phase install
464 519
465 [[ ${#} -lt 1 ]] && die "At least one argument needed" 520 [[ ${#} -lt 1 ]] && die "At least one argument needed"
466 521
467 java-pkg_init_paths_ 522 java-pkg_init_paths_
468 523
469 local zip_name="${PN}-src.zip" 524 local zip_name="${PN}-src.zip"
470 local zip_path="${T}/${zip_name}" 525 local zip_path="${T}/${zip_name}"
494# @ebuild-function java-pkg_dolauncher 549# @ebuild-function java-pkg_dolauncher
495# 550#
496# Make a wrapper script to lauch/start this package 551# Make a wrapper script to lauch/start this package
497# If necessary, the wrapper will switch to the appropriate VM. 552# If necessary, the wrapper will switch to the appropriate VM.
498# 553#
554# Can be called without parameters if the package installs only one jar
555# that has the Main-class attribute set. The wrapper will be named ${PN}.
556#
499# @param $1 - filename of launcher to create 557# @param $1 - filename of launcher to create
500# @param $2 - options, as follows: 558# @param $2 - options, as follows:
501# --main the.main.class.too.start 559# --main the.main.class.too.start
502# --jar /the/jar/too/launch.jar 560# --jar /the/jar/too/launch.jar or just <name>.jar
503# --java_args 'Extra arguments to pass too jave' 561# --java_args 'Extra arguments to pass to java'
504# --pkg_args 'extra arguments too pass too the package' 562# --pkg_args 'Extra arguments to pass to the package'
505# --pwd 563# --pwd Directory the launcher changes to before executing java
506# -into 564# -into Directory to install the launcher to, instead of /usr/bin
507# -pre 565# -pre Prepend contents of this file to the launcher
508# ------------------------------------------------------------------------------ 566# ------------------------------------------------------------------------------
509java-pkg_dolauncher() { 567java-pkg_dolauncher() {
510 debug-print-function ${FUNCNAME} $* 568 debug-print-function ${FUNCNAME} $*
511 569
512 java-pkg_check-phase install 570 java-pkg_check-phase install
513
514 [[ ${#} -lt 1 ]] && die "Need at least one argument"
515
516 java-pkg_init_paths_ 571 java-pkg_init_paths_
517 572
573 if [[ ${#} = 0 ]]; then
574 local name="${PN}"
575 else
518 local name="${1}" 576 local name="${1}"
577 shift
578 fi
579
519 # TODO rename to launcher 580 # TODO rename to launcher
520 local target="${T}/${name}" 581 local target="${T}/${name}"
582 local var_tmp="${T}/launcher_variables_tmp"
521 local target_dir pre 583 local target_dir pre
522 shift
523 584
524 echo "#!/bin/bash" > "${target}" 585 # Process the other the rest of the arguments
525 while [[ -n "${1}" && -n "${2}" ]]; do 586 while [[ -n "${1}" && -n "${2}" ]]; do
526 local var=${1} value=${2} 587 local var="${1}" value="${2}"
527 if [[ "${var:0:2}" == "--" ]]; then 588 if [[ "${var:0:2}" == "--" ]]; then
589 local var=${var:2}
528 echo "gjl_${var:2}=\"${value}\"" >> "${target}" 590 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
591 local gjl_${var}="${value}"
529 elif [[ "${var}" == "-into" ]]; then 592 elif [[ "${var}" == "-into" ]]; then
530 target_dir="${value}" 593 target_dir="${value}"
531 elif [[ "${var}" == "-pre" ]]; then 594 elif [[ "${var}" == "-pre" ]]; then
532 pre="${value}" 595 pre="${value}"
533 fi 596 fi
534 shift 2 597 shift 2
535 done 598 done
599
600 # Test if no --jar and --main arguments were given and
601 # in that case check if the package only installs one jar
602 # and use that jar.
603 if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
604 local cp="${JAVA_PKG_CLASSPATH}"
605 if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
606 echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
607 else
608 local msg="Not enough information to create a launcher given."
609 msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
610 die "${msg}"
611 fi
612 fi
613
614 # Write the actual script
615 echo "#!/bin/bash" > "${target}"
616 if [[ -n "${pre}" ]]; then
617 if [[ -f "${pre}" ]]; then
618 cat "${pre}" >> "${target}"
619 else
620 die "-pre specified file '${pre}' does not exist"
621 fi
622 fi
536 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 623 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
537 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 624 cat "${var_tmp}" >> "${target}"
625 rm -f "${var_tmp}"
538 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 626 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
539 627
540 if [[ -n "${into}" ]]; then 628 if [[ -n "${target_dir}" ]]; then
541 DESTTREE="${target_dir}" dobin "${target}" 629 DESTTREE="${target_dir}" dobin "${target}"
542 local ret=$? 630 local ret=$?
543 return ${ret} 631 return ${ret}
544 else 632 else
545 dobin "${target}" 633 dobin "${target}"
573 echo "dowar: warning, skipping directory ${war}" 661 echo "dowar: warning, skipping directory ${war}"
574 continue 662 continue
575 else 663 else
576 warpath="${war}" 664 warpath="${war}"
577 fi 665 fi
578 666
579 # Install those files like you mean it 667 # Install those files like you mean it
580 INSOPTIONS="-m 0644" \ 668 INSOPTIONS="-m 0644" \
581 INSDESTTREE=${JAVA_PKG_WARDEST} \ 669 INSDESTTREE=${JAVA_PKG_WARDEST} \
582 doins ${warpath} 670 doins ${warpath}
583 done 671 done
618# @ebuild-function java-pkg_jar-from 706# @ebuild-function java-pkg_jar-from
619# 707#
620# Makes a symlink to a jar from a certain package 708# Makes a symlink to a jar from a certain package
621# A lot of java packages include dependencies in a lib/ directory 709# A lot of java packages include dependencies in a lib/ directory
622# You can use this function to replace these bundled dependencies. 710# You can use this function to replace these bundled dependencies.
711# The dependency is recorded into package.env DEPEND line, unless "--build-only"
712# is passed as the very first argument, for jars that have to be present only
713# at build time and are not needed on runtime (junit testing etc).
623# 714#
624# Example: get all jars from xerces slot 2 715# Example: get all jars from xerces slot 2
625# java-pkg_jar-from xerces-2 716# java-pkg_jar-from xerces-2
626# Example: get a specific jar from xerces slot 2 717# Example: get a specific jar from xerces slot 2
627# java-pkg_jar-from xerces-2 xml-apis.jar 718# java-pkg_jar-from xerces-2 xml-apis.jar
628# Example get a specific jar from xerces slot 2, and name it diffrently 719# 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 720# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
721# Example: get junit.jar which is needed only for building
722# java-pkg_jar-from --build-only junit junit.jar
630# 723#
724# @param $1 - (optional) "--build-only" makes the jar(s) not added into
725# package.env DEPEND line.
631# @param $1 - Package to get jars from. 726# @param $1 - Package to get jars from.
632# @param $2 - jar from package. If not specified, all jars will be used. 727# @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 728# @param $3 - When a single jar is specified, destination filename of the
634# symlink. Defaults to the name of the jar. 729# symlink. Defaults to the name of the jar.
635# ------------------------------------------------------------------------------ 730# ------------------------------------------------------------------------------
636# TODO could probably be cleaned up a little 731# TODO could probably be cleaned up a little
637java-pkg_jar-from() { 732java-pkg_jar-from() {
638 debug-print-function ${FUNCNAME} $* 733 debug-print-function ${FUNCNAME} $*
639 734
735 local build_only=""
736
737 if [[ "${1}" = "--build-only" ]]; then
738 build_only="true"
739 shift
740 fi
741
742 if [[ "${1}" = "--with-dependencies" ]]; then
743 local deep="--with-dependencies"
744 shift
745 fi
746
640 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 747 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
641 748
642 [[ -z ${target_pkg} ]] && die "Must specify a package" 749 [[ -z ${target_pkg} ]] && die "Must specify a package"
643 750
644 # default destjar to the target jar 751 # default destjar to the target jar
645 [[ -z "${destjar}" ]] && destjar="${target_jar}" 752 [[ -z "${destjar}" ]] && destjar="${target_jar}"
646 753
754 local error_msg="There was a problem getting the classpath for ${target_pkg}."
755 local classpath
647 local classpath="$(java-config --classpath=${target_pkg})" 756 classpath="$(java-config ${deep} --classpath=${target_pkg})"
648 [[ $? != 0 ]] && die "There was a problem getting the classpath for ${target_pkg}" 757 [[ $? != 0 ]] && die ${error_msg}
649 758
650 local jar 759 local jar
651 for jar in ${classpath//:/ }; do 760 for jar in ${classpath//:/ }; do
652 local jar_name=$(basename "${jar}") 761 local jar_name=$(basename "${jar}")
653 if [[ ! -f "${jar}" ]] ; then 762 if [[ ! -f "${jar}" ]] ; then
657 # If no specific target jar was indicated, link it 766 # If no specific target jar was indicated, link it
658 if [[ -z "${target_jar}" ]] ; then 767 if [[ -z "${target_jar}" ]] ; then
659 [[ -f "${target_jar}" ]] && rm "${target_jar}" 768 [[ -f "${target_jar}" ]] && rm "${target_jar}"
660 ln -snf "${jar}" \ 769 ln -snf "${jar}" \
661 || die "Failed to make symlink from ${jar} to ${jar_name}" 770 || die "Failed to make symlink from ${jar} to ${jar_name}"
662 java-pkg_record-jar_ "${target_pkg}" "${jar}" 771 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
663 # otherwise, if the current jar is the target jar, link it 772 # otherwise, if the current jar is the target jar, link it
664 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 773 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
665 [[ -f "${destjar}" ]] && rm "${destjar}" 774 [[ -f "${destjar}" ]] && rm "${destjar}"
666 ln -snf "${jar}" "${destjar}" \ 775 ln -snf "${jar}" "${destjar}" \
667 || die "Failed to make symlink from ${jar} to ${destjar}" 776 || die "Failed to make symlink from ${jar} to ${destjar}"
668 java-pkg_record-jar_ "${target_pkg}" "${jar}" 777 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
669 return 0 778 return 0
670 fi 779 fi
671 done 780 done
672 # if no target was specified, we're ok 781 # if no target was specified, we're ok
673 if [[ -z "${target_jar}" ]] ; then 782 if [[ -z "${target_jar}" ]] ; then
690# ------------------------------------------------------------------------------ 799# ------------------------------------------------------------------------------
691# @ebuild-function java-pkg_getjars 800# @ebuild-function java-pkg_getjars
692# 801#
693# Get the classpath provided by any number of packages 802# Get the classpath provided by any number of packages
694# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'. 803# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
804# The providing packages are recorded as dependencies into package.env DEPEND
805# line, unless "--build-only" is passed as the very first argument, for jars
806# that have to be present only at build time and are not needed on runtime
807# (junit testing etc).
695# 808#
696# Example: Get the classpath for xerces-2, 809# Example: Get the classpath for xerces-2 and xalan,
697# java-pkg_getjars xerces-2 xalan 810# java-pkg_getjars xerces-2,xalan
698# Example Return: 811# Example Return:
699# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 812# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
700# 813#
814# @param $1 - (optional) "--build-only" makes the jar(s) not added into
815# package.env DEPEND line.
701# @param $@ - list of packages to get jars from 816# @param $2 - list of packages to get jars from
817# (passed to java-config --classpath)
702# ------------------------------------------------------------------------------ 818# ------------------------------------------------------------------------------
703java-pkg_getjars() { 819java-pkg_getjars() {
704 debug-print-function ${FUNCNAME} $* 820 debug-print-function ${FUNCNAME} $*
705 821
706 [[ ${#} -lt 1 ]] && die "At least one argument needed" 822 if [[ "${1}" = "--build-only" ]]; then
823 local build_only="true"
824 shift
825 fi
707 826
708 # NOTE could probably just pass $@ to java-config --classpath. and return it 827 if [[ "${1}" = "--with-dependencies" ]]; then
828 local deep="--with-dependencies"
829 shift
830 fi
831
832 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --build-only"
833
709 local classpath pkg 834 local classpath pkgs="${1}"
710 for pkg in ${@//,/ }; do
711 #for pkg in $(echo "$@" | tr ',' ' '); do
712 jars="$(java-config --classpath=${pkg})" 835 jars="$(java-config ${deep} --classpath=${pkgs})"
836 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed"
713 debug-print "${pkg}:${jars}" 837 debug-print "${pkgs}:${jars}"
714 # TODO should we ensure jars exist? 838
715 if [[ -z "${classpath}" ]]; then 839 if [[ -z "${classpath}" ]]; then
716 classpath="${jars}" 840 classpath="${jars}"
717 else 841 else
718 classpath="${classpath}:${jars}" 842 classpath="${classpath}:${jars}"
719 fi 843 fi
844
845 # Only record jars that aren't build-only
846 if [[ -z "${build_only}" ]]; then
847 oldifs="${IFS}"
848 IFS=","
849 for pkg in ${pkgs}; do
720 java-pkg_record-jar_ "${pkg}" 850 java-pkg_record-jar_ "${pkg}"
721 done 851 done
852 IFS="${oldifs}"
853 fi
854
722 echo "${classpath}" 855 echo "${classpath}"
723} 856}
724 857
725# ------------------------------------------------------------------------------ 858# ------------------------------------------------------------------------------
726# @ebuild-function java-pkg_getjar 859# @ebuild-function java-pkg_getjar
727# 860#
728# Get the filename of a single jar from a package 861# Get the filename of a single jar from a package
862# The providing package is recorded as runtime dependency into package.env
863# DEPEND line, unless "--build-only" is passed as the very first argument, for
864# jars that have to be present only at build time and are not needed on runtime
865# (junit testing etc).
729# 866#
730# @example 867# @example
731# java-pkg_getjar xerces-2 xml-apis.jar 868# java-pkg_getjar xerces-2 xml-apis.jar
732# @example-return 869# @example-return
733# /usr/share/xerces-2/lib/xml-apis.jar 870# /usr/share/xerces-2/lib/xml-apis.jar
734# 871#
872# @param $1 - (optional) "--build-only" makes the jar not added into
873# package.env DEPEND line.
735# @param $1 - package to use 874# @param $1 - package to use
736# @param $2 - jar to get 875# @param $2 - jar to get
737# ------------------------------------------------------------------------------ 876# ------------------------------------------------------------------------------
738java-pkg_getjar() { 877java-pkg_getjar() {
739 debug-print-function ${FUNCNAME} $* 878 debug-print-function ${FUNCNAME} $*
879
880 local build_only=""
881
882 if [[ "${1}" = "--build-only" ]]; then
883 build_only="true"
884 shift
885 fi
740 886
741 local pkg="${1}" target_jar="${2}" jar 887 local pkg="${1}" target_jar="${2}" jar
742 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 888 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
743 [[ -z ${target_jar} ]] && die "Must specify jar to get" 889 [[ -z ${target_jar} ]] && die "Must specify jar to get"
744 890
745 # TODO check that package is actually installed 891 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
892 local classpath
746 local classpath=$(java-config --classpath=${pkg}) 893 classpath=$(java-config --classpath=${pkg})
747 [[ $? != 0 ]] && die "There could not find classpath for ${pkg}. Are you sure its installed?" 894 [[ $? != 0 ]] && die ${error_msg}
895
748 for jar in ${classpath//:/ }; do 896 for jar in ${classpath//:/ }; do
749 if [[ ! -f "${jar}" ]] ; then 897 if [[ ! -f "${jar}" ]] ; then
750 die "Installation problems with jars in ${pkg} - is it installed?" 898 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
751 fi 899 fi
752 900
753 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then 901 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
754 java-pkg_record-jar_ "${pkg}" "${jar}" 902 # Only record jars that aren't build-only
903 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" "${jar}"
755 echo "${jar}" 904 echo "${jar}"
756 return 0 905 return 0
757 fi 906 fi
758 done 907 done
759 908
760 die "Could not find ${target_jar} in ${pkg}" 909 die "Could not find ${target_jar} in ${pkg}"
761 return 1 910 return 1
762} 911}
763 912
764# This function reads stdin, and based on that input, figures out how to 913# This function reads stdin, and based on that input, figures out how to
778# line="${line// /}" 927# line="${line// /}"
779# 928#
780# # format: path=jarinfo 929# # format: path=jarinfo
781# local path=${line%%=*} 930# local path=${line%%=*}
782# local jarinfo=${line##*=} 931# local jarinfo=${line##*=}
783# 932#
784# # format: jar@package 933# # format: jar@package
785# local jar=${jarinfo%%@*}.jar 934# local jar=${jarinfo%%@*}.jar
786# local package=${jarinfo##*@} 935# local package=${jarinfo##*@}
787# if [[ -n ${replace_only} ]]; then 936# if [[ -n ${replace_only} ]]; then
788# [[ ! -f $path ]] && die "No jar exists at ${path}" 937# [[ ! -f $path ]] && die "No jar exists at ${path}"
801# @section-end query 950# @section-end query
802# ------------------------------------------------------------------------------ 951# ------------------------------------------------------------------------------
803 952
804# ------------------------------------------------------------------------------ 953# ------------------------------------------------------------------------------
805# @section-begin helper 954# @section-begin helper
806# @section-summary Helper functions 955# @section-summary Helper functions
807# 956#
808# Various other functions to use from an ebuild 957# Various other functions to use from an ebuild
809# ------------------------------------------------------------------------------ 958# ------------------------------------------------------------------------------
810 959
811# ------------------------------------------------------------------------------ 960# ------------------------------------------------------------------------------
817# jdbc-stdext 966# jdbc-stdext
818# jaf 967# jaf
819# jdbc-rowset 968# jdbc-rowset
820# jms 969# jms
821# 970#
822# @param $1 - Optionally indicate that the dependencies are controlled by 971# @param $1 - Optionally indicate that the dependencies are controlled by
823# a use flag by specifying '--use' Requires $2. 972# a use flag by specifying '--use' Requires $2.
824# @param $2 - USE flag which will enable the dependencies. 973# @param $2 - USE flag which will enable the dependencies.
825# @param $@ - virtual packages to add depenedencies for 974# @param $@ - virtual packages to add depenedencies for
826# ------------------------------------------------------------------------------ 975# ------------------------------------------------------------------------------
827# TODO rewrite to parse a line based declaration file instead -- karltk 976# TODO rewrite to parse a line based declaration file instead -- karltk
883# 1032#
884# export DEPEND="${DEPEND} ${depstr}" 1033# export DEPEND="${DEPEND} ${depstr}"
885# export RDEPEND="${RDEPEND} ${depstr}" 1034# export RDEPEND="${RDEPEND} ${depstr}"
886#} 1035#}
887 1036
1037# ------------------------------------------------------------------------------
1038# @ebuild-function java-pkg_find-normal-jars
1039#
1040# Find the files with suffix .jar file in the given directory or $WORKDIR
1041#
1042# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1043# ------------------------------------------------------------------------------
1044java-pkg_find-normal-jars() {
1045 local dir=$1
1046 [[ "${dir}" ]] || dir="${WORKDIR}"
1047 local found
1048 for jar in $(find "${dir}" -name "*.jar" -type f); do
1049 echo "${jar}"
1050 found="true"
1051 done
1052 [[ "${found}" ]]
1053 return $?
1054}
1055
1056# ------------------------------------------------------------------------------
1057# @ebuild-function java-pkg_ensure-no-bundled-jars
1058#
1059# 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 1060# This function should be called after WORKDIR has been populated with symlink
889# TODO document 1061# to system jar files or bundled jars removed.
1062# ------------------------------------------------------------------------------
890java-pkg_ensure-no-bundled-jars() { 1063java-pkg_ensure-no-bundled-jars() {
891 debug-print-function ${FUNCNAME} $* 1064 debug-print-function ${FUNCNAME} $*
892 pushd ${WORKDIR} >/dev/null 2>/dev/null
893 1065
894 local bundled_jars=$(find . -name "*.jar" -type f) 1066 local bundled_jars=$(java-pkg_find-normal-jars)
895 if [[ -n ${bundled_jars} ]]; then 1067 if [[ -n ${bundled_jars} ]]; then
896 echo "Bundled jars found:" 1068 echo "Bundled jars found:"
897 local jar 1069 local jar
898 for jar in ${bundled_jars}; do 1070 for jar in ${bundled_jars}; do
899 echo $(pwd)${jar/./} 1071 echo $(pwd)${jar/./}
900 done 1072 done
901 die "Bundled jars found!" 1073 die "Bundled jars found!"
902
903 fi 1074 fi
904 popd >/dev/null 2>/dev/null
905} 1075}
906 1076
907# ------------------------------------------------------------------------------ 1077# ------------------------------------------------------------------------------
908# @internal-function java-pkg_ensure-vm-version-sufficient 1078# @internal-function java-pkg_ensure-vm-version-sufficient
909# 1079#
921 fi 1091 fi
922} 1092}
923 1093
924# ------------------------------------------------------------------------------ 1094# ------------------------------------------------------------------------------
925# @internal-function java-pkg_is-vm-version-sufficient 1095# @internal-function java-pkg_is-vm-version-sufficient
926# 1096#
927# @return zero - VM is sufficient 1097# @return zero - VM is sufficient
928# @return non-zero - VM is not sufficient 1098# @return non-zero - VM is not sufficient
929# ------------------------------------------------------------------------------ 1099# ------------------------------------------------------------------------------
930java-pkg_is-vm-version-sufficient() { 1100java-pkg_is-vm-version-sufficient() {
931 debug-print-function ${FUNCNAME} $* 1101 debug-print-function ${FUNCNAME} $*
951 die "Active Java VM too old" 1121 die "Active Java VM too old"
952 fi 1122 fi
953} 1123}
954 1124
955# ------------------------------------------------------------------------------ 1125# ------------------------------------------------------------------------------
956# @internal-function java-pkg_is-vm-version-eq 1126# @internal-function java-pkg_is-vm-version-eq
957# 1127#
958# @param $@ - VM version to compare current VM to 1128# @param $@ - VM version to compare current VM to
959# @return zero - VM versions are equal 1129# @return zero - VM versions are equal
960# @return non-zero - VM version are not equal 1130# @return non-zero - VM version are not equal
961# ------------------------------------------------------------------------------ 1131# ------------------------------------------------------------------------------
962java-pkg_is-vm-version-eq() { 1132java-pkg_is-vm-version-eq() {
992# 1162#
993# @param $@ - VM version to compare current to 1163# @param $@ - VM version to compare current to
994# ------------------------------------------------------------------------------ 1164# ------------------------------------------------------------------------------
995java-pkg_ensure-vm-version-ge() { 1165java-pkg_ensure-vm-version-ge() {
996 debug-print-function ${FUNCNAME} $* 1166 debug-print-function ${FUNCNAME} $*
997 1167
998 if ! java-pkg_is-vm-version-ge "$@" ; then 1168 if ! java-pkg_is-vm-version-ge "$@" ; then
999 debug-print "vm is not suffient" 1169 debug-print "vm is not suffient"
1000 eerror "This package requires a Java VM version >= $@" 1170 eerror "This package requires a Java VM version >= $@"
1001 einfo "Please use java-config -S to set the correct one" 1171 einfo "Please use java-config -S to set the correct one"
1002 die "Active Java VM too old" 1172 die "Active Java VM too old"
1003 fi 1173 fi
1004} 1174}
1005 1175
1006# ------------------------------------------------------------------------------ 1176# ------------------------------------------------------------------------------
1007# @internal-function java-pkg_is-vm-version-ge 1177# @internal-function java-pkg_is-vm-version-ge
1008# 1178#
1009# @param $@ - VM version to compare current VM to 1179# @param $@ - VM version to compare current VM to
1010# @return zero - current VM version is greater than checked version 1180# @return zero - current VM version is greater than checked version
1011# @return non-zero - current VM version is not greater than checked version 1181# @return non-zero - current VM version is not greater than checked version
1012# ------------------------------------------------------------------------------ 1182# ------------------------------------------------------------------------------
1013java-pkg_is-vm-version-ge() { 1183java-pkg_is-vm-version-ge() {
1027 return 1 1197 return 1
1028 fi 1198 fi
1029 fi 1199 fi
1030} 1200}
1031 1201
1202java-pkg_set-current-vm() {
1203 export GENTOO_VM=${1}
1204}
1205
1206java-pkg_get-current-vm() {
1207 echo ${GENTOO_VM}
1208}
1209
1210java-pkg_current-vm-matches() {
1211 hasq $(java-pkg_get-current-vm) ${@}
1212 return $?
1213}
1214
1032# ------------------------------------------------------------------------------ 1215# ------------------------------------------------------------------------------
1033# @ebuild-function java-pkg_get-source 1216# @ebuild-function java-pkg_get-source
1034# 1217#
1035# Determines what source version should be used, for passing to -source. 1218# 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 1219# Unless you want to break things you probably shouldn't set _WANT_SOURCE
1037# 1220#
1038# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE 1221# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1039# ------------------------------------------------------------------------------ 1222# ------------------------------------------------------------------------------
1044# ------------------------------------------------------------------------------ 1227# ------------------------------------------------------------------------------
1045# @ebuild-function java-pkg_get-target 1228# @ebuild-function java-pkg_get-target
1046# 1229#
1047# Determines what target version should be used, for passing to -target. 1230# 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 1231# If you don't care about lower versions, you can set _WANT_TARGET to the
1049# version of your JDK. 1232# 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# 1233#
1054# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1234# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1055# ------------------------------------------------------------------------------ 1235# ------------------------------------------------------------------------------
1056java-pkg_get-target() { 1236java-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}")} 1237 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1070} 1238}
1071 1239
1072java-pkg_get-javac() { 1240java-pkg_get-javac() {
1073 debug-print-function ${FUNCNAME} $* 1241 debug-print-function ${FUNCNAME} $*
1074 1242
1075 java-pkg_init-compiler_ 1243
1076 local compiler="${GENTOO_COMPILER}" 1244 local compiler="${GENTOO_COMPILER}"
1077 1245
1078 local compiler_executable 1246 local compiler_executable
1079 if [[ "${compiler}" = "javac" ]]; then 1247 if [[ "${compiler}" = "javac" ]]; then
1080 # nothing fancy needs to be done for javac 1248 # nothing fancy needs to be done for javac
1088 unset JAVAC 1256 unset JAVAC
1089 # try to get value of JAVAC 1257 # try to get value of JAVAC
1090 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1258 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1091 export JAVAC=${old_javac} 1259 export JAVAC=${old_javac}
1092 1260
1093 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1261 if [[ -z ${compiler_executable} ]]; then
1094 1262 echo "JAVAC is empty or undefined in ${compiler_env}"
1263 return 1
1264 fi
1265
1095 # check that it's executable 1266 # check that it's executable
1096 if [[ ! -x ${compiler_executable} ]]; then 1267 if [[ ! -x ${compiler_executable} ]]; then
1097 eerror "Could not find ${compiler_executable}!"
1098 die "${compiler_executable} doesn't exist, or isn't executable" 1268 echo "${compiler_executable} doesn't exist, or isn't executable"
1269 return 1
1099 fi 1270 fi
1100 else 1271 else
1101 eerror "Could not find environment file for ${compiler}" 1272 echo "Could not find environment file for ${compiler}"
1102 die "Could not find ${compiler_env}" 1273 return 1
1103 fi 1274 fi
1104 fi 1275 fi
1105 echo ${compiler_executable} 1276 echo ${compiler_executable}
1106} 1277}
1107 1278
1108# ------------------------------------------------------------------------------ 1279# ------------------------------------------------------------------------------
1109# @ebuild-function java-pkg_javac-args 1280# @ebuild-function java-pkg_javac-args
1110# 1281#
1111# If an ebuild uses javac directly, instead of using ejavac, it should call this 1282# If an ebuild uses javac directly, instead of using ejavac, it should call this
1112# to know what -source/-target to use. 1283# to know what -source/-target to use.
1113# 1284#
1114# @return string - arguments to pass to javac, complete with -target and -source 1285# @return string - arguments to pass to javac, complete with -target and -source
1117 debug-print-function ${FUNCNAME} $* 1288 debug-print-function ${FUNCNAME} $*
1118 1289
1119 local want_source="$(java-pkg_get-source)" 1290 local want_source="$(java-pkg_get-source)"
1120 local want_target="$(java-pkg_get-target)" 1291 local want_target="$(java-pkg_get-target)"
1121 1292
1122 local source_str="-source ${want_source}" 1293 local source_str="-source ${want_source}"
1123 local target_str="-target ${want_target}" 1294 local target_str="-target ${want_target}"
1124 1295
1125 debug-print "want source: ${want_source}" 1296 debug-print "want source: ${want_source}"
1126 debug-print "want target: ${want_target}" 1297 debug-print "want target: ${want_target}"
1127 1298
1128 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1299 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1129 debug-print "could not find valid -source/-target values" 1300 debug-print "could not find valid -source/-target values for javac"
1130 die "Could not find valid -source/-target values" 1301 echo "Could not find valid -source/-target values for javac"
1302 return 1
1131 else 1303 else
1132 if java-pkg_is-vm-version-ge "1.4"; then 1304 if java-pkg_is-vm-version-ge "1.4"; then
1133 echo "${source_str} ${target_str}" 1305 echo "${source_str} ${target_str}"
1134 else 1306 else
1135 echo "${target_str}" 1307 echo "${target_str}"
1139 1311
1140# TODO document 1312# TODO document
1141java-pkg_get-jni-cflags() { 1313java-pkg_get-jni-cflags() {
1142 local flags="-I${JAVA_HOME}/include" 1314 local flags="-I${JAVA_HOME}/include"
1143 1315
1144 # TODO figure out how to cope with other things than linux... 1316 local platform="linux"
1317 use elibc_FreeBSD && platform="freebsd"
1318
1319 # TODO do a check that the directories are valid
1145 flags="${flags} -I${JAVA_HOME}/include/linux" 1320 flags="${flags} -I${JAVA_HOME}/include/${platform}"
1146 1321
1147 echo ${flags} 1322 echo ${flags}
1323}
1324
1325java-pkg_ensure-gcj() {
1326 if ! built_with_use sys-devel/gcc gcj ; then
1327 ewarn
1328 ewarn "You must build gcc with the gcj support to build with gcj"
1329 ewarn
1330 ebeep 5
1331 die "No GCJ support found!"
1332 fi
1333}
1334
1335java-pkg_ensure-test() {
1336 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \
1337 && hasq test ${IUSE} && ! use test;
1338 then
1339 eerror "You specified FEATURES=test, but USE=test is needed"
1340 eerror "to pull in the additional dependencies for testing"
1341 die "Need USE=test enabled"
1342 fi
1148} 1343}
1149 1344
1150# ------------------------------------------------------------------------------ 1345# ------------------------------------------------------------------------------
1151# @section-end helper 1346# @section-end helper
1152# ------------------------------------------------------------------------------ 1347# ------------------------------------------------------------------------------
1162# ------------------------------------------------------------------------------ 1357# ------------------------------------------------------------------------------
1163# @ebuild-function eant 1358# @ebuild-function eant
1164# 1359#
1165# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1360# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1166# compiler. 1361# compiler.
1362# variables:
1363# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1364# gentoo.classpath property. Be sure to call
1365# java-ant_rewrite-classpath in src_unpack.
1167# 1366#
1168# ------------------------------------------------------------------------------ 1367# ------------------------------------------------------------------------------
1169eant() { 1368eant() {
1170 debug-print-function ${FUNCNAME} $* 1369 debug-print-function ${FUNCNAME} $*
1171 1370
1172 local antflags 1371 # FIXME get this working
1372# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then
1373# java-pkg_announce-qa-violation \
1374# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1375# fi
1376
1377 local antflags="-Dnoget=true"
1173 java-pkg_init-compiler_ 1378 java-pkg_init-compiler_
1174 local compiler="${GENTOO_COMPILER}" 1379 local compiler="${GENTOO_COMPILER}"
1175 1380
1176 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1381 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1177 1382
1179 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1384 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1180 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1385 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1181 fi 1386 fi
1182 1387
1183 if [[ ${compiler} != "javac" ]]; then 1388 if [[ ${compiler} != "javac" ]]; then
1184 antflags="-Dbuild.compiler=${build_compiler}" 1389 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1185 # Figure out any extra stuff to put on the classpath for compilers aside 1390 # Figure out any extra stuff to put on the classpath for compilers aside
1186 # from javac 1391 # from javac
1187 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to 1392 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1188 # java-config -p 1393 # java-config -p
1189 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1394 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 1395 if [[ -n ${build_compiler_deps} ]]; then
1191 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})" 1396 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1192 fi 1397 fi
1193 fi 1398 fi
1194 1399
1400 if is-java-strict; then
1401 einfo "Disabling system classpath for ant"
1402 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1403 fi
1404
1195 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1405 if [[ -n ${JAVA_PKG_DEBUG} ]]; then
1196 antflags="${antflags} -debug" 1406 antflags="${antflags} -debug"
1197 fi 1407 fi
1198 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}\""
1415 fi
1416
1199 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1417 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1200 ant ${antflags} "${@}" || die "eant failed" 1418 ant ${antflags} "${@}" || die "eant failed"
1201 1419
1202} 1420}
1203 1421
1204# ------------------------------------------------------------------------------ 1422# ------------------------------------------------------------------------------
1205# @ebuild-function ejavac 1423# @ebuild-function ejavac
1206# 1424#
1207# Javac wrapper function. Will use the appropriate compiler, based on 1425# Javac wrapper function. Will use the appropriate compiler, based on
1208# /etc/java-config/compilers.conf 1426# /etc/java-config/compilers.conf
1209# 1427#
1210# @param $@ - Arguments to be passed to the compiler 1428# @param $@ - Arguments to be passed to the compiler
1211# ------------------------------------------------------------------------------ 1429# ------------------------------------------------------------------------------
1212ejavac() { 1430ejavac() {
1213 debug-print-function ${FUNCNAME} $* 1431 debug-print-function ${FUNCNAME} $*
1214 1432
1433 java-pkg_init-compiler_
1434
1435 local compiler_executable
1215 local compiler_executable=$(java-pkg_get-javac) 1436 compiler_executable=$(java-pkg_get-javac)
1437 if [[ ${?} != 0 ]]; then
1438 eerror "There was a problem determining compiler: ${compiler_executable}"
1439 die "get-javac failed"
1440 fi
1216 1441
1442 local javac_args
1443 javac_args="$(java-pkg_javac-args)"
1444 if [[ ${?} != 0 ]]; then
1445 eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
1446 die "java-pkg_javac-args failed"
1447 fi
1448
1217 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 1449 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1218 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 1450 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1219} 1451}
1220 1452
1221# ------------------------------------------------------------------------------ 1453# ------------------------------------------------------------------------------
1222# @ebuild-function java-pkg_filter-compiler 1454# @ebuild-function java-pkg_filter-compiler
1223# 1455#
1224# Used to prevent the use of some compilers. Should be used in src_compile. 1456# Used to prevent the use of some compilers. Should be used in src_compile.
1225# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER 1457# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
1226# 1458#
1227# @param $@ - compilers to filter 1459# @param $@ - compilers to filter
1228# ------------------------------------------------------------------------------ 1460# ------------------------------------------------------------------------------
1229java-pkg_filter-compiler() { 1461java-pkg_filter-compiler() {
1230 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@" 1462 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@"
1231} 1463}
1232 1464
1233# ------------------------------------------------------------------------------ 1465# ------------------------------------------------------------------------------
1466# @ebuild-function java-pkg_force-compiler
1467#
1468# Used to force the use of particular compilers. Should be used in src_compile.
1469# A common use of this would be to force ecj-3.1 to be used on amd64, to avoid
1470# OutOfMemoryErrors that may come up.
1471#
1472# @param $@ - compilers to force
1473# ------------------------------------------------------------------------------
1474java-pkg_force-compiler() {
1475 JAVA_PKG_FORCE_COMPILER="$@"
1476}
1477
1478# ------------------------------------------------------------------------------
1234# @ebuild-function use_doc 1479# @ebuild-function use_doc
1235# 1480#
1236# Helper function for getting ant to build javadocs. If the user has USE=doc, 1481# 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. 1482# then 'javadoc' or the argument are returned. Otherwise, there is no return.
1238# 1483#
1239# The output of this should be passed to ant. 1484# The output of this should be passed to ant.
1240# 1485#
1241# Example: build javadocs by calling 'javadoc' target 1486# Example: build javadocs by calling 'javadoc' target
1242# eant $(use_doc) 1487# eant $(use_doc)
1243# Example: build javadocs by calling 'apidoc' target 1488# Example: build javadocs by calling 'apidoc' target
1248# ------------------------------------------------------------------------------ 1493# ------------------------------------------------------------------------------
1249use_doc() { 1494use_doc() {
1250 use doc && echo ${@:-javadoc} 1495 use doc && echo ${@:-javadoc}
1251} 1496}
1252 1497
1498
1253# ------------------------------------------------------------------------------ 1499# ------------------------------------------------------------------------------
1254# @section-end build 1500# @section-end build
1255# ------------------------------------------------------------------------------ 1501# ------------------------------------------------------------------------------
1256 1502
1257# ------------------------------------------------------------------------------ 1503# ------------------------------------------------------------------------------
1258# @section-begin internal 1504# @section-begin internal
1259# @section-summary Internal functions 1505# @section-summary Internal functions
1260# 1506#
1261# Do __NOT__ use any of these from an ebuild! These are only to be used from 1507# Do __NOT__ use any of these from an ebuild! These are only to be used from
1262# within the java eclasses. 1508# within the java eclasses.
1263# ------------------------------------------------------------------------------ 1509# ------------------------------------------------------------------------------
1264 1510
1265# ----------------------------------------------------------------------------- 1511# -----------------------------------------------------------------------------
1266# @function-internal java-pkg_init 1512# @function-internal java-pkg_init
1267# 1513#
1268# The purpose of this function, as the name might imply, is to initialize the 1514# 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 1515# 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 1516# that'll muss things up. It initializes some variables, which are used
1271# internally. And most importantly, it'll switch the VM if necessary. 1517# internally. And most importantly, it'll switch the VM if necessary.
1272# 1518#
1284 # TODO we will probably want to set JAVAC and JAVACFLAGS 1530 # TODO we will probably want to set JAVAC and JAVACFLAGS
1285 1531
1286 # Do some QA checks 1532 # Do some QA checks
1287 java-pkg_check-jikes 1533 java-pkg_check-jikes
1288 1534
1289 # When users have crazy classpaths some packages can fail to compile. 1535 # When users have crazy classpaths some packages can fail to compile.
1290 # and everything should work with empty CLASSPATH. 1536 # and everything should work with empty CLASSPATH.
1291 # This also helps prevent unexpected dependencies on random things 1537 # This also helps prevent unexpected dependencies on random things
1292 # from the CLASSPATH. 1538 # from the CLASSPATH.
1293 unset CLASSPATH 1539 unset CLASSPATH
1294} 1540}
1295 1541
1296# ------------------------------------------------------------------------------ 1542# ------------------------------------------------------------------------------
1297# @function-internal java-pkg-init-compiler_ 1543# @function-internal java-pkg-init-compiler_
1298# 1544#
1299# This function attempts to figure out what compiler should be used. It does 1545# 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 1546# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
1301# COMPILERS variable defined there. 1547# COMPILERS variable defined there.
1302# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER 1548# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
1303# 1549#
1304# It will go through the list of compilers, and verify that it supports the 1550# 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 1551# 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 1552# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
1307# isn't done. 1553# isn't done.
1308# 1554#
1324 if [[ -n ${GENTOO_COMPILER} ]]; then 1570 if [[ -n ${GENTOO_COMPILER} ]]; then
1325 debug-print "GENTOO_COMPILER already set" 1571 debug-print "GENTOO_COMPILER already set"
1326 return 1572 return
1327 fi 1573 fi
1328 1574
1575 local compilers;
1576 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1329 local compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})" 1577 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
1578 else
1579 compilers=${JAVA_PKG_FORCE_COMPILER}
1580 fi
1581
1330 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}" 1582 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
1331 1583
1332 # Figure out if we should announce what compiler we're using 1584 # Figure out if we should announce what compiler we're using
1333 local compiler 1585 local compiler
1334 for compiler in ${compilers}; do 1586 for compiler in ${compilers}; do
1337 if [[ ${compiler} = "javac" ]]; then 1589 if [[ ${compiler} = "javac" ]]; then
1338 debug-print "Found javac... breaking" 1590 debug-print "Found javac... breaking"
1339 export GENTOO_COMPILER="javac" 1591 export GENTOO_COMPILER="javac"
1340 break 1592 break
1341 fi 1593 fi
1342 1594
1343 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then 1595 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
1344 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1596 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1345 einfo "Filtering ${compiler}" 1597 einfo "Filtering ${compiler}"
1346 continue 1598 continue
1347 fi 1599 fi
1348 fi 1600 fi
1349 1601
1350 # for non-javac, we need to make sure it supports the right target and 1602 # for non-javac, we need to make sure it supports the right target and
1351 # source 1603 # source
1352 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1604 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1353 if [[ -f ${compiler_env} ]]; then 1605 if [[ -f ${compiler_env} ]]; then
1354 local desired_target="$(java-pkg_get-target)" 1606 local desired_target="$(java-pkg_get-target)"
1436# Writes the package.env out to disk. 1688# Writes the package.env out to disk.
1437# 1689#
1438# ------------------------------------------------------------------------------ 1690# ------------------------------------------------------------------------------
1439# TODO change to do-write, to match everything else 1691# TODO change to do-write, to match everything else
1440java-pkg_do_write_() { 1692java-pkg_do_write_() {
1693 java-pkg_init_paths_
1441 # Create directory for package.env 1694 # Create directory for package.env
1442 dodir "${JAVA_PKG_SHAREPATH}" 1695 dodir "${JAVA_PKG_SHAREPATH}"
1443 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 1696 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then
1444 # Create package.env 1697 # Create package.env
1445 ( 1698 (
1450 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 1703 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1451 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 1704 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1452 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 1705 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\""
1453 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 1706 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1454 ) > "${JAVA_PKG_ENV}" 1707 ) > "${JAVA_PKG_ENV}"
1455 1708
1456 # register target/source 1709 # register target/source
1457 local target="$(java-pkg_get-target)" 1710 local target="$(java-pkg_get-target)"
1458 local source="$(java-pkg_get-source)" 1711 local source="$(java-pkg_get-source)"
1459 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}" 1712 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
1460 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}" 1713 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
1473 # Strip unnecessary leading and trailing colons 1726 # Strip unnecessary leading and trailing colons
1474 # TODO try to cleanup if possible 1727 # TODO try to cleanup if possible
1475 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 1728 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
1476 fi 1729 fi
1477} 1730}
1478
1479 1731
1480# ------------------------------------------------------------------------------ 1732# ------------------------------------------------------------------------------
1481# @internal-function java-pkg_record-jar_ 1733# @internal-function java-pkg_record-jar_
1482# 1734#
1483# Record a dependency to the package.env 1735# Record a dependency to the package.env
1527 fi 1779 fi
1528} 1780}
1529 1781
1530# ------------------------------------------------------------------------------ 1782# ------------------------------------------------------------------------------
1531# @internal-function java-pkg_expand_dir_ 1783# @internal-function java-pkg_expand_dir_
1532# 1784#
1533# Gets the full path of the file/directory's parent. 1785# Gets the full path of the file/directory's parent.
1534# @param $1 - file/directory to find parent directory for 1786# @param $1 - file/directory to find parent directory for
1535# @return - path to $1's parent directory 1787# @return - path to $1's parent directory
1536# ------------------------------------------------------------------------------ 1788# ------------------------------------------------------------------------------
1537java-pkg_expand_dir_() { 1789java-pkg_expand_dir_() {
1564# ------------------------------------------------------------------------------ 1816# ------------------------------------------------------------------------------
1565java-pkg_setup-vm() { 1817java-pkg_setup-vm() {
1566 debug-print-function ${FUNCNAME} $* 1818 debug-print-function ${FUNCNAME} $*
1567 1819
1568 local vendor="$(java-pkg_get-vm-vendor)" 1820 local vendor="$(java-pkg_get-vm-vendor)"
1569 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge 1 5; then 1821 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1570 addpredict "/dev/random" 1822 addpredict "/dev/random"
1571 elif [[ "${vendor}" == "ibm" ]]; then 1823 elif [[ "${vendor}" == "ibm" ]]; then
1572 addpredict "/proc/self/maps" 1824 addpredict "/proc/self/maps"
1573 addpredict "/proc/cpuinfo" 1825 addpredict "/proc/cpuinfo"
1574 export LANG="C" LC_ALL="C" 1826 export LANG="C" LC_ALL="C"
1623# @return - The version of the current VM 1875# @return - The version of the current VM
1624# ------------------------------------------------------------------------------ 1876# ------------------------------------------------------------------------------
1625java-pkg_get-vm-version() { 1877java-pkg_get-vm-version() {
1626 debug-print-function ${FUNCNAME} $* 1878 debug-print-function ${FUNCNAME} $*
1627 1879
1628 java-pkg_get-current-vm | sed -e "s/.*-\([0-9.]\+\).*/\1/" 1880 java-config -g PROVIDES_VERSION
1629} 1881}
1630 1882
1631# ------------------------------------------------------------------------------ 1883# ------------------------------------------------------------------------------
1632# @internal-function java-pkg_switch-vm 1884# @internal-function java-pkg_switch-vm
1633# 1885#
1634# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 1886# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1635# verify that the current VM is sufficient. 1887# verify that the current VM is sufficient.
1636# Setup the environment for the VM being used. 1888# Setup the environment for the VM being used.
1637# ------------------------------------------------------------------------------ 1889# ------------------------------------------------------------------------------
1638java-pkg_switch-vm() { 1890java-pkg_switch-vm() {
1891 debug-print-function ${FUNCNAME} $*
1892
1639 if java-pkg_needs-vm; then 1893 if java-pkg_needs-vm; then
1640 # Use the VM specified by JAVA_PKG_FORCE_VM 1894 # Use the VM specified by JAVA_PKG_FORCE_VM
1641 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then 1895 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1642 # If you're forcing the VM, I hope you know what your doing... 1896 # If you're forcing the VM, I hope you know what your doing...
1897 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1643 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 1898 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1644 # if we're allowed to switch the vm... 1899 # if we're allowed to switch the vm...
1645 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 1900 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1646 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}" 1901 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1647 if [[ -n ${JAVA_PKG_VNEED} ]]; then 1902 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1648 export GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 1903 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1649 else 1904 else
1650 export GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 1905 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1906 fi
1907 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
1908 eerror "Unable to determine VM for building from dependencies:"
1909 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
1910 echo "VNEED: ${JAVA_PKG_VNEED}"
1911 die "Failed to determine VM for building."
1912 else
1913 export GENTOO_VM
1651 fi 1914 fi
1652 # otherwise just make sure the current VM is sufficient 1915 # otherwise just make sure the current VM is sufficient
1653 else 1916 else
1654 java-pkg_ensure-vm-version-sufficient 1917 java-pkg_ensure-vm-version-sufficient
1655 fi 1918 fi
1656 debug-print "Using: $(java-config -f)" 1919 debug-print "Using: $(java-config -f)"
1657 1920
1658 java-pkg_setup-vm 1921 java-pkg_setup-vm
1659 1922
1923 export JAVA=$(java-config --java)
1924 export JAVAC=$(java-config --javac)
1660 export JAVACFLAGS="$(java-pkg_javac-args)" 1925 JAVACFLAGS="$(java-pkg_javac-args)"
1926 if [[ ${?} != 0 ]]; then
1927 eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
1928 die "java-pkg_javac-args failed"
1929 fi
1661 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 1930 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
1931 export JAVACFLAGS
1662 1932
1663 export JAVA_HOME="$(java-config -g JAVA_HOME)" 1933 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1664 export JDK_HOME=${JAVA_HOME} 1934 export JDK_HOME=${JAVA_HOME}
1665 1935
1666 #TODO If you know a better solution let us know. 1936 #TODO If you know a better solution let us know.
1667 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 1937 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1668 1938
1669 local tann="${T}/announced-vm" 1939 local tann="${T}/announced-vm"
1670 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 1940 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1671 # Add a check for setup/preinst phase... to avoid duplicate outputs 1941 # Add a check for setup/preinst phase... to avoid duplicate outputs
1672 # for when FEATURES=buildpkg 1942 # for when FEATURES=buildpkg
1673 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]]; 1943 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1698 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2 1968 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2
1699 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2 1969 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2
1700 echo "and of course, the output of emerge --info" >&2 1970 echo "and of course, the output of emerge --info" >&2
1701} 1971}
1702 1972
1973
1974# TODO document
1975# List jars in the source directory, ${S}
1976java-pkg_jar-list() {
1977 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
1978 einfo "Linked Jars"
1979 find "${S}" -type l -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1980 einfo "Jars"
1981 find "${S}" -type f -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1982 einfo "Classes"
1983 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1984 fi
1985}
1986
1987# TODO document
1988# Verify that the classes were compiled for the right source / target
1989java-pkg_verify-classes() {
1990 ebegin "Verifying java class versions"
1991 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1992 class-version-verify.py -t $(java-pkg_get-target) -r ${D}
1993 result=$?
1994 eend ${result}
1995 if [[ ${result} == 0 ]]; then
1996 einfo "All good"
1997 else
1998 ewarn "Possible problem"
1999 die "Bad class files found"
2000 fi
2001}
2002
1703# ------------------------------------------------------------------------------ 2003# ------------------------------------------------------------------------------
1704# @section-end internal 2004# @section-end internal
1705# ------------------------------------------------------------------------------ 2005# ------------------------------------------------------------------------------
1706 2006
1707java-pkg_check-phase() { 2007java-pkg_check-phase() {
1708 local phase=${1} 2008 local phase=${1}
1709 local funcname=${2} 2009 local funcname=${2}
1710 # TODO add check for java-stricter
1711 if [[ ${EBUILD_PHASE} != ${phase} ]]; then 2010 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then
1712 java-pkg_announce-qa-violation \ 2011 java-pkg_announce-qa-violation \
1713 "${funcname} used outside of src_${phase}" 2012 "${funcname} used outside of src_${phase}"
1714 fi 2013 fi
1715} 2014}
1716 2015
1727 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2026 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1728 fi 2027 fi
1729} 2028}
1730 2029
1731java-pkg_announce-qa-violation() { 2030java-pkg_announce-qa-violation() {
1732 if hasq java-strict ${FEATURES}; then 2031 if is-java-strict; then
1733 echo "Java QA Notice: $@" >&2 2032 echo "Java QA Notice: $@" >&2
1734 increment-qa-violations 2033 increment-qa-violations
1735 fi 2034 fi
1736} 2035}
1737 2036
1738increment-qa-violations() { 2037increment-qa-violations() {
1739 let "JAVA_PKG_QA_VIOLATIONS+=1" 2038 let "JAVA_PKG_QA_VIOLATIONS+=1"
1740 export JAVA_PKG_QA_VIOLATIONS 2039 export JAVA_PKG_QA_VIOLATIONS
1741} 2040}
1742 2041
2042is-java-strict() {
2043 [[ -n ${JAVA_PKG_STRICT} ]]
2044 return $?
2045}
2046
1743# ------------------------------------------------------------------------------ 2047# ------------------------------------------------------------------------------
1744# @eclass-end 2048# @eclass-end
1745# ------------------------------------------------------------------------------ 2049# ------------------------------------------------------------------------------

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.43

  ViewVC Help
Powered by ViewVC 1.1.20