/[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.22 Revision 1.87
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 9# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.87 2007/05/27 11:09:11 betelgeuse Exp $
10 10
11# ----------------------------------------------------------------------------- 11# -----------------------------------------------------------------------------
12# @eclass-begin 12# @eclass-begin
13# @eclass-shortdesc Java Utility eclass 13# @eclass-shortdesc Java Utility eclass
14# @eclass-maintainer java@gentoo.org 14# @eclass-maintainer java@gentoo.org
23# 23#
24# ----------------------------------------------------------------------------- 24# -----------------------------------------------------------------------------
25 25
26inherit eutils versionator multilib 26inherit eutils versionator multilib
27 27
28IUSE="elibc_FreeBSD"
29
28# ----------------------------------------------------------------------------- 30# -----------------------------------------------------------------------------
29# @section-begin variables 31# @section-begin variables
30# @section-title Variables 32# @section-title Variables
31# 33#
32# Summary of variables which control the behavior of building Java packges. 34# Summary of variables which control the behavior of building Java packges.
33# ----------------------------------------------------------------------------- 35# -----------------------------------------------------------------------------
34 36
35# Make sure we use java-config-2 37# Make sure we use java-config-2
36export WANT_JAVA_CONFIG="2" 38export WANT_JAVA_CONFIG="2"
37 39
38# TODO document 40# -----------------------------------------------------------------------------
41# @variable-external WANT_ANT_TASKS
42# @variable-default ""
43#
44# An $IFS separated list of ant tasks.
45# Ebuild can specify this variable before inheriting java-ant-2 eclass to
46# determine ANT_TASKS it needs. They will be automatically translated to
47# DEPEND variable and ANT_TASKS variable. JAVA_PKG_FORCE_ANT_TASKS can override
48# ANT_TASKS set by WANT_ANT_TASKS, but not the DEPEND due to caching.
49# Ebuilds that need to depend conditionally on certain tasks and specify them
50# differently for different eant calls can't use this simplified approach.
51# You also cannot specify version or anything else than ant-*.
52#
53# @example WANT_ANT_TASKS="ant-junit ant-trax"
54#
55# @seealso JAVA_PKG_FORCE_ANT_TASKS
56# -----------------------------------------------------------------------------
57#WANT_ANT_TASKS
58
59# -----------------------------------------------------------------------------
60# @variable-internal JAVA_PKG_PORTAGE_DEP
61#
62# The version of portage we need to function properly. At this moment it's
63# portage with phase hooks support.
64# -----------------------------------------------------------------------------
39JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1" 65JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1"
40 66
41# ----------------------------------------------------------------------------- 67# -----------------------------------------------------------------------------
42# @variable-internal JAVA_PKG_E_DEPEND 68# @variable-internal JAVA_PKG_E_DEPEND
43# 69#
44# 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
45# 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
46# portage, that includes phase hooks. 72# portage, that includes phase hooks.
47# ----------------------------------------------------------------------------- 73# -----------------------------------------------------------------------------
48JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 ${JAVA_PKG_PORTAGE_DEP}" 74JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.31 ${JAVA_PKG_PORTAGE_DEP}"
49 75
50# ----------------------------------------------------------------------------- 76# -----------------------------------------------------------------------------
51# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 77# @variable-external JAVA_PKG_ALLOW_VM_CHANGE
52# @variable-default yes 78# @variable-default yes
53# 79#
127# @note This should only be used internally or for testing. 153# @note This should only be used internally or for testing.
128# @example Use jikes and javac, in that order 154# @example Use jikes and javac, in that order
129# JAVA_PKG_FORCE_COMPILER="jikes javac" 155# JAVA_PKG_FORCE_COMPILER="jikes javac"
130# ----------------------------------------------------------------------------- 156# -----------------------------------------------------------------------------
131 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
132# TODO document me 172# TODO document me
133JAVA_PKG_QA_VIOLATIONS=0 173JAVA_PKG_QA_VIOLATIONS=0
134 174
135# ----------------------------------------------------------------------------- 175# -----------------------------------------------------------------------------
136# @section-end variables 176# @section-end variables
143# 183#
144# These are used to install Java-related things, such as jars, Javadocs, JNI 184# These are used to install Java-related things, such as jars, Javadocs, JNI
145# libraries, etc. 185# libraries, etc.
146# ----------------------------------------------------------------------------- 186# -----------------------------------------------------------------------------
147 187
188# -----------------------------------------------------------------------------
189# @ebuild-function java-pkg_doexamples
190#
191# Installs given arguments to /usr/share/doc/${PF}/examples
192# If you give it only one parameter and it is a directory it will install
193# everything in that directory to the examples directory.
194#
195# @example
196# java-pkg_doexamples demo
197# java-pkg_doexamples demo/* examples/*
198#
199# @param $* - list of files to install
200# ------------------------------------------------------------------------------
201java-pkg_doexamples() {
202 debug-print-function ${FUNCNAME} $*
203
204 [[ ${#} -lt 1 ]] && die "At least one argument needed"
205
206 java-pkg_check-phase install
207
208 local dest=/usr/share/doc/${PF}/examples
209 if [[ ${#} = 1 && -d ${1} ]]; then
210 ( # dont want to pollute calling env
211 insinto "${dest}"
212 doins -r ${1}/*
213 ) || die "Installing examples failed"
214 else
215 ( # dont want to pollute calling env
216 insinto "${dest}"
217 doins -r "$@"
218 ) || die "Installing examples failed"
219 fi
220}
148 221
149# ----------------------------------------------------------------------------- 222# -----------------------------------------------------------------------------
150# @ebuild-function java-pkg_dojar 223# @ebuild-function java-pkg_dojar
151# 224#
152# Installs any number of jars. 225# Installs any number of jars.
171 # Create JARDEST if it doesn't exist 244 # Create JARDEST if it doesn't exist
172 dodir ${JAVA_PKG_JARDEST} 245 dodir ${JAVA_PKG_JARDEST}
173 246
174 local jar 247 local jar
175 # for each jar 248 # for each jar
176 for jar in "$@"; do 249 for jar in "${@}"; do
177 local jar_basename=$(basename "${jar}") 250 local jar_basename=$(basename "${jar}")
178 251
179 java-pkg_check-versioned-jar ${jar_basename} 252 java-pkg_check-versioned-jar ${jar_basename}
180 253
181 # check if it exists 254 # check if it exists
182 if [[ -e "${jar}" ]] ; then 255 if [[ -e "${jar}" ]] ; then
256 # Don't overwrite if jar has already been installed with the same
257 # name
258 local dest="${D}${JAVA_PKG_JARDEST}/${jar_basename}"
259 if [[ -e "${dest}" ]]; then
260 ewarn "Overwriting ${dest}"
261 fi
262
183 # install it into JARDEST if it's a non-symlink 263 # install it into JARDEST if it's a non-symlink
184 if [[ ! -L "${jar}" ]] ; then 264 if [[ ! -L "${jar}" ]] ; then
265 #but first check class version when in strict mode.
266 is-java-strict && java-pkg_verify-classes "${jar}"
267
185 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 268 INSDESTTREE="${JAVA_PKG_JARDEST}" \
186 doins "${jar}" || die "failed to install ${jar}" 269 doins "${jar}" || die "failed to install ${jar}"
187 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 270 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
188 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}" 271 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}"
189 # make a symlink to the original jar if it's symlink 272 # make a symlink to the original jar if it's symlink
200 283
201 java-pkg_do_write_ 284 java-pkg_do_write_
202} 285}
203 286
204 287
288# ------------------------------------------------------------------------------
289# @internal-function depend-java-query
290#
291# Wrapper for the depend-java-query binary to enable passing USE in env.
292# Using env variables keeps this eclass working with java-config versions that
293# do not handle use flags.
294# ------------------------------------------------------------------------------
295
296depend-java-query() {
297 # Used to have a which call here but it caused endless loops for some people
298 # that had some weird bashrc voodoo for which.
299 USE="${USE}" /usr/bin/depend-java-query "${@}"
300}
205 301
206# ------------------------------------------------------------------------------ 302# ------------------------------------------------------------------------------
207# @ebuild-function java-pkg_regjar 303# @ebuild-function java-pkg_regjar
208# 304#
209# Records an already installed jar in the package.env 305# Records an already installed jar in the package.env
240 [[ ${#} -lt 1 ]] && die "at least one argument needed" 336 [[ ${#} -lt 1 ]] && die "at least one argument needed"
241 337
242 java-pkg_init_paths_ 338 java-pkg_init_paths_
243 339
244 local jar jar_dir jar_file 340 local jar jar_dir jar_file
245 for jar in "$@"; do 341 for jar in "${@}"; do
246 # TODO use java-pkg_check-versioned-jar 342 # TODO use java-pkg_check-versioned-jar
247 if [[ -e "${jar}" ]]; then 343 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
344 [[ -d "${jar}" || -d "${D}${jar}" ]] \
345 && die "Called ${FUNCNAME} on a directory $*"
346
347 #check that class version correct when in strict mode
348 is-java-strict && java-pkg_verify-classes "${jar}"
349
248 # nelchael: we should strip ${D} in this case too, here's why: 350 # nelchael: we should strip ${D} in this case too, here's why:
249 # imagine such call: 351 # imagine such call:
250 # java-pkg_regjar ${D}/opt/java/*.jar 352 # java-pkg_regjar ${D}/opt/java/*.jar
251 # such call will fall into this case (-e ${jar}) and will 353 # such call will fall into this case (-e ${jar}) and will
252 # record paths with ${D} in package.env 354 # record paths with ${D} in package.env
253 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 355 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
254 elif [[ -e "${D}${jar}" ]]; then
255 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
256 else 356 else
357 if [[ ${jar} = *\** ]]; then
358 eerror "The argument ${jar} to ${FUNCNAME}"
359 eerror "has * in it. If you want it to glob in"
360 eerror '${D} add ${D} to the argument.'
361 fi
257 die "${jar} does not exist" 362 die "${jar} does not exist"
258 fi 363 fi
259 done 364 done
260 365
261 java-pkg_do_write_ 366 java-pkg_do_write_
262} 367}
263
264 368
265# ------------------------------------------------------------------------------ 369# ------------------------------------------------------------------------------
266# @ebuild-function java-pkg_newjar 370# @ebuild-function java-pkg_newjar
267# 371#
268# Installs a jar with a new name 372# Installs a jar with a new name
279 local original_jar="${1}" 383 local original_jar="${1}"
280 local new_jar="${2:-${PN}.jar}" 384 local new_jar="${2:-${PN}.jar}"
281 local new_jar_dest="${T}/${new_jar}" 385 local new_jar_dest="${T}/${new_jar}"
282 386
283 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 387 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
284 [[ ! -f ${original_jar} ]] && die "${original_jar} does not exist!" 388 [[ ! -f ${original_jar} ]] \
389 && die "${original_jar} does not exist or is not a file!"
285 390
286 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 391 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
287 cp "${original_jar}" "${new_jar_dest}" \ 392 cp "${original_jar}" "${new_jar_dest}" \
288 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 393 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
289 java-pkg_dojar "${new_jar_dest}" 394 java-pkg_dojar "${new_jar_dest}"
290} 395}
291 396
292
293# ------------------------------------------------------------------------------ 397# ------------------------------------------------------------------------------
294# @ebuild-function java-pkg_addcp 398# @ebuild-function java-pkg_addcp
295# 399#
296# Add something to the package's classpath. For jars, you should use dojar, 400# Add something to the package's classpath. For jars, you should use dojar,
297# newjar, or regjar. This is typically used to add directories to the classpath. 401# newjar, or regjar. This is typically used to add directories to the classpath.
301# ------------------------------------------------------------------------------ 405# ------------------------------------------------------------------------------
302java-pkg_addcp() { 406java-pkg_addcp() {
303 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}" 407 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
304 java-pkg_do_write_ 408 java-pkg_do_write_
305} 409}
306
307 410
308# ------------------------------------------------------------------------------ 411# ------------------------------------------------------------------------------
309# @ebuild-function java-pkg_doso 412# @ebuild-function java-pkg_doso
310# 413#
311# Installs any number of JNI libraries 414# Installs any number of JNI libraries
340 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 443 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
341 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 444 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
342 # otherwise make a symlink to the symlink's origin 445 # otherwise make a symlink to the symlink's origin
343 else 446 else
344 # TODO use dosym 447 # TODO use dosym
448 ln -s "$(readlink "${lib}")" \
345 ln -s "$(readlink "${lib}")" "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")" 449 "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")"
346 debug-print "${lib} is a symlink, linking accordanly" 450 debug-print "${lib} is a symlink, linking accordanly"
347 fi 451 fi
348 # otherwise die 452 # otherwise die
349 else 453 else
350 die "${lib} does not exist" 454 die "${lib} does not exist"
428# ------------------------------------------------------------------------------ 532# ------------------------------------------------------------------------------
429java-pkg_dohtml() { 533java-pkg_dohtml() {
430 debug-print-function ${FUNCNAME} $* 534 debug-print-function ${FUNCNAME} $*
431 535
432 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 536 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
433 # TODO-nichoj find out what exactly -f package-list does 537
538 # from /usr/lib/portage/bin/dohtml -h
539 # -f Set list of allowed extensionless file names.
434 dohtml -f package-list "$@" 540 dohtml -f package-list "$@"
541
435 # this probably shouldn't be here but it provides 542 # this probably shouldn't be here but it provides
436 # a reasonable way to catch # docs for all of the 543 # a reasonable way to catch # docs for all of the
437 # old ebuilds. 544 # old ebuilds.
438 java-pkg_recordjavadoc 545 java-pkg_recordjavadoc
439} 546}
440 547
441# TODO document 548# ------------------------------------------------------------------------------
549# @ebuild-function java-pkg_dojavadoc
550#
551# Installs javadoc documentation. This should be controlled by the doc use flag.
552#
553# @param $1: - The javadoc root directory.
554#
555# @example:
556# java-pkg_dojavadoc docs/api
557#
558# ------------------------------------------------------------------------------
442java-pkg_dojavadoc() { 559java-pkg_dojavadoc() {
560 debug-print-function ${FUNCNAME} $*
443 local dir="$1" 561 local dir="$1"
562
563 # QA checks
444 564
445 java-pkg_check-phase install 565 java-pkg_check-phase install
446 566
447 [[ -z "${dir}" ]] && die "Must specify a directory!" 567 [[ -z "${dir}" ]] && die "Must specify a directory!"
448 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!" 568 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!"
569 if [[ ! -e "${dir}/index.html" ]]; then
570 local msg="No index.html in javadoc directory"
571 ewarn "${msg}"
572 is-java-strict && die "${msg}"
573 fi
574
575 # Renaming to match our directory layout
449 576
450 local dir_to_install="${dir}" 577 local dir_to_install="${dir}"
451 if [[ "$(basename "${dir}")" != "api" ]]; then 578 if [[ "$(basename "${dir}")" != "api" ]]; then
452 dir_to_install="${T}/api" 579 dir_to_install="${T}/api"
453 # TODO use doins 580 # TODO use doins
454 cp -r "${dir}" "${dir_to_install}" || die "cp failed" 581 cp -r "${dir}" "${dir_to_install}" || die "cp failed"
455 fi 582 fi
583
584 # Actual installation
456 585
457 java-pkg_dohtml -r ${dir_to_install} 586 java-pkg_dohtml -r ${dir_to_install}
458} 587}
459 588
460# ------------------------------------------------------------------------------ 589# ------------------------------------------------------------------------------
478# FIXME apparently this fails if you give it an empty directories 607# FIXME apparently this fails if you give it an empty directories
479java-pkg_dosrc() { 608java-pkg_dosrc() {
480 debug-print-function ${FUNCNAME} $* 609 debug-print-function ${FUNCNAME} $*
481 610
482 [ ${#} -lt 1 ] && die "At least one argument needed" 611 [ ${#} -lt 1 ] && die "At least one argument needed"
483 if ! hasq source ${IUSE}; then
484 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
485 fi
486 612
487 java-pkg_check-phase install 613 java-pkg_check-phase install
488 614
489 [[ ${#} -lt 1 ]] && die "At least one argument needed" 615 [[ ${#} -lt 1 ]] && die "At least one argument needed"
616
617 if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
618 local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
619 if is-java-strict; then
620 eerror "${msg}"
621 die "${msg}"
622 else
623 echo "${msg}"
624 echo "Please report this to http://bugs.gentoo.org."
625 fi
626 fi
490 627
491 java-pkg_init_paths_ 628 java-pkg_init_paths_
492 629
493 local zip_name="${PN}-src.zip" 630 local zip_name="${PN}-src.zip"
494 local zip_path="${T}/${zip_name}" 631 local zip_path="${T}/${zip_name}"
495 local dir 632 local dir
496 for dir in ${@}; do 633 for dir in "${@}"; do
497 local dir_parent=$(dirname "${dir}") 634 local dir_parent=$(dirname "${dir}")
498 local dir_name=$(basename "${dir}") 635 local dir_name=$(basename "${dir}")
499 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 636 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
500 zip -q -r ${zip_path} ${dir_name} -i '*.java' 637 zip -q -r ${zip_path} ${dir_name} -i '*.java'
501 local result=$? 638 local result=$?
518# @ebuild-function java-pkg_dolauncher 655# @ebuild-function java-pkg_dolauncher
519# 656#
520# Make a wrapper script to lauch/start this package 657# Make a wrapper script to lauch/start this package
521# If necessary, the wrapper will switch to the appropriate VM. 658# If necessary, the wrapper will switch to the appropriate VM.
522# 659#
660# Can be called without parameters if the package installs only one jar
661# that has the Main-class attribute set. The wrapper will be named ${PN}.
662#
523# @param $1 - filename of launcher to create 663# @param $1 - filename of launcher to create
524# @param $2 - options, as follows: 664# @param $2 - options, as follows:
525# --main the.main.class.too.start 665# --main the.main.class.too.start
526# --jar /the/jar/too/launch.jar 666# --jar /the/jar/too/launch.jar or just <name>.jar
527# --java_args 'Extra arguments to pass to java' 667# --java_args 'Extra arguments to pass to java'
528# --pkg_args 'Extra arguments too pass to the package' 668# --pkg_args 'Extra arguments to pass to the package'
529# --pwd 669# --pwd Directory the launcher changes to before executing java
530# -into 670# -into Directory to install the launcher to, instead of /usr/bin
531# -pre 671# -pre Prepend contents of this file to the launcher
532# ------------------------------------------------------------------------------ 672# ------------------------------------------------------------------------------
533java-pkg_dolauncher() { 673java-pkg_dolauncher() {
534 debug-print-function ${FUNCNAME} $* 674 debug-print-function ${FUNCNAME} $*
535 675
536 java-pkg_check-phase install 676 java-pkg_check-phase install
537
538 [[ ${#} -lt 1 ]] && die "Need at least one argument"
539
540 java-pkg_init_paths_ 677 java-pkg_init_paths_
541 678
679 if [[ ${#} = 0 ]]; then
680 local name="${PN}"
681 else
542 local name="${1}" 682 local name="${1}"
683 shift
684 fi
685
543 # TODO rename to launcher 686 # TODO rename to launcher
544 local target="${T}/${name}" 687 local target="${T}/${name}"
545 local var_tmp="${T}/launcher_variables_tmp" 688 local var_tmp="${T}/launcher_variables_tmp"
546 local target_dir pre 689 local target_dir pre
547 shift
548 690
549 # Process the other the rest of the arguments 691 # Process the other the rest of the arguments
550 while [[ -n "${1}" && -n "${2}" ]]; do 692 while [[ -n "${1}" && -n "${2}" ]]; do
551 local var=${1} value=${2} 693 local var="${1}" value="${2}"
552 if [[ "${var:0:2}" == "--" ]]; then 694 if [[ "${var:0:2}" == "--" ]]; then
695 local var=${var:2}
553 echo "gjl_${var:2}=\"${value}\"" >> "${var_tmp}" 696 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
697 local gjl_${var}="${value}"
554 elif [[ "${var}" == "-into" ]]; then 698 elif [[ "${var}" == "-into" ]]; then
555 target_dir="${value}" 699 target_dir="${value}"
556 elif [[ "${var}" == "-pre" ]]; then 700 elif [[ "${var}" == "-pre" ]]; then
557 pre="${value}" 701 pre="${value}"
558 fi 702 fi
559 shift 2 703 shift 2
560 done 704 done
561 705
706 # Test if no --jar and --main arguments were given and
707 # in that case check if the package only installs one jar
708 # and use that jar.
709 if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
710 local cp="${JAVA_PKG_CLASSPATH}"
711 if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
712 echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
713 else
714 local msg="Not enough information to create a launcher given."
715 msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
716 die "${msg}"
717 fi
718 fi
719
562 # Write the actual script 720 # Write the actual script
563 echo "#!/bin/bash" > "${target}" 721 echo "#!/bin/bash" > "${target}"
564 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 722 if [[ -n "${pre}" ]]; then
723 if [[ -f "${pre}" ]]; then
724 cat "${pre}" >> "${target}"
725 else
726 die "-pre specified file '${pre}' does not exist"
727 fi
728 fi
565 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 729 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
566 cat "${var_tmp}" >> "${target}" 730 cat "${var_tmp}" >> "${target}"
567 rm -f "${var_tmp}" 731 rm -f "${var_tmp}"
568 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 732 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
569 733
661# Example: get a specific jar from xerces slot 2, and name it diffrently 825# Example: get a specific jar from xerces slot 2, and name it diffrently
662# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 826# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
663# Example: get junit.jar which is needed only for building 827# Example: get junit.jar which is needed only for building
664# java-pkg_jar-from --build-only junit junit.jar 828# java-pkg_jar-from --build-only junit junit.jar
665# 829#
666# @param $1 - (optional) "--build-only" makes the jar(s) not added into 830# @param $opt
667# package.env DEPEND line. 831# --build-only - makes the jar(s) not added into package.env DEPEND line.
668# @param $1 - Package to get jars from. 832# (assumed automatically when called inside src_test)
833# --with-dependencies - get jars also from requested package's dependencies
834# transitively.
835# --into $dir - symlink jar(s) into $dir (must exist) instead of .
836# @param $1 - Package to get jars from, or comma-separated list of packages in
837# case other parameters are not used.
669# @param $2 - jar from package. If not specified, all jars will be used. 838# @param $2 - jar from package. If not specified, all jars will be used.
670# @param $3 - When a single jar is specified, destination filename of the 839# @param $3 - When a single jar is specified, destination filename of the
671# symlink. Defaults to the name of the jar. 840# symlink. Defaults to the name of the jar.
672# ------------------------------------------------------------------------------ 841# ------------------------------------------------------------------------------
673# TODO could probably be cleaned up a little 842# TODO could probably be cleaned up a little
674java-pkg_jar-from() { 843java-pkg_jar-from() {
675 debug-print-function ${FUNCNAME} $* 844 debug-print-function ${FUNCNAME} $*
676 845
677 local build_only="" 846 local build_only=""
847 local destdir="."
848 local deep=""
678 849
850 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
851
852 while [[ "${1}" == --* ]]; do
679 if [[ "${1}" = "--build-only" ]]; then 853 if [[ "${1}" = "--build-only" ]]; then
680 build_only="true" 854 build_only="build"
855 elif [[ "${1}" = "--with-dependencies" ]]; then
856 deep="--with-dependencies"
857 elif [[ "${1}" = "--into" ]]; then
858 destdir="${2}"
859 shift
860 else
861 die "java-pkg_jar-from called with unknown parameter: ${1}"
862 fi
681 shift 863 shift
682 fi 864 done
683 865
684 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 866 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
685 867
686 [[ -z ${target_pkg} ]] && die "Must specify a package" 868 [[ -z ${target_pkg} ]] && die "Must specify a package"
687 869
688 # default destjar to the target jar 870 # default destjar to the target jar
689 [[ -z "${destjar}" ]] && destjar="${target_jar}" 871 [[ -z "${destjar}" ]] && destjar="${target_jar}"
690 872
691 local error_msg="There was a problem getting the classpath for ${target_pkg}." 873 local error_msg="There was a problem getting the classpath for ${target_pkg}."
692 local classpath 874 local classpath
693 classpath="$(java-config --classpath=${target_pkg})" 875 classpath="$(java-config ${deep} --classpath=${target_pkg})"
694 [[ $? != 0 ]] && die ${error_msg} 876 [[ $? != 0 ]] && die ${error_msg}
877
878 # When we have commas this functions is called to bring jars from multiple
879 # packages. This affects recording of dependencencies performed later
880 # which expects one package only, so we do it here.
881 if [[ ${target_pkg} = *,* ]]; then
882 for pkg in ${target_pkg//,/ }; do
883 java-pkg_ensure-dep "${build_only}" "${pkg}"
884 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
885 done
886 # setting this disables further record-jar_ calls later
887 build_only="build"
888 else
889 java-pkg_ensure-dep "${build_only}" "${target_pkg}"
890 fi
891
892 pushd ${destdir} > /dev/null \
893 || die "failed to change directory to ${destdir}"
695 894
696 local jar 895 local jar
697 for jar in ${classpath//:/ }; do 896 for jar in ${classpath//:/ }; do
698 local jar_name=$(basename "${jar}") 897 local jar_name=$(basename "${jar}")
699 if [[ ! -f "${jar}" ]] ; then 898 if [[ ! -f "${jar}" ]] ; then
710 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 909 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
711 [[ -f "${destjar}" ]] && rm "${destjar}" 910 [[ -f "${destjar}" ]] && rm "${destjar}"
712 ln -snf "${jar}" "${destjar}" \ 911 ln -snf "${jar}" "${destjar}" \
713 || die "Failed to make symlink from ${jar} to ${destjar}" 912 || die "Failed to make symlink from ${jar} to ${destjar}"
714 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}" 913 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
914 popd > /dev/null
715 return 0 915 return 0
716 fi 916 fi
717 done 917 done
918 popd > /dev/null
718 # if no target was specified, we're ok 919 # if no target was specified, we're ok
719 if [[ -z "${target_jar}" ]] ; then 920 if [[ -z "${target_jar}" ]] ; then
720 return 0 921 return 0
721 # otherwise, die bitterly 922 # otherwise, die bitterly
722 else 923 else
741# The providing packages are recorded as dependencies into package.env DEPEND 942# The providing packages are recorded as dependencies into package.env DEPEND
742# line, unless "--build-only" is passed as the very first argument, for jars 943# line, unless "--build-only" is passed as the very first argument, for jars
743# that have to be present only at build time and are not needed on runtime 944# that have to be present only at build time and are not needed on runtime
744# (junit testing etc). 945# (junit testing etc).
745# 946#
746# Example: Get the classpath for xerces-2, 947# Example: Get the classpath for xerces-2 and xalan,
747# java-pkg_getjars xerces-2 xalan 948# java-pkg_getjars xerces-2,xalan
748# Example Return: 949# Example Return:
749# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 950# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
750# 951#
751# @param $1 - (optional) "--build-only" makes the jar(s) not added into 952# @param $opt
752# package.env DEPEND line. 953# --build-only - makes the jar(s) not added into package.env DEPEND line.
954# (assumed automatically when called inside src_test)
955# --with-dependencies - get jars also from requested package's dependencies
956# transitively.
753# @param $@ - list of packages to get jars from 957# @param $1 - list of packages to get jars from
958# (passed to java-config --classpath)
754# ------------------------------------------------------------------------------ 959# ------------------------------------------------------------------------------
755java-pkg_getjars() { 960java-pkg_getjars() {
756 debug-print-function ${FUNCNAME} $* 961 debug-print-function ${FUNCNAME} $*
757 962
758 local build_only="" 963 local build_only=""
964 local deep=""
759 965
966 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
967
968 while [[ "${1}" == --* ]]; do
760 if [[ "${1}" = "--build-only" ]]; then 969 if [[ "${1}" = "--build-only" ]]; then
761 build_only="true" 970 build_only="build"
971 elif [[ "${1}" = "--with-dependencies" ]]; then
972 deep="--with-dependencies"
973 else
974 die "java-pkg_jar-from called with unknown parameter: ${1}"
975 fi
762 shift 976 shift
763 fi
764
765 [[ ${#} -lt 1 ]] && die "At least one argument needed"
766
767 # NOTE could probably just pass $@ to java-config --classpath. and return it
768 local classpath pkg
769 for pkg in ${@//,/ }; do
770 #for pkg in $(echo "$@" | tr ',' ' '); do
771 jars="$(java-config --classpath=${pkg})"
772 [[ -z "${jars}" ]] && die "java-config --classpath=${pkg} failed"
773 debug-print "${pkg}:${jars}"
774
775 if [[ -z "${classpath}" ]]; then
776 classpath="${jars}"
777 else
778 classpath="${classpath}:${jars}"
779 fi
780 # Only record jars that aren't build-only
781 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
782 done 977 done
978
979 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
980
981
982 local classpath pkgs="${1}"
983 jars="$(java-config ${deep} --classpath=${pkgs})"
984 [[ $? != 0 || -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed"
985 debug-print "${pkgs}:${jars}"
986
987 for pkg in ${pkgs//,/ }; do
988 java-pkg_ensure-dep "${build_only}" "${pkg}"
989 done
990
991 if [[ -z "${classpath}" ]]; then
992 classpath="${jars}"
993 else
994 classpath="${classpath}:${jars}"
995 fi
996
997 # Only record jars that aren't build-only
998 if [[ -z "${build_only}" ]]; then
999 for pkg in ${pkgs//,/ }; do
1000 java-pkg_record-jar_ "${pkg}"
1001 done
1002 fi
1003
783 echo "${classpath}" 1004 echo "${classpath}"
784} 1005}
785 1006
786# ------------------------------------------------------------------------------ 1007# ------------------------------------------------------------------------------
787# @ebuild-function java-pkg_getjar 1008# @ebuild-function java-pkg_getjar
795# @example 1016# @example
796# java-pkg_getjar xerces-2 xml-apis.jar 1017# java-pkg_getjar xerces-2 xml-apis.jar
797# @example-return 1018# @example-return
798# /usr/share/xerces-2/lib/xml-apis.jar 1019# /usr/share/xerces-2/lib/xml-apis.jar
799# 1020#
800# @param $1 - (optional) "--build-only" makes the jar not added into 1021# @param $opt
801# package.env DEPEND line. 1022# --build-only - makes the jar not added into package.env DEPEND line.
802# @param $1 - package to use 1023# @param $1 - package to use
803# @param $2 - jar to get 1024# @param $2 - jar to get
804# ------------------------------------------------------------------------------ 1025# ------------------------------------------------------------------------------
805java-pkg_getjar() { 1026java-pkg_getjar() {
806 debug-print-function ${FUNCNAME} $* 1027 debug-print-function ${FUNCNAME} $*
807 1028
808 local build_only="" 1029 local build_only=""
809 1030
1031 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1032
1033 while [[ "${1}" == --* ]]; do
810 if [[ "${1}" = "--build-only" ]]; then 1034 if [[ "${1}" = "--build-only" ]]; then
811 build_only="true" 1035 build_only="build"
1036 else
1037 die "java-pkg_jar-from called with unknown parameter: ${1}"
1038 fi
812 shift 1039 shift
813 fi 1040 done
1041
1042 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
814 1043
815 local pkg="${1}" target_jar="${2}" jar 1044 local pkg="${1}" target_jar="${2}" jar
816 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 1045 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
817 [[ -z ${target_jar} ]] && die "Must specify jar to get" 1046 [[ -z ${target_jar} ]] && die "Must specify jar to get"
818 1047
819 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?" 1048 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
820 local classpath 1049 local classpath
821 classpath=$(java-config --classpath=${pkg}) 1050 classpath=$(java-config --classpath=${pkg})
822 [[ $? != 0 ]] && die ${error_msg} 1051 [[ $? != 0 ]] && die ${error_msg}
1052
1053 java-pkg_ensure-dep "${build_only}" "${pkg}"
823 1054
824 for jar in ${classpath//:/ }; do 1055 for jar in ${classpath//:/ }; do
825 if [[ ! -f "${jar}" ]] ; then 1056 if [[ ! -f "${jar}" ]] ; then
826 die "Installation problem with jar ${jar} in ${pkg} - is it installed?" 1057 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
827 fi 1058 fi
834 fi 1065 fi
835 done 1066 done
836 1067
837 die "Could not find ${target_jar} in ${pkg}" 1068 die "Could not find ${target_jar} in ${pkg}"
838 return 1 1069 return 1
1070}
1071
1072# ------------------------------------------------------------------------------
1073# @ebuild-function java-pkg_register-dependency
1074#
1075# Registers runtime dependency on a package, list of packages, or a single jar
1076# from a package, into package.env DEPEND line. Can only be called in
1077# src_install phase.
1078# Intended for binary packages where you don't need to symlink the jars or get
1079# their classpath during build. As such, the dependencies only need to be
1080# specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1081# Get the classpath provided by any number of packages.
1082#
1083# @param $1 - comma-separated list of packages, or a single package
1084# @param $2 - if param $1 is a single package, optionally specify the jar
1085# to depend on
1086#
1087# Example: Record the dependency on whole xerces-2 and xalan,
1088# java-pkg_register-dependency xerces-2,xalan
1089# Example: Record the dependency on ant.jar from ant-core
1090# java-pkg_register-dependency ant-core ant.jar
1091#
1092# Note: Passing both list of packages as the first parameter AND specifying the
1093# jar as the second is not allowed and will cause the function to die. We assume
1094# that there's more chance one passes such combination as a mistake, than that
1095# there are more packages providing identically named jar without class
1096# collisions.
1097# ------------------------------------------------------------------------------
1098java-pkg_register-dependency() {
1099 debug-print-function ${FUNCNAME} $*
1100
1101 java-pkg_check-phase install
1102
1103 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1104
1105 local pkgs="${1}"
1106 local jar="${2}"
1107
1108 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1109
1110 if [[ -z "${jar}" ]]; then
1111 for pkg in ${pkgs//,/ }; do
1112 java-pkg_ensure-dep runtime "${pkg}"
1113 java-pkg_record-jar_ "${pkg}"
1114 done
1115 else
1116 [[ ${pkgs} == *,* ]] && \
1117 die "${FUNCNAME} called with both package list and jar name"
1118 java-pkg_ensure-dep runtime "${pkgs}"
1119 java-pkg_record-jar_ "${pkgs}" "${jar}"
1120 fi
1121
1122 java-pkg_do_write_
1123}
1124
1125# ------------------------------------------------------------------------------
1126# @ebuild-function java-pkg_register-environment-variable
1127#
1128# Register an arbitrary environment variable into package.env. The gjl launcher
1129# for this package or any package depending on this will export it into
1130# environement before executing java command.
1131# Must only be called in src_install phase.
1132#
1133# @param $1 - variable name
1134# @param $2 - variable value
1135# ------------------------------------------------------------------------------
1136JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
1137JAVA_PKG_EXTRA_ENV_VARS=""
1138java-pkg_register-environment-variable() {
1139 debug-print-function ${FUNCNAME} $*
1140
1141 java-pkg_check-phase install
1142
1143 [[ ${#} != 2 ]] && die "${FUNCNAME} takes two arguments"
1144
1145 echo "${1}=\"${2}\"" >> ${JAVA_PKG_EXTRA_ENV}
1146 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
1147
1148 java-pkg_do_write_
839} 1149}
840 1150
841# This function reads stdin, and based on that input, figures out how to 1151# This function reads stdin, and based on that input, figures out how to
842# populate jars from the filesystem. 1152# populate jars from the filesystem.
843# Need to figure out a good way of making use of this, ie be able to use a 1153# Need to figure out a good way of making use of this, ie be able to use a
960# 1270#
961# export DEPEND="${DEPEND} ${depstr}" 1271# export DEPEND="${DEPEND} ${depstr}"
962# export RDEPEND="${RDEPEND} ${depstr}" 1272# export RDEPEND="${RDEPEND} ${depstr}"
963#} 1273#}
964 1274
1275# ------------------------------------------------------------------------------
1276# @ebuild-function java-pkg_find-normal-jars
1277#
1278# Find the files with suffix .jar file in the given directory or $WORKDIR
1279#
1280# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1281# ------------------------------------------------------------------------------
1282java-pkg_find-normal-jars() {
1283 local dir=$1
1284 [[ "${dir}" ]] || dir="${WORKDIR}"
1285 local found
1286 for jar in $(find "${dir}" -name "*.jar" -type f); do
1287 echo "${jar}"
1288 found="true"
1289 done
1290 [[ "${found}" ]]
1291 return $?
1292}
1293
1294# ------------------------------------------------------------------------------
1295# @ebuild-function java-pkg_ensure-no-bundled-jars
1296#
1297# Try to locate bundled jar files in ${WORKDIR} and die if found.
965# This should be used after S has been populated with symlinks to jars 1298# This function should be called after WORKDIR has been populated with symlink
966# TODO document 1299# to system jar files or bundled jars removed.
1300# ------------------------------------------------------------------------------
967java-pkg_ensure-no-bundled-jars() { 1301java-pkg_ensure-no-bundled-jars() {
968 debug-print-function ${FUNCNAME} $* 1302 debug-print-function ${FUNCNAME} $*
969 pushd ${WORKDIR} >/dev/null 2>/dev/null
970 1303
971 local bundled_jars=$(find . -name "*.jar" -type f) 1304 local bundled_jars=$(java-pkg_find-normal-jars)
972 if [[ -n ${bundled_jars} ]]; then 1305 if [[ -n ${bundled_jars} ]]; then
973 echo "Bundled jars found:" 1306 echo "Bundled jars found:"
974 local jar 1307 local jar
975 for jar in ${bundled_jars}; do 1308 for jar in ${bundled_jars}; do
976 echo $(pwd)${jar/./} 1309 echo $(pwd)${jar/./}
977 done 1310 done
978 die "Bundled jars found!" 1311 die "Bundled jars found!"
979
980 fi 1312 fi
981 popd >/dev/null 2>/dev/null
982} 1313}
983 1314
984# ------------------------------------------------------------------------------ 1315# ------------------------------------------------------------------------------
985# @internal-function java-pkg_ensure-vm-version-sufficient 1316# @internal-function java-pkg_ensure-vm-version-sufficient
986# 1317#
1135# @ebuild-function java-pkg_get-target 1466# @ebuild-function java-pkg_get-target
1136# 1467#
1137# Determines what target version should be used, for passing to -target. 1468# Determines what target version should be used, for passing to -target.
1138# If you don't care about lower versions, you can set _WANT_TARGET to the 1469# If you don't care about lower versions, you can set _WANT_TARGET to the
1139# version of your JDK. 1470# version of your JDK.
1140# Remember doing this will mostly like cause things to break.
1141# Doesn't allow it to be lower then the one in depend.
1142# Doesn't allow it to be higher then the active vm.
1143# 1471#
1144# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1472# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1145# ------------------------------------------------------------------------------ 1473# ------------------------------------------------------------------------------
1146java-pkg_get-target() { 1474java-pkg_get-target() {
1147 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")
1148 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then
1149 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)"
1150 if version_is_at_least "${min}" "${JAVA_PKG_WANT_TARGET}" && version_is_at_least "${JAVA_PKG_WANT_TARGET}" "${max}"; then
1151 echo ${JAVA_PKG_WANT_TARGET}
1152 else
1153 echo ${min}
1154 fi
1155 else
1156 echo ${min}
1157 fi
1158
1159 #echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND}")} 1475 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1160} 1476}
1161 1477
1162java-pkg_get-javac() { 1478java-pkg_get-javac() {
1163 debug-print-function ${FUNCNAME} $* 1479 debug-print-function ${FUNCNAME} $*
1164 1480
1165 java-pkg_init-compiler_ 1481
1166 local compiler="${GENTOO_COMPILER}" 1482 local compiler="${GENTOO_COMPILER}"
1167 1483
1168 local compiler_executable 1484 local compiler_executable
1169 if [[ "${compiler}" = "javac" ]]; then 1485 if [[ "${compiler}" = "javac" ]]; then
1170 # nothing fancy needs to be done for javac 1486 # nothing fancy needs to be done for javac
1178 unset JAVAC 1494 unset JAVAC
1179 # try to get value of JAVAC 1495 # try to get value of JAVAC
1180 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1496 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1181 export JAVAC=${old_javac} 1497 export JAVAC=${old_javac}
1182 1498
1183 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1499 if [[ -z ${compiler_executable} ]]; then
1500 echo "JAVAC is empty or undefined in ${compiler_env}"
1501 return 1
1502 fi
1184 1503
1185 # check that it's executable 1504 # check that it's executable
1186 if [[ ! -x ${compiler_executable} ]]; then 1505 if [[ ! -x ${compiler_executable} ]]; then
1187 eerror "Could not find ${compiler_executable}!"
1188 die "${compiler_executable} doesn't exist, or isn't executable" 1506 echo "${compiler_executable} doesn't exist, or isn't executable"
1507 return 1
1189 fi 1508 fi
1190 else 1509 else
1191 eerror "Could not find environment file for ${compiler}" 1510 echo "Could not find environment file for ${compiler}"
1192 die "Could not find ${compiler_env}" 1511 return 1
1193 fi 1512 fi
1194 fi 1513 fi
1195 echo ${compiler_executable} 1514 echo ${compiler_executable}
1196} 1515}
1197 1516
1214 1533
1215 debug-print "want source: ${want_source}" 1534 debug-print "want source: ${want_source}"
1216 debug-print "want target: ${want_target}" 1535 debug-print "want target: ${want_target}"
1217 1536
1218 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1537 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1219 debug-print "could not find valid -source/-target values" 1538 debug-print "could not find valid -source/-target values for javac"
1220 die "Could not find valid -source/-target values" 1539 echo "Could not find valid -source/-target values for javac"
1540 return 1
1221 else 1541 else
1222 if java-pkg_is-vm-version-ge "1.4"; then 1542 if java-pkg_is-vm-version-ge "1.4"; then
1223 echo "${source_str} ${target_str}" 1543 echo "${source_str} ${target_str}"
1224 else 1544 else
1225 echo "${target_str}" 1545 echo "${target_str}"
1229 1549
1230# TODO document 1550# TODO document
1231java-pkg_get-jni-cflags() { 1551java-pkg_get-jni-cflags() {
1232 local flags="-I${JAVA_HOME}/include" 1552 local flags="-I${JAVA_HOME}/include"
1233 1553
1554 local platform="linux"
1555 use elibc_FreeBSD && platform="freebsd"
1556
1234 # TODO do a check that the directories are valid 1557 # TODO do a check that the directories are valid
1235 # TODO figure out how to cope with other things than linux...
1236 flags="${flags} -I${JAVA_HOME}/include/linux" 1558 flags="${flags} -I${JAVA_HOME}/include/${platform}"
1237 1559
1238 echo ${flags} 1560 echo ${flags}
1239} 1561}
1240 1562
1241java-pkg_ensure-gcj() { 1563java-pkg_ensure-gcj() {
1247 die "No GCJ support found!" 1569 die "No GCJ support found!"
1248 fi 1570 fi
1249} 1571}
1250 1572
1251java-pkg_ensure-test() { 1573java-pkg_ensure-test() {
1252 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} && ! use test; then 1574 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \
1575 && hasq test ${IUSE} && ! use test;
1576 then
1253 eerror "You specified FEATURES=test, but USE=test is needed" 1577 eerror "You specified FEATURES=test, but USE=test is needed"
1254 eerror "to pull in the additional dependencies for testing" 1578 eerror "to pull in the additional dependencies for testing"
1255 die "Need USE=test enabled" 1579 die "Need USE=test enabled"
1256 fi 1580 fi
1257} 1581}
1258 1582
1259# ------------------------------------------------------------------------------ 1583# ------------------------------------------------------------------------------
1584# @ebuild-function java-pkg_register-ant-task
1585#
1586# Register this package as ant task, so that ant will load it when no specific
1587# ANT_TASKS are specified. Note that even without this registering, all packages
1588# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1589# packages, but can be also used by other ebuilds that used to symlink their
1590# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1591# compatibility.
1592#
1593# @param --version x.y Register only for ant version x.y (otherwise for any ant
1594# version). Used by the ant-* packages to prevent loading of mismatched
1595# ant-core ant tasks after core was updated, before the tasks are updated,
1596# without a need for blockers.
1597# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1598# ------------------------------------------------------------------------------
1599java-pkg_register-ant-task() {
1600 local TASKS_DIR="tasks"
1601
1602 # check for --version x.y parameters
1603 while [[ -n "${1}" && -n "${2}" ]]; do
1604 local var="${1#--}"
1605 local val="${2}"
1606 if [[ "${var}" == "version" ]]; then
1607 TASKS_DIR="tasks-${val}"
1608 else
1609 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1610 fi
1611 shift 2
1612 done
1613
1614 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1615
1616 dodir /usr/share/ant/${TASKS_DIR}
1617 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1618}
1619
1620# ------------------------------------------------------------------------------
1621# @internal-function java-pkg_ant-tasks-from-deps
1622#
1623# Function to determine ANT_TASKS from DEPEND variable for backwards
1624# compatibility with ebuilds that don't set ANT_TASKS before calling eant() or
1625# WANT_ANT_TASKS before inheriting java-pkg-2. If the DEPEND string contains
1626# "dev-java/ant" or "dev-java/ant-tasks", then it returns "all", otherwise
1627# "none". It's not smart enough to cope with USE flag depends but that shouldn't
1628# be a problem, the worst it can do is activace all tasks when not needed.
1629# Note that this is called only with JAVA_PKG_STRICT=1, to find ebuilds with
1630# insufficient dependencies, otherwise all available tasks are used for
1631# backwards compatilbility.
1632#
1633# @return "all" or "none"
1634# ------------------------------------------------------------------------------
1635java-pkg_ant-tasks-from-deps() {
1636 local found_ant found_ant_tasks
1637
1638 for dep in ${DEPEND}
1639 do
1640 local ant="$(awk '/(dev-java\/ant)/ { if (match($1, "(dev-java/ant)((-[0-9])+|$)", m)) print m[1] }' <<< ${dep})"
1641 [[ "${ant}" == "dev-java/ant" ]] && found_ant=true
1642 [[ "${dep}" == *"ant-tasks"* ]] && found_ant_tasks=true
1643 done
1644
1645 if [[ -n "${found_ant}" || -n "${found_ant_tasks}" ]]; then
1646 java-pkg_announce-qa-violation --nodie "The ebuild DEPENDS on deprecated ant or ant-tasks"
1647 echo "all"
1648 else
1649 # ebuild doesn't set ANT_TASKS and doesn't depend on ant-tasks or ant
1650 # so we deactivate all tasks that may be installed
1651 echo "none"
1652 fi
1653}
1654
1655# ------------------------------------------------------------------------------
1656# @internal-function java-pkg_ant-tasks-depend
1657#
1658# Translates the WANT_ANT_TASKS variable into valid dependencies.
1659# ------------------------------------------------------------------------------
1660java-pkg_ant-tasks-depend() {
1661 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1662
1663 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1664 local DEP=""
1665 for i in ${WANT_ANT_TASKS}
1666 do
1667 if [[ ${i} != ant-* ]]; then
1668 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1669 return 1
1670 fi
1671 DEP="${DEP}dev-java/${i} "
1672 done
1673 echo ${DEP}
1674 return 0
1675 else
1676 return 0
1677 fi
1678}
1679
1680# ------------------------------------------------------------------------------
1681# @ebuild-function ejunit
1682#
1683# Junit wrapper function. Makes it easier to run the tests and checks for
1684# dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner.
1685#
1686# Examples:
1687# ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1688# ejunit org.blinkenlights.jid3.test.AllTests
1689#
1690# @param $1 - -cp or -classpath
1691# @param $2 - classpath; junit and recorded dependencies get appended
1692# @param $@ - the rest of the parameters are passed to java
1693# ------------------------------------------------------------------------------
1694ejunit() {
1695 debug-print-function ${FUNCNAME} $*
1696
1697 local pkgs
1698 for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
1699 pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
1700 done
1701
1702 local cp=$(java-pkg_getjars --with-dependencies junit${pkgs})
1703 if [[ ${1} = -cp || ${1} = -classpath ]]; then
1704 cp="${2}:${cp}"
1705 shift 2
1706 else
1707 cp=".:${cp}"
1708 fi
1709
1710 local runner=junit.textui.TestRunner
1711 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}"
1712 java -cp "${cp}" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
1713}
1714
1715# ------------------------------------------------------------------------------
1260# @section-end helper 1716# @section-end helper
1261# ------------------------------------------------------------------------------ 1717# ------------------------------------------------------------------------------
1262 1718
1263# ------------------------------------------------------------------------------ 1719# ------------------------------------------------------------------------------
1264# @section-begin build 1720# @section-begin build
1270 1726
1271# ------------------------------------------------------------------------------ 1727# ------------------------------------------------------------------------------
1272# @ebuild-function eant 1728# @ebuild-function eant
1273# 1729#
1274# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1730# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1275# compiler. 1731# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1276# 1732# variables:
1733# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1734# gentoo.classpath property. Be sure to call
1735# java-ant_rewrite-classpath in src_unpack.
1736# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1277# ------------------------------------------------------------------------------ 1737# ------------------------------------------------------------------------------
1278eant() { 1738eant() {
1279 debug-print-function ${FUNCNAME} $* 1739 debug-print-function ${FUNCNAME} $*
1280 1740
1281 # FIXME get this working 1741 if ! hasq java-ant-2 ${INHERITED}; then
1282# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then 1742 local msg="You should inherit java-ant-2 when using eant"
1283# java-pkg_announce-qa-violation \ 1743 java-pkg_announce-qa-violation "${msg}"
1284# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1285# fi 1744 fi
1286 1745
1287 local antflags 1746 local antflags="-Dnoget=true -Dmaven.mode.offline=true"
1747
1288 java-pkg_init-compiler_ 1748 java-pkg_init-compiler_
1289 local compiler="${GENTOO_COMPILER}" 1749 local compiler="${GENTOO_COMPILER}"
1290 1750
1291 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1751 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1292 1752
1294 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1754 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1295 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1755 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1296 fi 1756 fi
1297 1757
1298 if [[ ${compiler} != "javac" ]]; then 1758 if [[ ${compiler} != "javac" ]]; then
1299 antflags="-Dbuild.compiler=${build_compiler}" 1759 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1300 # Figure out any extra stuff to put on the classpath for compilers aside 1760 # Figure out any extra stuff to put on the classpath for compilers aside
1301 # from javac 1761 # from javac
1302 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to 1762 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1303 # java-config -p 1763 # java-config -p
1304 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1764 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})"
1310 if is-java-strict; then 1770 if is-java-strict; then
1311 einfo "Disabling system classpath for ant" 1771 einfo "Disabling system classpath for ant"
1312 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1772 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1313 fi 1773 fi
1314 1774
1315 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1775 for arg in "${@}"; do
1316 antflags="${antflags} -debug" 1776 if [[ ${arg} = -lib ]]; then
1777 if is-java-strict; then
1778 eerror "You should not use the -lib argument to eant because it will fail"
1779 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1780 eerror "or ant properties to make dependencies available."
1781 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1782 eerror "split ant (>=dev-java/ant-core-1.7)."
1783 die "eant -lib is deprecated/forbidden"
1784 else
1785 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1786 echo "more info."
1787 fi
1788 fi
1789 done
1790
1791 if has_version ">=dev-java/ant-core-1.7.0"; then
1792 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1793 ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}"
1794
1795 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1796 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1797
1798 if is-java-strict; then
1799 # if ant-tasks were not set by ebuild or forced, try to determine them from depends
1800 if [[ -z "${ANT_TASKS}" ]]; then
1801 ANT_TASKS="$(java-pkg_ant-tasks-from-deps)"
1802 fi
1803 else
1804 # if ant-tasks is not set by ebuild or forced, activate all of them
1805 ANT_TASKS="${ANT_TASKS:-all}"
1806 fi
1807
1808 # at this point, ANT_TASKS should be "all", "none" or explicit list
1809 if [[ "${ANT_TASKS}" == "all" ]]; then
1810 einfo "Using all available ANT_TASKS"
1811 elif [[ "${ANT_TASKS}" == "none" ]]; then
1812 einfo "Disabling all optional ANT_TASKS"
1813 else
1814 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1815 fi
1816
1817 export ANT_TASKS
1818 fi
1819
1820 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1821 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1822
1823 local gcp="${EANT_GENTOO_CLASSPATH}"
1824 local getjarsarg=""
1825
1826 if [[ ${EBUILD_PHASE} = "test" ]]; then
1827 antflags="${antflags} -DJunit.present=true"
1828 [[ ${gcp} && ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1829 getjarsarg="--with-dependencies"
1830 fi
1831
1832 local cp
1833
1834 for atom in ${gcp}; do
1835 cp="${cp}:$(java-pkg_getjars ${getjarsarg} ${atom})"
1836 done
1837
1838 if [[ ${cp} ]]; then
1839 # It seems ant does not like single quotes around ${cp}
1840 antflags="${antflags} -Dgentoo.classpath=\"${cp#:}\""
1317 fi 1841 fi
1318 1842
1319 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1843 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1844 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
1320 ant ${antflags} "${@}" || die "eant failed" 1845 ant ${antflags} "${@}" || die "eant failed"
1321
1322} 1846}
1323 1847
1324# ------------------------------------------------------------------------------ 1848# ------------------------------------------------------------------------------
1325# @ebuild-function ejavac 1849# @ebuild-function ejavac
1326# 1850#
1330# @param $@ - Arguments to be passed to the compiler 1854# @param $@ - Arguments to be passed to the compiler
1331# ------------------------------------------------------------------------------ 1855# ------------------------------------------------------------------------------
1332ejavac() { 1856ejavac() {
1333 debug-print-function ${FUNCNAME} $* 1857 debug-print-function ${FUNCNAME} $*
1334 1858
1335 # FIXME using get-javac ends up printing stuff with einfo 1859 java-pkg_init-compiler_
1860
1861 local compiler_executable
1336# local compiler_executable=$(java-pkg_get-javac) 1862 compiler_executable=$(java-pkg_get-javac)
1337 local compiler_executable="javac" 1863 if [[ ${?} != 0 ]]; then
1864 eerror "There was a problem determining compiler: ${compiler_executable}"
1865 die "get-javac failed"
1866 fi
1338 1867
1868 local javac_args
1869 javac_args="$(java-pkg_javac-args)"
1870 if [[ ${?} != 0 ]]; then
1871 eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
1872 die "java-pkg_javac-args failed"
1873 fi
1874
1339 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 1875 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1340 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 1876 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1341} 1877}
1342 1878
1343# ------------------------------------------------------------------------------ 1879# ------------------------------------------------------------------------------
1344# @ebuild-function java-pkg_filter-compiler 1880# @ebuild-function java-pkg_filter-compiler
1345# 1881#
1383# ------------------------------------------------------------------------------ 1919# ------------------------------------------------------------------------------
1384use_doc() { 1920use_doc() {
1385 use doc && echo ${@:-javadoc} 1921 use doc && echo ${@:-javadoc}
1386} 1922}
1387 1923
1924
1388# ------------------------------------------------------------------------------ 1925# ------------------------------------------------------------------------------
1389# @section-end build 1926# @section-end build
1390# ------------------------------------------------------------------------------ 1927# ------------------------------------------------------------------------------
1391 1928
1392# ------------------------------------------------------------------------------ 1929# ------------------------------------------------------------------------------
1410# 1947#
1411# ----------------------------------------------------------------------------- 1948# -----------------------------------------------------------------------------
1412java-pkg_init() { 1949java-pkg_init() {
1413 unset JAVAC 1950 unset JAVAC
1414 unset JAVA_HOME 1951 unset JAVA_HOME
1952
1953 # People do all kinds of weird things.
1954 # http://forums.gentoo.org/viewtopic-p-3943166.html
1955 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
1956 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
1957 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
1958 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
1959 ewarn "sun-jdk vms and and as such break configure scripts that"
1960 ewarn "use it (for example app-office/openoffice) so we filter it out."
1961 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
1962 ewarn "make.conf for example) to silence this warning or"
1963 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
1964 fi
1965
1966 if [[ -z ${accept} ]]; then
1967 unset _JAVA_OPTIONS
1968 # phase hooks make this run many times without this
1969 I_WANT_GLOBAL_JAVA_OPTIONS="true"
1970 fi
1971
1415 java-pkg_init_paths_ 1972 java-pkg_init_paths_
1416 java-pkg_switch-vm 1973 java-pkg_switch-vm
1417 PATH=${JAVA_HOME}/bin:${PATH} 1974 PATH=${JAVA_HOME}/bin:${PATH}
1418 1975
1419 # TODO we will probably want to set JAVAC and JAVACFLAGS 1976 # TODO we will probably want to set JAVAC and JAVACFLAGS
1424 # When users have crazy classpaths some packages can fail to compile. 1981 # When users have crazy classpaths some packages can fail to compile.
1425 # and everything should work with empty CLASSPATH. 1982 # and everything should work with empty CLASSPATH.
1426 # This also helps prevent unexpected dependencies on random things 1983 # This also helps prevent unexpected dependencies on random things
1427 # from the CLASSPATH. 1984 # from the CLASSPATH.
1428 unset CLASSPATH 1985 unset CLASSPATH
1986
1987 # Unset external ANT_ stuff
1988 unset ANT_TASKS
1989 unset ANT_OPTS
1429} 1990}
1430 1991
1431# ------------------------------------------------------------------------------ 1992# ------------------------------------------------------------------------------
1432# @function-internal java-pkg-init-compiler_ 1993# @function-internal java-pkg-init-compiler_
1433# 1994#
1577# Writes the package.env out to disk. 2138# Writes the package.env out to disk.
1578# 2139#
1579# ------------------------------------------------------------------------------ 2140# ------------------------------------------------------------------------------
1580# TODO change to do-write, to match everything else 2141# TODO change to do-write, to match everything else
1581java-pkg_do_write_() { 2142java-pkg_do_write_() {
2143 debug-print-function ${FUNCNAME} $*
2144 java-pkg_init_paths_
1582 # Create directory for package.env 2145 # Create directory for package.env
1583 dodir "${JAVA_PKG_SHAREPATH}" 2146 dodir "${JAVA_PKG_SHAREPATH}"
1584 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 2147 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f \
2148 "${JAVA_PKG_DEPEND_FILE}" ]]; then
1585 # Create package.env 2149 # Create package.env
1586 ( 2150 (
1587 echo "DESCRIPTION=\"${DESCRIPTION}\"" 2151 echo "DESCRIPTION=\"${DESCRIPTION}\""
1588 echo "GENERATION=\"2\"" 2152 echo "GENERATION=\"2\""
1589 2153
1590 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\"" 2154 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
1591 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 2155 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1592 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 2156 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1593 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 2157 [[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
2158 && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND_FILE} | uniq | tr '\n' ':')\""
1594 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 2159 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1595 ) > "${JAVA_PKG_ENV}" 2160 ) > "${JAVA_PKG_ENV}"
1596 2161
1597 # register target/source 2162 # register target/source
1598 local target="$(java-pkg_get-target)" 2163 local target="$(java-pkg_get-target)"
1609 2174
1610 2175
1611 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}" 2176 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
1612 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}" 2177 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
1613 2178
2179 # extra env variables
2180 if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
2181 cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}" || die
2182 # nested echo to remove leading/trailing spaces
2183 echo "ENV_VARS=\"$(echo ${JAVA_PKG_EXTRA_ENV_VARS})\"" \
2184 >> "${JAVA_PKG_ENV}" || die
2185 fi
2186
1614 # Strip unnecessary leading and trailing colons 2187 # Strip unnecessary leading and trailing colons
1615 # TODO try to cleanup if possible 2188 # TODO try to cleanup if possible
1616 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 2189 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
2190 else
2191 debug-print "JAVA_PKG_CLASSPATH, JAVA_PKG_LIBRARY or"
2192 debug-print "JAVA_PKG_DEPEND_FILE not defined so can't"
2193 debug-print "write package.env."
1617 fi 2194 fi
1618} 2195}
1619
1620 2196
1621# ------------------------------------------------------------------------------ 2197# ------------------------------------------------------------------------------
1622# @internal-function java-pkg_record-jar_ 2198# @internal-function java-pkg_record-jar_
1623# 2199#
1624# Record a dependency to the package.env 2200# Record a dependency to the package.env
1625# 2201#
1626# ------------------------------------------------------------------------------ 2202# ------------------------------------------------------------------------------
1627JAVA_PKG_DEPEND="${T}/java-pkg-depend" 2203JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
1628 2204
1629java-pkg_record-jar_() { 2205java-pkg_record-jar_() {
1630 debug-print-function ${FUNCNAME} $* 2206 debug-print-function ${FUNCNAME} $*
1631 2207
1632 local pkg=${1} jar=${2} append 2208 local pkg=${1} jar=${2} append
1634 append="${pkg}" 2210 append="${pkg}"
1635 else 2211 else
1636 append="$(basename ${jar})@${pkg}" 2212 append="$(basename ${jar})@${pkg}"
1637 fi 2213 fi
1638 2214
1639 echo ${append} >> ${JAVA_PKG_DEPEND} 2215 echo ${append} >> ${JAVA_PKG_DEPEND_FILE}
1640} 2216}
1641 2217
1642# ------------------------------------------------------------------------------ 2218# ------------------------------------------------------------------------------
1643# @internal-function java-pkg_append_ 2219# @internal-function java-pkg_append_
1644# 2220#
1704# 2280#
1705# ------------------------------------------------------------------------------ 2281# ------------------------------------------------------------------------------
1706java-pkg_setup-vm() { 2282java-pkg_setup-vm() {
1707 debug-print-function ${FUNCNAME} $* 2283 debug-print-function ${FUNCNAME} $*
1708 2284
2285 export LANG="C" LC_ALL="C"
2286
1709 local vendor="$(java-pkg_get-vm-vendor)" 2287 local vendor="$(java-pkg_get-vm-vendor)"
1710 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge 1 5; then 2288 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1711 addpredict "/dev/random" 2289 addpredict "/dev/random"
1712 elif [[ "${vendor}" == "ibm" ]]; then 2290 elif [[ "${vendor}" == "ibm" ]]; then
1713 addpredict "/proc/self/maps" 2291 addpredict "/proc/self/maps"
1714 addpredict "/proc/cpuinfo" 2292 addpredict "/proc/cpuinfo"
1715 export LANG="C" LC_ALL="C"
1716 elif [[ "${vendor}" == "jrockit" ]]; then 2293 elif [[ "${vendor}" == "jrockit" ]]; then
1717 addpredict "/proc/cpuinfo" 2294 addpredict "/proc/cpuinfo"
1718 fi 2295 fi
1719} 2296}
1720 2297
1775# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 2352# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1776# verify that the current VM is sufficient. 2353# verify that the current VM is sufficient.
1777# Setup the environment for the VM being used. 2354# Setup the environment for the VM being used.
1778# ------------------------------------------------------------------------------ 2355# ------------------------------------------------------------------------------
1779java-pkg_switch-vm() { 2356java-pkg_switch-vm() {
2357 debug-print-function ${FUNCNAME} $*
2358
1780 if java-pkg_needs-vm; then 2359 if java-pkg_needs-vm; then
1781 # Use the VM specified by JAVA_PKG_FORCE_VM 2360 # Use the VM specified by JAVA_PKG_FORCE_VM
1782 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then 2361 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1783 # If you're forcing the VM, I hope you know what your doing... 2362 # If you're forcing the VM, I hope you know what your doing...
2363 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1784 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 2364 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1785 # if we're allowed to switch the vm... 2365 # if we're allowed to switch the vm...
1786 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 2366 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1787 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}" 2367 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1788 if [[ -n ${JAVA_PKG_VNEED} ]]; then 2368 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1789 export GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2369 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1790 else 2370 else
1791 export GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2371 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
2372 fi
2373 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
2374 eerror "Unable to determine VM for building from dependencies:"
2375 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
2376 echo "VNEED: ${JAVA_PKG_VNEED}"
2377 die "Failed to determine VM for building."
2378 else
2379 export GENTOO_VM
1792 fi 2380 fi
1793 # otherwise just make sure the current VM is sufficient 2381 # otherwise just make sure the current VM is sufficient
1794 else 2382 else
1795 java-pkg_ensure-vm-version-sufficient 2383 java-pkg_ensure-vm-version-sufficient
1796 fi 2384 fi
1798 2386
1799 java-pkg_setup-vm 2387 java-pkg_setup-vm
1800 2388
1801 export JAVA=$(java-config --java) 2389 export JAVA=$(java-config --java)
1802 export JAVAC=$(java-config --javac) 2390 export JAVAC=$(java-config --javac)
1803 export JAVACFLAGS="$(java-pkg_javac-args)" 2391 JAVACFLAGS="$(java-pkg_javac-args)"
2392 if [[ ${?} != 0 ]]; then
2393 eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
2394 die "java-pkg_javac-args failed"
2395 fi
1804 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 2396 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
2397 export JAVACFLAGS
1805 2398
1806 export JAVA_HOME="$(java-config -g JAVA_HOME)" 2399 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1807 export JDK_HOME=${JAVA_HOME} 2400 export JDK_HOME=${JAVA_HOME}
1808 2401
1809 #TODO If you know a better solution let us know. 2402 #TODO If you know a better solution let us know.
1855 einfo "Classes" 2448 einfo "Classes"
1856 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR}," 2449 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1857 fi 2450 fi
1858} 2451}
1859 2452
1860# TODO document 2453# ------------------------------------------------------------------------------
2454# @internal-function java-pkg_verify-classes
2455#
1861# Verify that the classes were compiled for the right source / target 2456# Verify that the classes were compiled for the right source / target. Dies if
2457# not.
2458# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2459# ------------------------------------------------------------------------------
1862java-pkg_verify-classes() { 2460java-pkg_verify-classes() {
1863 ebegin "Verifying java class versions"
1864 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 2461 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1865 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 2462 local target=$(java-pkg_get-target)
2463 local result
2464 local log="${T}/class-version-verify.log"
2465 if [[ -n "${1}" ]]; then
2466 class-version-verify.py -v -t ${target} "${1}" > "${log}"
1866 result=$? 2467 result=$?
1867 eend ${result}
1868 if [[ ${result} == 0 ]]; then
1869 einfo "All good"
1870 else 2468 else
1871 ewarn "Possible problem" 2469 ebegin "Verifying java class versions (target: ${target})"
1872 die "Bad class files found" 2470 class-version-verify.py -v -t ${target} -r "${D}" > "${log}"
2471 result=$?
2472 eend ${result}
2473 fi
2474 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2475 if [[ ${result} != 0 ]]; then
2476 eerror "Incorrect bytecode version found"
2477 [[ -n "${1}" ]] && eerror "in file: ${1}"
2478 eerror "See ${log} for more details."
2479 die "Incorrect bytecode found"
2480 fi
2481}
2482
2483# ----------------------------------------------------------------------------
2484# @internal-function java-pkg_ensure-dep
2485# Check that a package being used in jarfrom, getjars and getjar is contained
2486# within DEPEND or RDEPEND.
2487# @param $1 - empty - check both vars; "runtime" or "build" - check only
2488# RDEPEND, resp. DEPEND
2489# @param $2 - Package name and slot.
2490
2491java-pkg_ensure-dep() {
2492 debug-print-function ${FUNCNAME} $*
2493
2494 local limit_to="${1}"
2495 local target_pkg="${2}"
2496 local dev_error=""
2497
2498 local stripped_pkg=$(echo "${target_pkg}" | sed \
2499 's/-[0-9]*\(\.[0-9]\)*$//')
2500
2501 debug-print "Matching against: ${stripped_pkg}"
2502
2503 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2504 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2505 dev_error="${dev_error} declared in DEPEND."
2506 if is-java-strict; then
2507 eerror "${dev_error}"
2508 die "${dev_error}"
2509 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2510 eerror "${dev_error}"
2511 elog "Because you have this package installed the package will"
2512 elog "build without problems, but please report this to"
2513 elog "http://bugs.gentoo.org"
1873 fi 2514 fi
1874} 2515 fi
1875 2516
2517 if [[ ${limit_to} != build ]]; then
2518 if [[ ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2519 if [[ ! ( ${PDEPEND} =~ "${stripped_pkg}" ) ]]; then
2520 dev_error="The ebuild is attempting to use ${target_pkg},"
2521 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND"
2522 dev_error="${dev_error} or PDEPEND."
2523 if is-java-strict; then
2524 eerror "${dev_error}"
2525 die "${dev_error}"
2526 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2527 eerror "${dev_error}"
2528 elog "The package will build without problems, but may fail to run"
2529 elog "if you don't have ${target_pkg} installed, so please report"
2530 elog "this to http://bugs.gentoo.org"
2531 fi
2532 fi
2533 fi
2534 fi
2535}
1876 2536
1877# ------------------------------------------------------------------------------ 2537# ------------------------------------------------------------------------------
1878# @section-end internal 2538# @section-end internal
1879# ------------------------------------------------------------------------------ 2539# ------------------------------------------------------------------------------
1880 2540
1881java-pkg_check-phase() { 2541java-pkg_check-phase() {
1882 local phase=${1} 2542 local phase=${1}
1883 local funcname=${2} 2543 local funcname=${FUNCNAME[1]}
1884 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then 2544 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
1885 java-pkg_announce-qa-violation \
1886 "${funcname} used outside of src_${phase}" 2545 local msg="${funcname} used outside of src_${phase}"
2546 java-pkg_announce-qa-violation "${msg}"
1887 fi 2547 fi
1888} 2548}
1889 2549
1890java-pkg_check-versioned-jar() { 2550java-pkg_check-versioned-jar() {
1891 local jar=${1} 2551 local jar=${1}
1900 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2560 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1901 fi 2561 fi
1902} 2562}
1903 2563
1904java-pkg_announce-qa-violation() { 2564java-pkg_announce-qa-violation() {
1905 if is-java-strict; then 2565 local nodie
2566 if [[ ${1} == "--nodie" ]]; then
2567 nodie="true"
2568 shift
2569 fi
1906 echo "Java QA Notice: $@" >&2 2570 echo "Java QA Notice: $@" >&2
1907 increment-qa-violations 2571 increment-qa-violations
1908 fi 2572 [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
1909} 2573}
1910 2574
1911increment-qa-violations() { 2575increment-qa-violations() {
1912 let "JAVA_PKG_QA_VIOLATIONS+=1" 2576 let "JAVA_PKG_QA_VIOLATIONS+=1"
1913 export JAVA_PKG_QA_VIOLATIONS 2577 export JAVA_PKG_QA_VIOLATIONS

Legend:
Removed from v.1.22  
changed lines
  Added in v.1.87

  ViewVC Help
Powered by ViewVC 1.1.20