/[gentoo-x86]/eclass/java-utils-2.eclass
Gentoo

Diff of /eclass/java-utils-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.3 Revision 1.48
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.48 2007/01/21 21:12:52 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#
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
38# ----------------------------------------------------------------------------- 41# -----------------------------------------------------------------------------
42# @variable-external WANT_ANT_TASKS
43# @variable-default ""
44#
45# An $IFS separated list of ant tasks.
46# Ebuild can specify this variable before inheriting java-ant-2 eclass to
47# determine ANT_TASKS it needs. They will be automatically translated to
48# DEPEND variable and ANT_TASKS variable. JAVA_PKG_FORCE_ANT_TASKS can override
49# ANT_TASKS set by WANT_ANT_TASKS, but not the DEPEND due to caching.
50# Ebuilds that need to depend conditionally on certain tasks and specify them
51# differently for different eant calls can't use this simplified approach.
52# You also cannot specify version or anything else than ant-*.
53#
54# @example WANT_ANT_TASKS="ant-junit ant-trax"
55#
56# @seealso JAVA_PKG_FORCE_ANT_TASKS
57# -----------------------------------------------------------------------------
58#WANT_ANT_TASKS
59
60# @variable-internal JAVA_PKG_PORTAGE_DEP
61#
62# The version of portage we need to function properly. At this moment it's
63# portage with phase hooks support.
64# -----------------------------------------------------------------------------
65JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1"
66
67# -----------------------------------------------------------------------------
39# @variable-internal JAVA_PKG_E_DEPEND 68# @variable-internal JAVA_PKG_E_DEPEND
40# 69#
41# This is a convience variable to be used from the other java eclasses. This is 70# 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 71# the version of java-config we want to use. We also need a recent version
43# portage, that includes phase hooks. 72# portage, that includes phase hooks.
44# ----------------------------------------------------------------------------- 73# -----------------------------------------------------------------------------
45JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 >=sys-apps/portage-2.1_pre1" 74JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 ${JAVA_PKG_PORTAGE_DEP}"
46 75
47# ----------------------------------------------------------------------------- 76# -----------------------------------------------------------------------------
48# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 77# @variable-external JAVA_PKG_ALLOW_VM_CHANGE
49# @variable-default yes 78# @variable-default yes
50# 79#
97# ----------------------------------------------------------------------------- 126# -----------------------------------------------------------------------------
98 127
99# ----------------------------------------------------------------------------- 128# -----------------------------------------------------------------------------
100# @variable-internal JAVA_PKG_COMPILER_DIR 129# @variable-internal JAVA_PKG_COMPILER_DIR
101# @default /usr/share/java-config-2/compiler 130# @default /usr/share/java-config-2/compiler
102# 131#
103# Directory where compiler settings are saved, without trailing slash. 132# Directory where compiler settings are saved, without trailing slash.
104# Probably shouldn't touch this variable. 133# Probably shouldn't touch this variable.
105# ----------------------------------------------------------------------------- 134# -----------------------------------------------------------------------------
106JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"} 135JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"}
107 136
117 146
118# ----------------------------------------------------------------------------- 147# -----------------------------------------------------------------------------
119# @variable-external JAVA_PKG_FORCE_COMPILER 148# @variable-external JAVA_PKG_FORCE_COMPILER
120# 149#
121# Explicitly set a list of compilers to use. This is normally read from 150# Explicitly set a list of compilers to use. This is normally read from
122# JAVA_PKG_COMPILERS_CONF. 151# JAVA_PKG_COMPILERS_CONF.
123# 152#
124# @note This should only be used internally or for testing. 153# @note This should only be used internally or for testing.
125# @example Use jikes and javac, in that order 154# @example Use jikes and javac, in that order
126# JAVA_PKG_FORCE_COMPILER="jikes javac" 155# JAVA_PKG_FORCE_COMPILER="jikes javac"
127# ----------------------------------------------------------------------------- 156# -----------------------------------------------------------------------------
128 157
158# -----------------------------------------------------------------------------
159# @variable-external JAVA_PKG_FORCE_ANT_TASKS
160#
161# An $IFS separated list of ant tasks. Can be set in environment before calling
162# emerge/ebuild to override variables set in ebuild, mainly for testing before
163# putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in
164# eant() call, not the dependencies specified in WANT_ANT_TASKS.
165#
166# @example JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \
167# ebuild foo.ebuild compile
168#
169# @seealso WANT_ANT_TASKS
170# -----------------------------------------------------------------------------
171
129# TODO document me 172# TODO document me
130JAVA_PKG_QA_VIOLATIONS=0 173JAVA_PKG_QA_VIOLATIONS=0
131 174
132# ----------------------------------------------------------------------------- 175# -----------------------------------------------------------------------------
133# @section-end variables 176# @section-end variables
147# @ebuild-function java-pkg_dojar 190# @ebuild-function java-pkg_dojar
148# 191#
149# Installs any number of jars. 192# Installs any number of jars.
150# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default. 193# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default.
151# You can use java-pkg_jarinto to change this path. 194# You can use java-pkg_jarinto to change this path.
152# You should never install a jar with a package version in the filename. 195# You should never install a jar with a package version in the filename.
153# Instead, use java-pkg_newjar defined below. 196# Instead, use java-pkg_newjar defined below.
154# 197#
155# @example 198# @example
156# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar 199# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar
157# 200#
168 # Create JARDEST if it doesn't exist 211 # Create JARDEST if it doesn't exist
169 dodir ${JAVA_PKG_JARDEST} 212 dodir ${JAVA_PKG_JARDEST}
170 213
171 local jar 214 local jar
172 # for each jar 215 # for each jar
173 for jar in "$@"; do 216 for jar in ${@}; do
174 local jar_basename=$(basename "${jar}") 217 local jar_basename=$(basename "${jar}")
175 218
176 java-pkg_check-versioned-jar ${jar_basename} 219 java-pkg_check-versioned-jar ${jar_basename}
177 220
178 # check if it exists 221 # check if it exists
179 if [[ -e "${jar}" ]] ; then 222 if [[ -e "${jar}" ]] ; then
223 # Don't overwrite if jar has already been installed with the same
224 # name
225 local dest="${D}${JAVA_PKG_JARDEST}/${jar_basename}"
226 if [[ -e "${dest}" ]]; then
227 ewarn "Overwriting ${dest}"
228 fi
229
180 # install it into JARDEST if it's a non-symlink 230 # install it into JARDEST if it's a non-symlink
181 if [[ ! -L "${jar}" ]] ; then 231 if [[ ! -L "${jar}" ]] ; then
182 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 232 INSDESTTREE="${JAVA_PKG_JARDEST}" \
183 doins "${jar}" || die "failed to install ${jar}" 233 doins "${jar}" || die "failed to install ${jar}"
184 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 234 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
197 247
198 java-pkg_do_write_ 248 java-pkg_do_write_
199} 249}
200 250
201 251
252# ------------------------------------------------------------------------------
253# @internal-function depend-java-query
254#
255# Wrapper for the depend-java-query binary to enable passing USE in env.
256# Using env variables keeps this eclass working with java-config versions that
257# do not handle use flags.
258# ------------------------------------------------------------------------------
259
260depend-java-query() {
261 USE="${USE}" $(which depend-java-query) "${@}"
262}
202 263
203# ------------------------------------------------------------------------------ 264# ------------------------------------------------------------------------------
204# @ebuild-function java-pkg_regjar 265# @ebuild-function java-pkg_regjar
205# 266#
206# Records an already installed jar in the package.env 267# 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 268# This would mostly be used if the package has make or a custom script to
208# install things. 269# install things.
209# 270#
210# Example: 271# Example:
211# java-pkg-regjar ${D}/opt/foo/lib/foo.jar 272# java-pkg_regjar ${D}/opt/foo/lib/foo.jar
273#
274# WARNING:
275# if you want to use shell expansion, you have to use ${D}/... as the for in
276# this function will not be able to expand the path, here's an example:
277#
278# java-pkg_regjar /opt/my-java/lib/*.jar
279#
280# will not work, because:
281# * the `for jar in "$@"` can't expand the path to jar file names, as they
282# don't exist yet
283# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar'
284# doesn't exist
285#
286# you have to use it as:
287#
288# java-pkg_regjar ${D}/opt/my-java/lib/*.jar
212# 289#
213# @param $@ - jars to record 290# @param $@ - jars to record
214# ------------------------------------------------------------------------------ 291# ------------------------------------------------------------------------------
215# TODO fix me! 292# TODO should we be making sure the jar is present on ${D} or wherever?
216java-pkg_regjar() { 293java-pkg_regjar() {
217 debug-print-function ${FUNCNAME} $* 294 debug-print-function ${FUNCNAME} $*
218 295
219 java-pkg_check-phase install 296 java-pkg_check-phase install
220 297
221 [[ ${#} -lt 1 ]] && die "at least one argument needed" 298 [[ ${#} -lt 1 ]] && die "at least one argument needed"
222 299
223 java-pkg_init_paths_ 300 java-pkg_init_paths_
224 301
225 local jar jar_dir jar_file 302 local jar jar_dir jar_file
226 for jar in "$@"; do 303 for jar in ${@}; do
227 # TODO use java-pkg_check-versioned-jar 304 # 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 305 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
306 [[ -d "${jar}" || -d "${D}${jar}" ]] \
307 && die "Called ${FUNCNAME} on a directory $*"
308 # nelchael: we should strip ${D} in this case too, here's why:
309 # imagine such call:
310 # java-pkg_regjar ${D}/opt/java/*.jar
311 # such call will fall into this case (-e ${jar}) and will
312 # record paths with ${D} in package.env
231 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 313 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
232 else 314 else
233 die "${jar} does not exist" 315 die "${jar} does not exist"
234 fi 316 fi
235 done 317 done
236 318
237 java-pkg_do_write_ 319 java-pkg_do_write_
238} 320}
239 321
240
241# ------------------------------------------------------------------------------ 322# ------------------------------------------------------------------------------
242# @ebuild-function java-pkg_newjar 323# @ebuild-function java-pkg_newjar
243# 324#
244# Installs a jar with a new name 325# Installs a jar with a new name
245# 326#
255 local original_jar="${1}" 336 local original_jar="${1}"
256 local new_jar="${2:-${PN}.jar}" 337 local new_jar="${2:-${PN}.jar}"
257 local new_jar_dest="${T}/${new_jar}" 338 local new_jar_dest="${T}/${new_jar}"
258 339
259 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 340 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
260 [[ ! -f ${original_jar} ]] && die "${new_jar} does not exist!" 341 [[ ! -f ${original_jar} ]] \
342 && die "${original_jar} does not exist or is not a file!"
261 343
262 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 344 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
263 cp "${original_jar}" "${new_jar_dest}" \ 345 cp "${original_jar}" "${new_jar_dest}" \
264 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 346 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
265 java-pkg_dojar "${new_jar_dest}" 347 java-pkg_dojar "${new_jar_dest}"
266} 348}
267 349
268
269# ------------------------------------------------------------------------------ 350# ------------------------------------------------------------------------------
270# @ebuild-function java-pkg_addcp 351# @ebuild-function java-pkg_addcp
271# 352#
272# Add something to the package's classpath. For jars, you should use dojar, 353# 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. 354# newjar, or regjar. This is typically used to add directories to the classpath.
278java-pkg_addcp() { 359java-pkg_addcp() {
279 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}" 360 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
280 java-pkg_do_write_ 361 java-pkg_do_write_
281} 362}
282 363
283
284# ------------------------------------------------------------------------------ 364# ------------------------------------------------------------------------------
285# @ebuild-function java-pkg_doso 365# @ebuild-function java-pkg_doso
286# 366#
287# Installs any number of JNI libraries 367# Installs any number of JNI libraries
288# They will be installed into /usr/lib by default, but java-pkg_sointo 368# They will be installed into /usr/lib by default, but java-pkg_sointo
289# can be used change this path 369# can be used change this path
290# 370#
291# Example: 371# Example:
346 java-pkg_check-phase install 426 java-pkg_check-phase install
347 427
348 [[ ${#} -lt 1 ]] && "at least one argument needed" 428 [[ ${#} -lt 1 ]] && "at least one argument needed"
349 429
350 java-pkg_init_paths_ 430 java-pkg_init_paths_
351 431
352 local lib target_dir 432 local lib target_dir
353 for lib in "$@" ; do 433 for lib in "$@" ; do
354 # Check the absolute path of the lib 434 # Check the absolute path of the lib
355 if [[ -e "${lib}" ]] ; then 435 if [[ -e "${lib}" ]] ; then
356 target_dir="$(java-pkg_expand_dir_ ${lib})" 436 target_dir="$(java-pkg_expand_dir_ ${lib})"
404# ------------------------------------------------------------------------------ 484# ------------------------------------------------------------------------------
405java-pkg_dohtml() { 485java-pkg_dohtml() {
406 debug-print-function ${FUNCNAME} $* 486 debug-print-function ${FUNCNAME} $*
407 487
408 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 488 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
409 # TODO-nichoj find out what exactly -f package-list does 489
490 # from /usr/lib/portage/bin/dohtml -h
491 # -f Set list of allowed extensionless file names.
410 dohtml -f package-list "$@" 492 dohtml -f package-list "$@"
493
411 # this probably shouldn't be here but it provides 494 # this probably shouldn't be here but it provides
412 # a reasonable way to catch # docs for all of the 495 # a reasonable way to catch # docs for all of the
413 # old ebuilds. 496 # old ebuilds.
414 java-pkg_recordjavadoc 497 java-pkg_recordjavadoc
415} 498}
416 499
417# TODO document 500# ------------------------------------------------------------------------------
501# @ebuild-function java-pkg_dojavadoc
502#
503# Installs javadoc documentation. This should be controlled by the doc use flag.
504#
505# @param $1: - The javadoc root directory.
506#
507# @example:
508# java-pkg_dojavadoc docs/api
509#
510# ------------------------------------------------------------------------------
418java-pkg_dojavadoc() { 511java-pkg_dojavadoc() {
419 local dir="$1" 512 local dir="$1"
420 513
421 java-pkg_check-phase install 514 java-pkg_check-phase install
422 515
434} 527}
435 528
436# ------------------------------------------------------------------------------ 529# ------------------------------------------------------------------------------
437# @ebuild-function java-pkg_dosrc 530# @ebuild-function java-pkg_dosrc
438# 531#
439# Installs a zip containing the source for a package, so it can used in 532# Installs a zip containing the source for a package, so it can used in
440# from IDEs like eclipse and netbeans. 533# from IDEs like eclipse and netbeans.
441# 534#
442# Ebuild needs to DEPEND on app-arch/zip to use this. 535# Ebuild needs to DEPEND on app-arch/zip to use this.
443# 536#
444# It also should be controlled by USE=source. 537# It also should be controlled by USE=source.
445# 538#
446# @example: 539# @example:
447# java-pkg_dosrc src/* 540# java-pkg_dosrc src/*
448# 541#
449# ------------------------------------------------------------------------------ 542# ------------------------------------------------------------------------------
450# TODO change so it the arguments it takes are the base directories containing 543# TODO change so it the arguments it takes are the base directories containing
451# source -nichoj 544# source -nichoj
452# TODO should we be able to handle multiple calls to dosrc? -nichoj 545# TODO should we be able to handle multiple calls to dosrc? -nichoj
453# TODO maybe we can take an existing zip/jar? -nichoj 546# TODO maybe we can take an existing zip/jar? -nichoj
454# FIXME apparently this fails if you give it an empty directories 547# FIXME apparently this fails if you give it an empty directories
455java-pkg_dosrc() { 548java-pkg_dosrc() {
456 debug-print-function ${FUNCNAME} $* 549 debug-print-function ${FUNCNAME} $*
457 550
458 [ ${#} -lt 1 ] && die "At least one argument needed" 551 [ ${#} -lt 1 ] && die "At least one argument needed"
459 if ! hasq source ${IUSE}; then 552 if ! hasq source ${IUSE}; then
460 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE" 553 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
461 fi 554 fi
462 555
463 java-pkg_check-phase install 556 java-pkg_check-phase install
464 557
465 [[ ${#} -lt 1 ]] && die "At least one argument needed" 558 [[ ${#} -lt 1 ]] && die "At least one argument needed"
466 559
467 java-pkg_init_paths_ 560 java-pkg_init_paths_
468 561
469 local zip_name="${PN}-src.zip" 562 local zip_name="${PN}-src.zip"
470 local zip_path="${T}/${zip_name}" 563 local zip_path="${T}/${zip_name}"
494# @ebuild-function java-pkg_dolauncher 587# @ebuild-function java-pkg_dolauncher
495# 588#
496# Make a wrapper script to lauch/start this package 589# Make a wrapper script to lauch/start this package
497# If necessary, the wrapper will switch to the appropriate VM. 590# If necessary, the wrapper will switch to the appropriate VM.
498# 591#
592# Can be called without parameters if the package installs only one jar
593# that has the Main-class attribute set. The wrapper will be named ${PN}.
594#
499# @param $1 - filename of launcher to create 595# @param $1 - filename of launcher to create
500# @param $2 - options, as follows: 596# @param $2 - options, as follows:
501# --main the.main.class.too.start 597# --main the.main.class.too.start
502# --jar /the/jar/too/launch.jar 598# --jar /the/jar/too/launch.jar or just <name>.jar
503# --java_args 'Extra arguments to pass too jave' 599# --java_args 'Extra arguments to pass to java'
504# --pkg_args 'extra arguments too pass too the package' 600# --pkg_args 'Extra arguments to pass to the package'
505# --pwd 601# --pwd Directory the launcher changes to before executing java
506# -into 602# -into Directory to install the launcher to, instead of /usr/bin
507# -pre 603# -pre Prepend contents of this file to the launcher
508# ------------------------------------------------------------------------------ 604# ------------------------------------------------------------------------------
509java-pkg_dolauncher() { 605java-pkg_dolauncher() {
510 debug-print-function ${FUNCNAME} $* 606 debug-print-function ${FUNCNAME} $*
511 607
512 java-pkg_check-phase install 608 java-pkg_check-phase install
513
514 [[ ${#} -lt 1 ]] && die "Need at least one argument"
515
516 java-pkg_init_paths_ 609 java-pkg_init_paths_
517 610
611 if [[ ${#} = 0 ]]; then
612 local name="${PN}"
613 else
518 local name="${1}" 614 local name="${1}"
615 shift
616 fi
617
519 # TODO rename to launcher 618 # TODO rename to launcher
520 local target="${T}/${name}" 619 local target="${T}/${name}"
620 local var_tmp="${T}/launcher_variables_tmp"
521 local target_dir pre 621 local target_dir pre
522 shift
523 622
524 echo "#!/bin/bash" > "${target}" 623 # Process the other the rest of the arguments
525 while [[ -n "${1}" && -n "${2}" ]]; do 624 while [[ -n "${1}" && -n "${2}" ]]; do
526 local var=${1} value=${2} 625 local var="${1}" value="${2}"
527 if [[ "${var:0:2}" == "--" ]]; then 626 if [[ "${var:0:2}" == "--" ]]; then
627 local var=${var:2}
528 echo "gjl_${var:2}=\"${value}\"" >> "${target}" 628 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
629 local gjl_${var}="${value}"
529 elif [[ "${var}" == "-into" ]]; then 630 elif [[ "${var}" == "-into" ]]; then
530 target_dir="${value}" 631 target_dir="${value}"
531 elif [[ "${var}" == "-pre" ]]; then 632 elif [[ "${var}" == "-pre" ]]; then
532 pre="${value}" 633 pre="${value}"
533 fi 634 fi
534 shift 2 635 shift 2
535 done 636 done
637
638 # Test if no --jar and --main arguments were given and
639 # in that case check if the package only installs one jar
640 # and use that jar.
641 if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
642 local cp="${JAVA_PKG_CLASSPATH}"
643 if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
644 echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
645 else
646 local msg="Not enough information to create a launcher given."
647 msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
648 die "${msg}"
649 fi
650 fi
651
652 # Write the actual script
653 echo "#!/bin/bash" > "${target}"
654 if [[ -n "${pre}" ]]; then
655 if [[ -f "${pre}" ]]; then
656 cat "${pre}" >> "${target}"
657 else
658 die "-pre specified file '${pre}' does not exist"
659 fi
660 fi
536 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 661 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
537 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 662 cat "${var_tmp}" >> "${target}"
663 rm -f "${var_tmp}"
538 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 664 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
539 665
540 if [[ -n "${into}" ]]; then 666 if [[ -n "${target_dir}" ]]; then
541 DESTTREE="${target_dir}" dobin "${target}" 667 DESTTREE="${target_dir}" dobin "${target}"
542 local ret=$? 668 local ret=$?
543 return ${ret} 669 return ${ret}
544 else 670 else
545 dobin "${target}" 671 dobin "${target}"
573 echo "dowar: warning, skipping directory ${war}" 699 echo "dowar: warning, skipping directory ${war}"
574 continue 700 continue
575 else 701 else
576 warpath="${war}" 702 warpath="${war}"
577 fi 703 fi
578 704
579 # Install those files like you mean it 705 # Install those files like you mean it
580 INSOPTIONS="-m 0644" \ 706 INSOPTIONS="-m 0644" \
581 INSDESTTREE=${JAVA_PKG_WARDEST} \ 707 INSDESTTREE=${JAVA_PKG_WARDEST} \
582 doins ${warpath} 708 doins ${warpath}
583 done 709 done
618# @ebuild-function java-pkg_jar-from 744# @ebuild-function java-pkg_jar-from
619# 745#
620# Makes a symlink to a jar from a certain package 746# Makes a symlink to a jar from a certain package
621# A lot of java packages include dependencies in a lib/ directory 747# A lot of java packages include dependencies in a lib/ directory
622# You can use this function to replace these bundled dependencies. 748# You can use this function to replace these bundled dependencies.
749# The dependency is recorded into package.env DEPEND line, unless "--build-only"
750# is passed as the very first argument, for jars that have to be present only
751# at build time and are not needed on runtime (junit testing etc).
623# 752#
624# Example: get all jars from xerces slot 2 753# Example: get all jars from xerces slot 2
625# java-pkg_jar-from xerces-2 754# java-pkg_jar-from xerces-2
626# Example: get a specific jar from xerces slot 2 755# Example: get a specific jar from xerces slot 2
627# java-pkg_jar-from xerces-2 xml-apis.jar 756# java-pkg_jar-from xerces-2 xml-apis.jar
628# Example get a specific jar from xerces slot 2, and name it diffrently 757# 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 758# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
759# Example: get junit.jar which is needed only for building
760# java-pkg_jar-from --build-only junit junit.jar
630# 761#
762# @param $1 - (optional) "--build-only" makes the jar(s) not added into
763# package.env DEPEND line.
631# @param $1 - Package to get jars from. 764# @param $1 - Package to get jars from.
632# @param $2 - jar from package. If not specified, all jars will be used. 765# @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 766# @param $3 - When a single jar is specified, destination filename of the
634# symlink. Defaults to the name of the jar. 767# symlink. Defaults to the name of the jar.
635# ------------------------------------------------------------------------------ 768# ------------------------------------------------------------------------------
636# TODO could probably be cleaned up a little 769# TODO could probably be cleaned up a little
637java-pkg_jar-from() { 770java-pkg_jar-from() {
638 debug-print-function ${FUNCNAME} $* 771 debug-print-function ${FUNCNAME} $*
639 772
773 local build_only=""
774
775 if [[ "${1}" = "--build-only" || "${EBUILD_PHASE}" == "test" ]]; then
776 build_only="true"
777 shift
778 fi
779
780 if [[ "${1}" = "--with-dependencies" ]]; then
781 local deep="--with-dependencies"
782 shift
783 fi
784
640 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 785 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
641 786
642 [[ -z ${target_pkg} ]] && die "Must specify a package" 787 [[ -z ${target_pkg} ]] && die "Must specify a package"
643 788
644 # default destjar to the target jar 789 # default destjar to the target jar
645 [[ -z "${destjar}" ]] && destjar="${target_jar}" 790 [[ -z "${destjar}" ]] && destjar="${target_jar}"
646 791
792 local error_msg="There was a problem getting the classpath for ${target_pkg}."
793 local classpath
647 local classpath="$(java-config --classpath=${target_pkg})" 794 classpath="$(java-config ${deep} --classpath=${target_pkg})"
648 [[ $? != 0 ]] && die "There was a problem getting the classpath for ${target_pkg}" 795 [[ $? != 0 ]] && die ${error_msg}
649 796
650 local jar 797 local jar
651 for jar in ${classpath//:/ }; do 798 for jar in ${classpath//:/ }; do
652 local jar_name=$(basename "${jar}") 799 local jar_name=$(basename "${jar}")
653 if [[ ! -f "${jar}" ]] ; then 800 if [[ ! -f "${jar}" ]] ; then
657 # If no specific target jar was indicated, link it 804 # If no specific target jar was indicated, link it
658 if [[ -z "${target_jar}" ]] ; then 805 if [[ -z "${target_jar}" ]] ; then
659 [[ -f "${target_jar}" ]] && rm "${target_jar}" 806 [[ -f "${target_jar}" ]] && rm "${target_jar}"
660 ln -snf "${jar}" \ 807 ln -snf "${jar}" \
661 || die "Failed to make symlink from ${jar} to ${jar_name}" 808 || die "Failed to make symlink from ${jar} to ${jar_name}"
662 java-pkg_record-jar_ "${target_pkg}" "${jar}" 809 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
663 # otherwise, if the current jar is the target jar, link it 810 # otherwise, if the current jar is the target jar, link it
664 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 811 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
665 [[ -f "${destjar}" ]] && rm "${destjar}" 812 [[ -f "${destjar}" ]] && rm "${destjar}"
666 ln -snf "${jar}" "${destjar}" \ 813 ln -snf "${jar}" "${destjar}" \
667 || die "Failed to make symlink from ${jar} to ${destjar}" 814 || die "Failed to make symlink from ${jar} to ${destjar}"
668 java-pkg_record-jar_ "${target_pkg}" "${jar}" 815 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
669 return 0 816 return 0
670 fi 817 fi
671 done 818 done
672 # if no target was specified, we're ok 819 # if no target was specified, we're ok
673 if [[ -z "${target_jar}" ]] ; then 820 if [[ -z "${target_jar}" ]] ; then
690# ------------------------------------------------------------------------------ 837# ------------------------------------------------------------------------------
691# @ebuild-function java-pkg_getjars 838# @ebuild-function java-pkg_getjars
692# 839#
693# Get the classpath provided by any number of packages 840# Get the classpath provided by any number of packages
694# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'. 841# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
842# The providing packages are recorded as dependencies into package.env DEPEND
843# line, unless "--build-only" is passed as the very first argument, for jars
844# that have to be present only at build time and are not needed on runtime
845# (junit testing etc).
695# 846#
696# Example: Get the classpath for xerces-2, 847# Example: Get the classpath for xerces-2 and xalan,
697# java-pkg_getjars xerces-2 xalan 848# java-pkg_getjars xerces-2,xalan
698# Example Return: 849# Example Return:
699# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 850# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
700# 851#
852# @param $1 - (optional) "--build-only" makes the jar(s) not added into
853# package.env DEPEND line.
701# @param $@ - list of packages to get jars from 854# @param $2 - list of packages to get jars from
855# (passed to java-config --classpath)
702# ------------------------------------------------------------------------------ 856# ------------------------------------------------------------------------------
703java-pkg_getjars() { 857java-pkg_getjars() {
704 debug-print-function ${FUNCNAME} $* 858 debug-print-function ${FUNCNAME} $*
705 859
706 [[ ${#} -lt 1 ]] && die "At least one argument needed" 860 if [[ "${1}" = "--build-only" || "${EBUILD_PHASE}" == "test" ]]; then
861 local build_only="true"
862 shift
863 fi
707 864
708 # NOTE could probably just pass $@ to java-config --classpath. and return it 865 if [[ "${1}" = "--with-dependencies" ]]; then
866 local deep="--with-dependencies"
867 shift
868 fi
869
870 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --build-only"
871
709 local classpath pkg 872 local classpath pkgs="${1}"
710 for pkg in ${@//,/ }; do
711 #for pkg in $(echo "$@" | tr ',' ' '); do
712 jars="$(java-config --classpath=${pkg})" 873 jars="$(java-config ${deep} --classpath=${pkgs})"
874 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed"
713 debug-print "${pkg}:${jars}" 875 debug-print "${pkgs}:${jars}"
714 # TODO should we ensure jars exist? 876
715 if [[ -z "${classpath}" ]]; then 877 if [[ -z "${classpath}" ]]; then
716 classpath="${jars}" 878 classpath="${jars}"
717 else 879 else
718 classpath="${classpath}:${jars}" 880 classpath="${classpath}:${jars}"
719 fi 881 fi
882
883 # Only record jars that aren't build-only
884 if [[ -z "${build_only}" ]]; then
885 oldifs="${IFS}"
886 IFS=","
887 for pkg in ${pkgs}; do
720 java-pkg_record-jar_ "${pkg}" 888 java-pkg_record-jar_ "${pkg}"
721 done 889 done
890 IFS="${oldifs}"
891 fi
892
722 echo "${classpath}" 893 echo "${classpath}"
723} 894}
724 895
725# ------------------------------------------------------------------------------ 896# ------------------------------------------------------------------------------
726# @ebuild-function java-pkg_getjar 897# @ebuild-function java-pkg_getjar
727# 898#
728# Get the filename of a single jar from a package 899# Get the filename of a single jar from a package
900# The providing package is recorded as runtime dependency into package.env
901# DEPEND line, unless "--build-only" is passed as the very first argument, for
902# jars that have to be present only at build time and are not needed on runtime
903# (junit testing etc).
729# 904#
730# @example 905# @example
731# java-pkg_getjar xerces-2 xml-apis.jar 906# java-pkg_getjar xerces-2 xml-apis.jar
732# @example-return 907# @example-return
733# /usr/share/xerces-2/lib/xml-apis.jar 908# /usr/share/xerces-2/lib/xml-apis.jar
734# 909#
910# @param $1 - (optional) "--build-only" makes the jar not added into
911# package.env DEPEND line.
735# @param $1 - package to use 912# @param $1 - package to use
736# @param $2 - jar to get 913# @param $2 - jar to get
737# ------------------------------------------------------------------------------ 914# ------------------------------------------------------------------------------
738java-pkg_getjar() { 915java-pkg_getjar() {
739 debug-print-function ${FUNCNAME} $* 916 debug-print-function ${FUNCNAME} $*
917
918 local build_only=""
919
920 if [[ "${1}" = "--build-only" || "${EBUILD_PHASE}" == "test" ]]; then
921 build_only="true"
922 shift
923 fi
740 924
741 local pkg="${1}" target_jar="${2}" jar 925 local pkg="${1}" target_jar="${2}" jar
742 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 926 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
743 [[ -z ${target_jar} ]] && die "Must specify jar to get" 927 [[ -z ${target_jar} ]] && die "Must specify jar to get"
744 928
745 # TODO check that package is actually installed 929 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
930 local classpath
746 local classpath=$(java-config --classpath=${pkg}) 931 classpath=$(java-config --classpath=${pkg})
747 [[ $? != 0 ]] && die "There could not find classpath for ${pkg}. Are you sure its installed?" 932 [[ $? != 0 ]] && die ${error_msg}
933
748 for jar in ${classpath//:/ }; do 934 for jar in ${classpath//:/ }; do
749 if [[ ! -f "${jar}" ]] ; then 935 if [[ ! -f "${jar}" ]] ; then
750 die "Installation problems with jars in ${pkg} - is it installed?" 936 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
751 fi 937 fi
752 938
753 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then 939 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
754 java-pkg_record-jar_ "${pkg}" "${jar}" 940 # Only record jars that aren't build-only
941 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" "${jar}"
755 echo "${jar}" 942 echo "${jar}"
756 return 0 943 return 0
757 fi 944 fi
758 done 945 done
759 946
760 die "Could not find ${target_jar} in ${pkg}" 947 die "Could not find ${target_jar} in ${pkg}"
761 return 1 948 return 1
762} 949}
763 950
764# This function reads stdin, and based on that input, figures out how to 951# This function reads stdin, and based on that input, figures out how to
778# line="${line// /}" 965# line="${line// /}"
779# 966#
780# # format: path=jarinfo 967# # format: path=jarinfo
781# local path=${line%%=*} 968# local path=${line%%=*}
782# local jarinfo=${line##*=} 969# local jarinfo=${line##*=}
783# 970#
784# # format: jar@package 971# # format: jar@package
785# local jar=${jarinfo%%@*}.jar 972# local jar=${jarinfo%%@*}.jar
786# local package=${jarinfo##*@} 973# local package=${jarinfo##*@}
787# if [[ -n ${replace_only} ]]; then 974# if [[ -n ${replace_only} ]]; then
788# [[ ! -f $path ]] && die "No jar exists at ${path}" 975# [[ ! -f $path ]] && die "No jar exists at ${path}"
801# @section-end query 988# @section-end query
802# ------------------------------------------------------------------------------ 989# ------------------------------------------------------------------------------
803 990
804# ------------------------------------------------------------------------------ 991# ------------------------------------------------------------------------------
805# @section-begin helper 992# @section-begin helper
806# @section-summary Helper functions 993# @section-summary Helper functions
807# 994#
808# Various other functions to use from an ebuild 995# Various other functions to use from an ebuild
809# ------------------------------------------------------------------------------ 996# ------------------------------------------------------------------------------
810 997
811# ------------------------------------------------------------------------------ 998# ------------------------------------------------------------------------------
817# jdbc-stdext 1004# jdbc-stdext
818# jaf 1005# jaf
819# jdbc-rowset 1006# jdbc-rowset
820# jms 1007# jms
821# 1008#
822# @param $1 - Optionally indicate that the dependencies are controlled by 1009# @param $1 - Optionally indicate that the dependencies are controlled by
823# a use flag by specifying '--use' Requires $2. 1010# a use flag by specifying '--use' Requires $2.
824# @param $2 - USE flag which will enable the dependencies. 1011# @param $2 - USE flag which will enable the dependencies.
825# @param $@ - virtual packages to add depenedencies for 1012# @param $@ - virtual packages to add depenedencies for
826# ------------------------------------------------------------------------------ 1013# ------------------------------------------------------------------------------
827# TODO rewrite to parse a line based declaration file instead -- karltk 1014# TODO rewrite to parse a line based declaration file instead -- karltk
883# 1070#
884# export DEPEND="${DEPEND} ${depstr}" 1071# export DEPEND="${DEPEND} ${depstr}"
885# export RDEPEND="${RDEPEND} ${depstr}" 1072# export RDEPEND="${RDEPEND} ${depstr}"
886#} 1073#}
887 1074
1075# ------------------------------------------------------------------------------
1076# @ebuild-function java-pkg_find-normal-jars
1077#
1078# Find the files with suffix .jar file in the given directory or $WORKDIR
1079#
1080# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1081# ------------------------------------------------------------------------------
1082java-pkg_find-normal-jars() {
1083 local dir=$1
1084 [[ "${dir}" ]] || dir="${WORKDIR}"
1085 local found
1086 for jar in $(find "${dir}" -name "*.jar" -type f); do
1087 echo "${jar}"
1088 found="true"
1089 done
1090 [[ "${found}" ]]
1091 return $?
1092}
1093
1094# ------------------------------------------------------------------------------
1095# @ebuild-function java-pkg_ensure-no-bundled-jars
1096#
1097# 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 1098# This function should be called after WORKDIR has been populated with symlink
889# TODO document 1099# to system jar files or bundled jars removed.
1100# ------------------------------------------------------------------------------
890java-pkg_ensure-no-bundled-jars() { 1101java-pkg_ensure-no-bundled-jars() {
891 debug-print-function ${FUNCNAME} $* 1102 debug-print-function ${FUNCNAME} $*
892 pushd ${WORKDIR} >/dev/null 2>/dev/null
893 1103
894 local bundled_jars=$(find . -name "*.jar" -type f) 1104 local bundled_jars=$(java-pkg_find-normal-jars)
895 if [[ -n ${bundled_jars} ]]; then 1105 if [[ -n ${bundled_jars} ]]; then
896 echo "Bundled jars found:" 1106 echo "Bundled jars found:"
897 local jar 1107 local jar
898 for jar in ${bundled_jars}; do 1108 for jar in ${bundled_jars}; do
899 echo $(pwd)${jar/./} 1109 echo $(pwd)${jar/./}
900 done 1110 done
901 die "Bundled jars found!" 1111 die "Bundled jars found!"
902
903 fi 1112 fi
904 popd >/dev/null 2>/dev/null
905} 1113}
906 1114
907# ------------------------------------------------------------------------------ 1115# ------------------------------------------------------------------------------
908# @internal-function java-pkg_ensure-vm-version-sufficient 1116# @internal-function java-pkg_ensure-vm-version-sufficient
909# 1117#
921 fi 1129 fi
922} 1130}
923 1131
924# ------------------------------------------------------------------------------ 1132# ------------------------------------------------------------------------------
925# @internal-function java-pkg_is-vm-version-sufficient 1133# @internal-function java-pkg_is-vm-version-sufficient
926# 1134#
927# @return zero - VM is sufficient 1135# @return zero - VM is sufficient
928# @return non-zero - VM is not sufficient 1136# @return non-zero - VM is not sufficient
929# ------------------------------------------------------------------------------ 1137# ------------------------------------------------------------------------------
930java-pkg_is-vm-version-sufficient() { 1138java-pkg_is-vm-version-sufficient() {
931 debug-print-function ${FUNCNAME} $* 1139 debug-print-function ${FUNCNAME} $*
951 die "Active Java VM too old" 1159 die "Active Java VM too old"
952 fi 1160 fi
953} 1161}
954 1162
955# ------------------------------------------------------------------------------ 1163# ------------------------------------------------------------------------------
956# @internal-function java-pkg_is-vm-version-eq 1164# @internal-function java-pkg_is-vm-version-eq
957# 1165#
958# @param $@ - VM version to compare current VM to 1166# @param $@ - VM version to compare current VM to
959# @return zero - VM versions are equal 1167# @return zero - VM versions are equal
960# @return non-zero - VM version are not equal 1168# @return non-zero - VM version are not equal
961# ------------------------------------------------------------------------------ 1169# ------------------------------------------------------------------------------
962java-pkg_is-vm-version-eq() { 1170java-pkg_is-vm-version-eq() {
992# 1200#
993# @param $@ - VM version to compare current to 1201# @param $@ - VM version to compare current to
994# ------------------------------------------------------------------------------ 1202# ------------------------------------------------------------------------------
995java-pkg_ensure-vm-version-ge() { 1203java-pkg_ensure-vm-version-ge() {
996 debug-print-function ${FUNCNAME} $* 1204 debug-print-function ${FUNCNAME} $*
997 1205
998 if ! java-pkg_is-vm-version-ge "$@" ; then 1206 if ! java-pkg_is-vm-version-ge "$@" ; then
999 debug-print "vm is not suffient" 1207 debug-print "vm is not suffient"
1000 eerror "This package requires a Java VM version >= $@" 1208 eerror "This package requires a Java VM version >= $@"
1001 einfo "Please use java-config -S to set the correct one" 1209 einfo "Please use java-config -S to set the correct one"
1002 die "Active Java VM too old" 1210 die "Active Java VM too old"
1003 fi 1211 fi
1004} 1212}
1005 1213
1006# ------------------------------------------------------------------------------ 1214# ------------------------------------------------------------------------------
1007# @internal-function java-pkg_is-vm-version-ge 1215# @internal-function java-pkg_is-vm-version-ge
1008# 1216#
1009# @param $@ - VM version to compare current VM to 1217# @param $@ - VM version to compare current VM to
1010# @return zero - current VM version is greater than checked version 1218# @return zero - current VM version is greater than checked version
1011# @return non-zero - current VM version is not greater than checked version 1219# @return non-zero - current VM version is not greater than checked version
1012# ------------------------------------------------------------------------------ 1220# ------------------------------------------------------------------------------
1013java-pkg_is-vm-version-ge() { 1221java-pkg_is-vm-version-ge() {
1027 return 1 1235 return 1
1028 fi 1236 fi
1029 fi 1237 fi
1030} 1238}
1031 1239
1240java-pkg_set-current-vm() {
1241 export GENTOO_VM=${1}
1242}
1243
1244java-pkg_get-current-vm() {
1245 echo ${GENTOO_VM}
1246}
1247
1248java-pkg_current-vm-matches() {
1249 hasq $(java-pkg_get-current-vm) ${@}
1250 return $?
1251}
1252
1032# ------------------------------------------------------------------------------ 1253# ------------------------------------------------------------------------------
1033# @ebuild-function java-pkg_get-source 1254# @ebuild-function java-pkg_get-source
1034# 1255#
1035# Determines what source version should be used, for passing to -source. 1256# 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 1257# Unless you want to break things you probably shouldn't set _WANT_SOURCE
1037# 1258#
1038# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE 1259# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1039# ------------------------------------------------------------------------------ 1260# ------------------------------------------------------------------------------
1044# ------------------------------------------------------------------------------ 1265# ------------------------------------------------------------------------------
1045# @ebuild-function java-pkg_get-target 1266# @ebuild-function java-pkg_get-target
1046# 1267#
1047# Determines what target version should be used, for passing to -target. 1268# 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 1269# If you don't care about lower versions, you can set _WANT_TARGET to the
1049# version of your JDK. 1270# 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# 1271#
1054# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1272# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1055# ------------------------------------------------------------------------------ 1273# ------------------------------------------------------------------------------
1056java-pkg_get-target() { 1274java-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}")} 1275 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1070} 1276}
1071 1277
1072java-pkg_get-javac() { 1278java-pkg_get-javac() {
1073 debug-print-function ${FUNCNAME} $* 1279 debug-print-function ${FUNCNAME} $*
1074 1280
1075 java-pkg_init-compiler_ 1281
1076 local compiler="${GENTOO_COMPILER}" 1282 local compiler="${GENTOO_COMPILER}"
1077 1283
1078 local compiler_executable 1284 local compiler_executable
1079 if [[ "${compiler}" = "javac" ]]; then 1285 if [[ "${compiler}" = "javac" ]]; then
1080 # nothing fancy needs to be done for javac 1286 # nothing fancy needs to be done for javac
1088 unset JAVAC 1294 unset JAVAC
1089 # try to get value of JAVAC 1295 # try to get value of JAVAC
1090 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1296 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1091 export JAVAC=${old_javac} 1297 export JAVAC=${old_javac}
1092 1298
1093 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1299 if [[ -z ${compiler_executable} ]]; then
1094 1300 echo "JAVAC is empty or undefined in ${compiler_env}"
1301 return 1
1302 fi
1303
1095 # check that it's executable 1304 # check that it's executable
1096 if [[ ! -x ${compiler_executable} ]]; then 1305 if [[ ! -x ${compiler_executable} ]]; then
1097 eerror "Could not find ${compiler_executable}!"
1098 die "${compiler_executable} doesn't exist, or isn't executable" 1306 echo "${compiler_executable} doesn't exist, or isn't executable"
1307 return 1
1099 fi 1308 fi
1100 else 1309 else
1101 eerror "Could not find environment file for ${compiler}" 1310 echo "Could not find environment file for ${compiler}"
1102 die "Could not find ${compiler_env}" 1311 return 1
1103 fi 1312 fi
1104 fi 1313 fi
1105 echo ${compiler_executable} 1314 echo ${compiler_executable}
1106} 1315}
1107 1316
1108# ------------------------------------------------------------------------------ 1317# ------------------------------------------------------------------------------
1109# @ebuild-function java-pkg_javac-args 1318# @ebuild-function java-pkg_javac-args
1110# 1319#
1111# If an ebuild uses javac directly, instead of using ejavac, it should call this 1320# If an ebuild uses javac directly, instead of using ejavac, it should call this
1112# to know what -source/-target to use. 1321# to know what -source/-target to use.
1113# 1322#
1114# @return string - arguments to pass to javac, complete with -target and -source 1323# @return string - arguments to pass to javac, complete with -target and -source
1117 debug-print-function ${FUNCNAME} $* 1326 debug-print-function ${FUNCNAME} $*
1118 1327
1119 local want_source="$(java-pkg_get-source)" 1328 local want_source="$(java-pkg_get-source)"
1120 local want_target="$(java-pkg_get-target)" 1329 local want_target="$(java-pkg_get-target)"
1121 1330
1122 local source_str="-source ${want_source}" 1331 local source_str="-source ${want_source}"
1123 local target_str="-target ${want_target}" 1332 local target_str="-target ${want_target}"
1124 1333
1125 debug-print "want source: ${want_source}" 1334 debug-print "want source: ${want_source}"
1126 debug-print "want target: ${want_target}" 1335 debug-print "want target: ${want_target}"
1127 1336
1128 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1337 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1129 debug-print "could not find valid -source/-target values" 1338 debug-print "could not find valid -source/-target values for javac"
1130 die "Could not find valid -source/-target values" 1339 echo "Could not find valid -source/-target values for javac"
1340 return 1
1131 else 1341 else
1132 if java-pkg_is-vm-version-ge "1.4"; then 1342 if java-pkg_is-vm-version-ge "1.4"; then
1133 echo "${source_str} ${target_str}" 1343 echo "${source_str} ${target_str}"
1134 else 1344 else
1135 echo "${target_str}" 1345 echo "${target_str}"
1139 1349
1140# TODO document 1350# TODO document
1141java-pkg_get-jni-cflags() { 1351java-pkg_get-jni-cflags() {
1142 local flags="-I${JAVA_HOME}/include" 1352 local flags="-I${JAVA_HOME}/include"
1143 1353
1144 # TODO figure out how to cope with other things than linux... 1354 local platform="linux"
1355 use elibc_FreeBSD && platform="freebsd"
1356
1357 # TODO do a check that the directories are valid
1145 flags="${flags} -I${JAVA_HOME}/include/linux" 1358 flags="${flags} -I${JAVA_HOME}/include/${platform}"
1146 1359
1147 echo ${flags} 1360 echo ${flags}
1361}
1362
1363java-pkg_ensure-gcj() {
1364 if ! built_with_use sys-devel/gcc gcj ; then
1365 ewarn
1366 ewarn "You must build gcc with the gcj support to build with gcj"
1367 ewarn
1368 ebeep 5
1369 die "No GCJ support found!"
1370 fi
1371}
1372
1373java-pkg_ensure-test() {
1374 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \
1375 && hasq test ${IUSE} && ! use test;
1376 then
1377 eerror "You specified FEATURES=test, but USE=test is needed"
1378 eerror "to pull in the additional dependencies for testing"
1379 die "Need USE=test enabled"
1380 fi
1381}
1382
1383# ------------------------------------------------------------------------------
1384# @ebuild-function java-pkg_register-ant-task
1385#
1386# Register this package as ant task, so that ant will load it when no specific
1387# ANT_TASKS are specified. Note that even without this registering, all packages
1388# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1389# packages, but can be also used by other ebuilds that used to symlink their
1390# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1391# compatibility.
1392#
1393# @param --version x.y Register only for ant version x.y (otherwise for any ant
1394# version). Used by the ant-* packages to prevent loading of mismatched
1395# ant-core ant tasks after core was updated, before the tasks are updated,
1396# without a need for blockers.
1397# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1398# ------------------------------------------------------------------------------
1399java-pkg_register-ant-task() {
1400 local TASKS_DIR="tasks"
1401
1402 # check for --version x.y parameters
1403 while [[ -n "${1}" && -n "${2}" ]]; do
1404 local var="${1#--}"
1405 local val="${2}"
1406 if [[ "${var}" == "version" ]]; then
1407 TASKS_DIR="tasks-${val}"
1408 else
1409 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1410 fi
1411 shift 2
1412 done
1413
1414 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1415
1416 dodir /usr/share/ant/${TASKS_DIR}
1417 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1418}
1419
1420# ------------------------------------------------------------------------------
1421# @internal-function java-pkg_ant-tasks-from-deps
1422#
1423# Function to determine ANT_TASKS from DEPEND variable for backwards
1424# compatibility with ebuilds that don't set ANT_TASKS before calling eant() or
1425# WANT_ANT_TASKS before inheriting java-pkg-2. If the DEPEND string contains
1426# "dev-java/ant" or "dev-java/ant-tasks", then it returns "all", otherwise
1427# "none". It's not smart enough to cope with USE flag depends but that shouldn't
1428# be a problem, the worst it can do is activace all tasks when not needed.
1429# Note that this is called only with JAVA_PKG_STRICT=1, to find ebuilds with
1430# insufficient dependencies, otherwise all available tasks are used for
1431# backwards compatilbility.
1432#
1433# @return "all" or "none"
1434# ------------------------------------------------------------------------------
1435java-pkg_ant-tasks-from-deps() {
1436 local found_ant found_ant_tasks
1437
1438 for dep in ${DEPEND}
1439 do
1440 local ant="$(awk '/(dev-java\/ant)/ { if (match($1, "(dev-java/ant)((-[0-9])+|$)", m)) print m[1] }' <<< ${dep})"
1441 [[ "${ant}" == "dev-java/ant" ]] && found_ant=true
1442 [[ "${dep}" == *"ant-tasks"* ]] && found_ant_tasks=true
1443 done
1444
1445 if [[ -n "${found_ant}" || -n "${found_ant_tasks}" ]]; then
1446 java-pkg_announce-qa-violation "The ebuild DEPENDS on deprecated ant or ant-tasks"
1447 echo "all"
1448 else
1449 # ebuild doesn't set ANT_TASKS and doesn't depend on ant-tasks or ant
1450 # so we deactivate all tasks that may be installed
1451 echo "none"
1452 fi
1453}
1454
1455# ------------------------------------------------------------------------------
1456# @internal-function java-pkg_ant-tasks-depend
1457#
1458# Translates the WANT_ANT_TASKS variable into valid dependencies.
1459# ------------------------------------------------------------------------------
1460java-pkg_ant-tasks-depend() {
1461 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1462
1463 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1464 local DEP=""
1465 for i in ${WANT_ANT_TASKS}
1466 do
1467 if [[ ${i} != ant-* ]]; then
1468 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1469 return 1
1470 fi
1471 DEP="${DEP}dev-java/${i} "
1472 done
1473 echo ${DEP}
1474 return 0
1475 else
1476 return 0
1477 fi
1148} 1478}
1149 1479
1150# ------------------------------------------------------------------------------ 1480# ------------------------------------------------------------------------------
1151# @section-end helper 1481# @section-end helper
1152# ------------------------------------------------------------------------------ 1482# ------------------------------------------------------------------------------
1161 1491
1162# ------------------------------------------------------------------------------ 1492# ------------------------------------------------------------------------------
1163# @ebuild-function eant 1493# @ebuild-function eant
1164# 1494#
1165# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1495# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1166# compiler. 1496# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1167# 1497# variables:
1498# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1499# gentoo.classpath property. Be sure to call
1500# java-ant_rewrite-classpath in src_unpack.
1501# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1168# ------------------------------------------------------------------------------ 1502# ------------------------------------------------------------------------------
1169eant() { 1503eant() {
1170 debug-print-function ${FUNCNAME} $* 1504 debug-print-function ${FUNCNAME} $*
1171 1505
1172 local antflags 1506 # FIXME get this working
1507# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then
1508# java-pkg_announce-qa-violation \
1509# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1510# fi
1511
1512 local antflags="-Dnoget=true -Dmaven.mode.offline=true"
1173 java-pkg_init-compiler_ 1513 java-pkg_init-compiler_
1174 local compiler="${GENTOO_COMPILER}" 1514 local compiler="${GENTOO_COMPILER}"
1175 1515
1176 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1516 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1177 1517
1179 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1519 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1180 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1520 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1181 fi 1521 fi
1182 1522
1183 if [[ ${compiler} != "javac" ]]; then 1523 if [[ ${compiler} != "javac" ]]; then
1184 antflags="-Dbuild.compiler=${build_compiler}" 1524 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1185 # Figure out any extra stuff to put on the classpath for compilers aside 1525 # Figure out any extra stuff to put on the classpath for compilers aside
1186 # from javac 1526 # from javac
1187 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to 1527 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1188 # java-config -p 1528 # java-config -p
1189 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1529 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 1530 if [[ -n ${build_compiler_deps} ]]; then
1191 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})" 1531 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1192 fi 1532 fi
1193 fi 1533 fi
1194 1534
1195 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1535 if is-java-strict; then
1196 antflags="${antflags} -debug" 1536 einfo "Disabling system classpath for ant"
1537 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1538 fi
1539
1540 if has_version ">=dev-java/ant-core-1.7.0"; then
1541 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1542 ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}"
1543
1544 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1545 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1546
1547 if is-java-strict; then
1548 # if ant-tasks were not set by ebuild or forced, try to determine them from depends
1549 if [[ -z "${ANT_TASKS}" ]]; then
1550 ANT_TASKS="$(java-pkg_ant-tasks-from-deps)"
1551 fi
1552 else
1553 # if ant-tasks is not set by ebuild or forced, activate all of them
1554 ANT_TASKS="${ANT_TASKS:-all}"
1197 fi 1555 fi
1198 1556
1557 # at this point, ANT_TASKS should be "all", "none" or explicit list
1558 if [[ "${ANT_TASKS}" == "all" ]]; then
1559 einfo "Using all available ANT_TASKS"
1560 elif [[ "${ANT_TASKS}" == "none" ]]; then
1561 einfo "Disabling all optional ANT_TASKS"
1562 else
1563 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1564 fi
1565
1566 export ANT_TASKS
1567 fi
1568
1569 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1570 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1571
1572 local gcp="${EANT_GENTOO_CLASSPATH}"
1573
1574 if [[ "${gcp}" ]]; then
1575 local cp="$(java-pkg_getjars ${gcp})"
1576 # It seems ant does not like single quotes around ${cp}
1577 antflags="${antflags} -Dgentoo.classpath=\"${cp}\""
1578 fi
1579
1199 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1580 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1581 debug-print "Calling ant: ${antflags} ${@}"
1200 ant ${antflags} "${@}" || die "eant failed" 1582 ant ${antflags} "${@}" || die "eant failed"
1201 1583
1202} 1584}
1203 1585
1204# ------------------------------------------------------------------------------ 1586# ------------------------------------------------------------------------------
1205# @ebuild-function ejavac 1587# @ebuild-function ejavac
1206# 1588#
1207# Javac wrapper function. Will use the appropriate compiler, based on 1589# Javac wrapper function. Will use the appropriate compiler, based on
1208# /etc/java-config/compilers.conf 1590# /etc/java-config/compilers.conf
1209# 1591#
1210# @param $@ - Arguments to be passed to the compiler 1592# @param $@ - Arguments to be passed to the compiler
1211# ------------------------------------------------------------------------------ 1593# ------------------------------------------------------------------------------
1212ejavac() { 1594ejavac() {
1213 debug-print-function ${FUNCNAME} $* 1595 debug-print-function ${FUNCNAME} $*
1214 1596
1597 java-pkg_init-compiler_
1598
1599 local compiler_executable
1215 local compiler_executable=$(java-pkg_get-javac) 1600 compiler_executable=$(java-pkg_get-javac)
1601 if [[ ${?} != 0 ]]; then
1602 eerror "There was a problem determining compiler: ${compiler_executable}"
1603 die "get-javac failed"
1604 fi
1216 1605
1606 local javac_args
1607 javac_args="$(java-pkg_javac-args)"
1608 if [[ ${?} != 0 ]]; then
1609 eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
1610 die "java-pkg_javac-args failed"
1611 fi
1612
1217 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 1613 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1218 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 1614 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1219} 1615}
1220 1616
1221# ------------------------------------------------------------------------------ 1617# ------------------------------------------------------------------------------
1222# @ebuild-function java-pkg_filter-compiler 1618# @ebuild-function java-pkg_filter-compiler
1223# 1619#
1224# Used to prevent the use of some compilers. Should be used in src_compile. 1620# Used to prevent the use of some compilers. Should be used in src_compile.
1225# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER 1621# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
1226# 1622#
1227# @param $@ - compilers to filter 1623# @param $@ - compilers to filter
1228# ------------------------------------------------------------------------------ 1624# ------------------------------------------------------------------------------
1229java-pkg_filter-compiler() { 1625java-pkg_filter-compiler() {
1230 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@" 1626 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@"
1231} 1627}
1232 1628
1233# ------------------------------------------------------------------------------ 1629# ------------------------------------------------------------------------------
1630# @ebuild-function java-pkg_force-compiler
1631#
1632# Used to force the use of particular compilers. Should be used in src_compile.
1633# A common use of this would be to force ecj-3.1 to be used on amd64, to avoid
1634# OutOfMemoryErrors that may come up.
1635#
1636# @param $@ - compilers to force
1637# ------------------------------------------------------------------------------
1638java-pkg_force-compiler() {
1639 JAVA_PKG_FORCE_COMPILER="$@"
1640}
1641
1642# ------------------------------------------------------------------------------
1234# @ebuild-function use_doc 1643# @ebuild-function use_doc
1235# 1644#
1236# Helper function for getting ant to build javadocs. If the user has USE=doc, 1645# 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. 1646# then 'javadoc' or the argument are returned. Otherwise, there is no return.
1238# 1647#
1239# The output of this should be passed to ant. 1648# The output of this should be passed to ant.
1240# 1649#
1241# Example: build javadocs by calling 'javadoc' target 1650# Example: build javadocs by calling 'javadoc' target
1242# eant $(use_doc) 1651# eant $(use_doc)
1243# Example: build javadocs by calling 'apidoc' target 1652# Example: build javadocs by calling 'apidoc' target
1248# ------------------------------------------------------------------------------ 1657# ------------------------------------------------------------------------------
1249use_doc() { 1658use_doc() {
1250 use doc && echo ${@:-javadoc} 1659 use doc && echo ${@:-javadoc}
1251} 1660}
1252 1661
1662
1253# ------------------------------------------------------------------------------ 1663# ------------------------------------------------------------------------------
1254# @section-end build 1664# @section-end build
1255# ------------------------------------------------------------------------------ 1665# ------------------------------------------------------------------------------
1256 1666
1257# ------------------------------------------------------------------------------ 1667# ------------------------------------------------------------------------------
1258# @section-begin internal 1668# @section-begin internal
1259# @section-summary Internal functions 1669# @section-summary Internal functions
1260# 1670#
1261# Do __NOT__ use any of these from an ebuild! These are only to be used from 1671# Do __NOT__ use any of these from an ebuild! These are only to be used from
1262# within the java eclasses. 1672# within the java eclasses.
1263# ------------------------------------------------------------------------------ 1673# ------------------------------------------------------------------------------
1264 1674
1265# ----------------------------------------------------------------------------- 1675# -----------------------------------------------------------------------------
1266# @function-internal java-pkg_init 1676# @function-internal java-pkg_init
1267# 1677#
1268# The purpose of this function, as the name might imply, is to initialize the 1678# 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 1679# 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 1680# that'll muss things up. It initializes some variables, which are used
1271# internally. And most importantly, it'll switch the VM if necessary. 1681# internally. And most importantly, it'll switch the VM if necessary.
1272# 1682#
1284 # TODO we will probably want to set JAVAC and JAVACFLAGS 1694 # TODO we will probably want to set JAVAC and JAVACFLAGS
1285 1695
1286 # Do some QA checks 1696 # Do some QA checks
1287 java-pkg_check-jikes 1697 java-pkg_check-jikes
1288 1698
1289 # When users have crazy classpaths some packages can fail to compile. 1699 # When users have crazy classpaths some packages can fail to compile.
1290 # and everything should work with empty CLASSPATH. 1700 # and everything should work with empty CLASSPATH.
1291 # This also helps prevent unexpected dependencies on random things 1701 # This also helps prevent unexpected dependencies on random things
1292 # from the CLASSPATH. 1702 # from the CLASSPATH.
1293 unset CLASSPATH 1703 unset CLASSPATH
1704
1705 # Unset external ANT_ stuff
1706 unset ANT_TASKS
1707 unset ANT_OPTS
1294} 1708}
1295 1709
1296# ------------------------------------------------------------------------------ 1710# ------------------------------------------------------------------------------
1297# @function-internal java-pkg-init-compiler_ 1711# @function-internal java-pkg-init-compiler_
1298# 1712#
1299# This function attempts to figure out what compiler should be used. It does 1713# 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 1714# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
1301# COMPILERS variable defined there. 1715# COMPILERS variable defined there.
1302# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER 1716# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
1303# 1717#
1304# It will go through the list of compilers, and verify that it supports the 1718# 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 1719# 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 1720# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
1307# isn't done. 1721# isn't done.
1308# 1722#
1330 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1744 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1331 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})" 1745 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
1332 else 1746 else
1333 compilers=${JAVA_PKG_FORCE_COMPILER} 1747 compilers=${JAVA_PKG_FORCE_COMPILER}
1334 fi 1748 fi
1335 1749
1336 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}" 1750 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
1337 1751
1338 # Figure out if we should announce what compiler we're using 1752 # Figure out if we should announce what compiler we're using
1339 local compiler 1753 local compiler
1340 for compiler in ${compilers}; do 1754 for compiler in ${compilers}; do
1343 if [[ ${compiler} = "javac" ]]; then 1757 if [[ ${compiler} = "javac" ]]; then
1344 debug-print "Found javac... breaking" 1758 debug-print "Found javac... breaking"
1345 export GENTOO_COMPILER="javac" 1759 export GENTOO_COMPILER="javac"
1346 break 1760 break
1347 fi 1761 fi
1348 1762
1349 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then 1763 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
1350 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1764 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1351 einfo "Filtering ${compiler}" 1765 einfo "Filtering ${compiler}"
1352 continue 1766 continue
1353 fi 1767 fi
1354 fi 1768 fi
1355 1769
1356 # for non-javac, we need to make sure it supports the right target and 1770 # for non-javac, we need to make sure it supports the right target and
1357 # source 1771 # source
1358 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1772 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1359 if [[ -f ${compiler_env} ]]; then 1773 if [[ -f ${compiler_env} ]]; then
1360 local desired_target="$(java-pkg_get-target)" 1774 local desired_target="$(java-pkg_get-target)"
1442# Writes the package.env out to disk. 1856# Writes the package.env out to disk.
1443# 1857#
1444# ------------------------------------------------------------------------------ 1858# ------------------------------------------------------------------------------
1445# TODO change to do-write, to match everything else 1859# TODO change to do-write, to match everything else
1446java-pkg_do_write_() { 1860java-pkg_do_write_() {
1861 java-pkg_init_paths_
1447 # Create directory for package.env 1862 # Create directory for package.env
1448 dodir "${JAVA_PKG_SHAREPATH}" 1863 dodir "${JAVA_PKG_SHAREPATH}"
1449 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 1864 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then
1450 # Create package.env 1865 # Create package.env
1451 ( 1866 (
1456 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 1871 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1457 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 1872 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1458 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 1873 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\""
1459 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 1874 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1460 ) > "${JAVA_PKG_ENV}" 1875 ) > "${JAVA_PKG_ENV}"
1461 1876
1462 # register target/source 1877 # register target/source
1463 local target="$(java-pkg_get-target)" 1878 local target="$(java-pkg_get-target)"
1464 local source="$(java-pkg_get-source)" 1879 local source="$(java-pkg_get-source)"
1465 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}" 1880 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
1466 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}" 1881 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
1479 # Strip unnecessary leading and trailing colons 1894 # Strip unnecessary leading and trailing colons
1480 # TODO try to cleanup if possible 1895 # TODO try to cleanup if possible
1481 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 1896 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
1482 fi 1897 fi
1483} 1898}
1484
1485 1899
1486# ------------------------------------------------------------------------------ 1900# ------------------------------------------------------------------------------
1487# @internal-function java-pkg_record-jar_ 1901# @internal-function java-pkg_record-jar_
1488# 1902#
1489# Record a dependency to the package.env 1903# Record a dependency to the package.env
1533 fi 1947 fi
1534} 1948}
1535 1949
1536# ------------------------------------------------------------------------------ 1950# ------------------------------------------------------------------------------
1537# @internal-function java-pkg_expand_dir_ 1951# @internal-function java-pkg_expand_dir_
1538# 1952#
1539# Gets the full path of the file/directory's parent. 1953# Gets the full path of the file/directory's parent.
1540# @param $1 - file/directory to find parent directory for 1954# @param $1 - file/directory to find parent directory for
1541# @return - path to $1's parent directory 1955# @return - path to $1's parent directory
1542# ------------------------------------------------------------------------------ 1956# ------------------------------------------------------------------------------
1543java-pkg_expand_dir_() { 1957java-pkg_expand_dir_() {
1570# ------------------------------------------------------------------------------ 1984# ------------------------------------------------------------------------------
1571java-pkg_setup-vm() { 1985java-pkg_setup-vm() {
1572 debug-print-function ${FUNCNAME} $* 1986 debug-print-function ${FUNCNAME} $*
1573 1987
1574 local vendor="$(java-pkg_get-vm-vendor)" 1988 local vendor="$(java-pkg_get-vm-vendor)"
1575 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge 1 5; then 1989 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1576 addpredict "/dev/random" 1990 addpredict "/dev/random"
1577 elif [[ "${vendor}" == "ibm" ]]; then 1991 elif [[ "${vendor}" == "ibm" ]]; then
1578 addpredict "/proc/self/maps" 1992 addpredict "/proc/self/maps"
1579 addpredict "/proc/cpuinfo" 1993 addpredict "/proc/cpuinfo"
1580 export LANG="C" LC_ALL="C" 1994 export LANG="C" LC_ALL="C"
1629# @return - The version of the current VM 2043# @return - The version of the current VM
1630# ------------------------------------------------------------------------------ 2044# ------------------------------------------------------------------------------
1631java-pkg_get-vm-version() { 2045java-pkg_get-vm-version() {
1632 debug-print-function ${FUNCNAME} $* 2046 debug-print-function ${FUNCNAME} $*
1633 2047
1634 java-pkg_get-current-vm | sed -e "s/.*-\([0-9.]\+\).*/\1/" 2048 java-config -g PROVIDES_VERSION
1635} 2049}
1636 2050
1637# ------------------------------------------------------------------------------ 2051# ------------------------------------------------------------------------------
1638# @internal-function java-pkg_switch-vm 2052# @internal-function java-pkg_switch-vm
1639# 2053#
1640# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 2054# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1641# verify that the current VM is sufficient. 2055# verify that the current VM is sufficient.
1642# Setup the environment for the VM being used. 2056# Setup the environment for the VM being used.
1643# ------------------------------------------------------------------------------ 2057# ------------------------------------------------------------------------------
1644java-pkg_switch-vm() { 2058java-pkg_switch-vm() {
2059 debug-print-function ${FUNCNAME} $*
2060
1645 if java-pkg_needs-vm; then 2061 if java-pkg_needs-vm; then
1646 # Use the VM specified by JAVA_PKG_FORCE_VM 2062 # Use the VM specified by JAVA_PKG_FORCE_VM
1647 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then 2063 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1648 # If you're forcing the VM, I hope you know what your doing... 2064 # If you're forcing the VM, I hope you know what your doing...
2065 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1649 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 2066 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1650 # if we're allowed to switch the vm... 2067 # if we're allowed to switch the vm...
1651 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 2068 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1652 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}" 2069 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1653 if [[ -n ${JAVA_PKG_VNEED} ]]; then 2070 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1654 export GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2071 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1655 else 2072 else
1656 export GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2073 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
2074 fi
2075 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
2076 eerror "Unable to determine VM for building from dependencies:"
2077 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
2078 echo "VNEED: ${JAVA_PKG_VNEED}"
2079 die "Failed to determine VM for building."
2080 else
2081 export GENTOO_VM
1657 fi 2082 fi
1658 # otherwise just make sure the current VM is sufficient 2083 # otherwise just make sure the current VM is sufficient
1659 else 2084 else
1660 java-pkg_ensure-vm-version-sufficient 2085 java-pkg_ensure-vm-version-sufficient
1661 fi 2086 fi
1662 debug-print "Using: $(java-config -f)" 2087 debug-print "Using: $(java-config -f)"
1663 2088
1664 java-pkg_setup-vm 2089 java-pkg_setup-vm
1665 2090
1666 export JAVA=$(java-config -java) 2091 export JAVA=$(java-config --java)
1667 export JAVAC=$(java-config -javac) 2092 export JAVAC=$(java-config --javac)
1668 export JAVACFLAGS="$(java-pkg_javac-args)" 2093 JAVACFLAGS="$(java-pkg_javac-args)"
2094 if [[ ${?} != 0 ]]; then
2095 eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
2096 die "java-pkg_javac-args failed"
2097 fi
1669 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 2098 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
2099 export JAVACFLAGS
1670 2100
1671 export JAVA_HOME="$(java-config -g JAVA_HOME)" 2101 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1672 export JDK_HOME=${JAVA_HOME} 2102 export JDK_HOME=${JAVA_HOME}
1673 2103
1674 #TODO If you know a better solution let us know. 2104 #TODO If you know a better solution let us know.
1675 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 2105 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1676 2106
1677 local tann="${T}/announced-vm" 2107 local tann="${T}/announced-vm"
1678 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 2108 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1679 # Add a check for setup/preinst phase... to avoid duplicate outputs 2109 # Add a check for setup/preinst phase... to avoid duplicate outputs
1680 # for when FEATURES=buildpkg 2110 # for when FEATURES=buildpkg
1681 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]]; 2111 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1706 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2 2136 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2
1707 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2 2137 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2
1708 echo "and of course, the output of emerge --info" >&2 2138 echo "and of course, the output of emerge --info" >&2
1709} 2139}
1710 2140
2141
2142# TODO document
2143# List jars in the source directory, ${S}
2144java-pkg_jar-list() {
2145 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
2146 einfo "Linked Jars"
2147 find "${S}" -type l -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2148 einfo "Jars"
2149 find "${S}" -type f -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2150 einfo "Classes"
2151 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2152 fi
2153}
2154
2155# TODO document
2156# Verify that the classes were compiled for the right source / target
2157java-pkg_verify-classes() {
2158 ebegin "Verifying java class versions"
2159 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
2160 class-version-verify.py -t $(java-pkg_get-target) -r ${D}
2161 result=$?
2162 eend ${result}
2163 if [[ ${result} == 0 ]]; then
2164 einfo "All good"
2165 else
2166 ewarn "Possible problem"
2167 die "Bad class files found"
2168 fi
2169}
2170
1711# ------------------------------------------------------------------------------ 2171# ------------------------------------------------------------------------------
1712# @section-end internal 2172# @section-end internal
1713# ------------------------------------------------------------------------------ 2173# ------------------------------------------------------------------------------
1714 2174
1715java-pkg_check-phase() { 2175java-pkg_check-phase() {
1716 local phase=${1} 2176 local phase=${1}
1717 local funcname=${2} 2177 local funcname=${2}
1718 # TODO add check for java-stricter
1719 if [[ ${EBUILD_PHASE} != ${phase} ]]; then 2178 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then
1720 java-pkg_announce-qa-violation \ 2179 java-pkg_announce-qa-violation \
1721 "${funcname} used outside of src_${phase}" 2180 "${funcname} used outside of src_${phase}"
1722 fi 2181 fi
1723} 2182}
1724 2183
1735 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2194 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1736 fi 2195 fi
1737} 2196}
1738 2197
1739java-pkg_announce-qa-violation() { 2198java-pkg_announce-qa-violation() {
1740 if hasq java-strict ${FEATURES}; then 2199 if is-java-strict; then
1741 echo "Java QA Notice: $@" >&2 2200 echo "Java QA Notice: $@" >&2
1742 increment-qa-violations 2201 increment-qa-violations
1743 fi 2202 fi
1744} 2203}
1745 2204
1746increment-qa-violations() { 2205increment-qa-violations() {
1747 let "JAVA_PKG_QA_VIOLATIONS+=1" 2206 let "JAVA_PKG_QA_VIOLATIONS+=1"
1748 export JAVA_PKG_QA_VIOLATIONS 2207 export JAVA_PKG_QA_VIOLATIONS
1749} 2208}
1750 2209
2210is-java-strict() {
2211 [[ -n ${JAVA_PKG_STRICT} ]]
2212 return $?
2213}
2214
1751# ------------------------------------------------------------------------------ 2215# ------------------------------------------------------------------------------
1752# @eclass-end 2216# @eclass-end
1753# ------------------------------------------------------------------------------ 2217# ------------------------------------------------------------------------------

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

  ViewVC Help
Powered by ViewVC 1.1.20