/[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.12 Revision 1.88
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.88 2007/05/28 19:28:22 caster 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
15# 15#
16# This eclass provides functionality which is used by 16# This eclass provides functionality which is used by
17# java-pkg.eclass and java-pkg-opt.eclass as well as from ebuilds. 17# java-pkg.eclass and java-pkg-opt.eclass as well as from ebuilds.
18# 18#
19# @warning 19# @warning
20# You probably don't want to inherit this directly from an ebuild. Instead, 20# 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 21# 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. 22# Java packages, or java-pkg-opt for packages that have optional Java support.
23# 23#
24# ----------------------------------------------------------------------------- 24# -----------------------------------------------------------------------------
25 25
26inherit eutils versionator multilib 26inherit eutils versionator multilib
27
28IUSE="elibc_FreeBSD"
27 29
28# ----------------------------------------------------------------------------- 30# -----------------------------------------------------------------------------
29# @section-begin variables 31# @section-begin variables
30# @section-title Variables 32# @section-title Variables
31# 33#
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#
100# ----------------------------------------------------------------------------- 126# -----------------------------------------------------------------------------
101 127
102# ----------------------------------------------------------------------------- 128# -----------------------------------------------------------------------------
103# @variable-internal JAVA_PKG_COMPILER_DIR 129# @variable-internal JAVA_PKG_COMPILER_DIR
104# @default /usr/share/java-config-2/compiler 130# @default /usr/share/java-config-2/compiler
105# 131#
106# Directory where compiler settings are saved, without trailing slash. 132# Directory where compiler settings are saved, without trailing slash.
107# Probably shouldn't touch this variable. 133# Probably shouldn't touch this variable.
108# ----------------------------------------------------------------------------- 134# -----------------------------------------------------------------------------
109JAVA_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"}
110 136
120 146
121# ----------------------------------------------------------------------------- 147# -----------------------------------------------------------------------------
122# @variable-external JAVA_PKG_FORCE_COMPILER 148# @variable-external JAVA_PKG_FORCE_COMPILER
123# 149#
124# 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
125# JAVA_PKG_COMPILERS_CONF. 151# JAVA_PKG_COMPILERS_CONF.
126# 152#
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.
153# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default. 226# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default.
154# You can use java-pkg_jarinto to change this path. 227# You can use java-pkg_jarinto to change this path.
155# You should never install a jar with a package version in the filename. 228# You should never install a jar with a package version in the filename.
156# Instead, use java-pkg_newjar defined below. 229# Instead, use java-pkg_newjar defined below.
157# 230#
158# @example 231# @example
159# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar 232# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar
160# 233#
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
222# will not work, because: 318# will not work, because:
223# * the `for jar in "$@"` can't expand the path to jar file names, as they 319# * the `for jar in "$@"` can't expand the path to jar file names, as they
224# don't exist yet 320# don't exist yet
225# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar' 321# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar'
226# doesn't exist 322# doesn't exist
227# 323#
228# you have to use it as: 324# you have to use it as:
229# 325#
230# java-pkg_regjar ${D}/opt/my-java/lib/*.jar 326# java-pkg_regjar ${D}/opt/my-java/lib/*.jar
231# 327#
232# @param $@ - jars to record 328# @param $@ - jars to record
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.
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 410
307
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
312# They will be installed into /usr/lib by default, but java-pkg_sointo 415# They will be installed into /usr/lib by default, but java-pkg_sointo
313# can be used change this path 416# can be used change this path
314# 417#
315# Example: 418# Example:
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"
370 java-pkg_check-phase install 474 java-pkg_check-phase install
371 475
372 [[ ${#} -lt 1 ]] && "at least one argument needed" 476 [[ ${#} -lt 1 ]] && "at least one argument needed"
373 477
374 java-pkg_init_paths_ 478 java-pkg_init_paths_
375 479
376 local lib target_dir 480 local lib target_dir
377 for lib in "$@" ; do 481 for lib in "$@" ; do
378 # Check the absolute path of the lib 482 # Check the absolute path of the lib
379 if [[ -e "${lib}" ]] ; then 483 if [[ -e "${lib}" ]] ; then
380 target_dir="$(java-pkg_expand_dir_ ${lib})" 484 target_dir="$(java-pkg_expand_dir_ ${lib})"
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
456 583
584 # Actual installation
585
457 java-pkg_dohtml -r ${dir_to_install} 586 java-pkg_dohtml -r ${dir_to_install}
458} 587}
459 588
460# ------------------------------------------------------------------------------ 589# ------------------------------------------------------------------------------
461# @ebuild-function java-pkg_dosrc 590# @ebuild-function java-pkg_dosrc
462# 591#
463# Installs a zip containing the source for a package, so it can used in 592# Installs a zip containing the source for a package, so it can used in
464# from IDEs like eclipse and netbeans. 593# from IDEs like eclipse and netbeans.
465# 594#
466# Ebuild needs to DEPEND on app-arch/zip to use this. 595# Ebuild needs to DEPEND on app-arch/zip to use this.
467# 596#
468# It also should be controlled by USE=source. 597# It also should be controlled by USE=source.
469# 598#
470# @example: 599# @example:
471# java-pkg_dosrc src/* 600# java-pkg_dosrc src/*
472# 601#
473# ------------------------------------------------------------------------------ 602# ------------------------------------------------------------------------------
474# TODO change so it the arguments it takes are the base directories containing 603# TODO change so it the arguments it takes are the base directories containing
475# source -nichoj 604# source -nichoj
476# TODO should we be able to handle multiple calls to dosrc? -nichoj 605# TODO should we be able to handle multiple calls to dosrc? -nichoj
477# TODO maybe we can take an existing zip/jar? -nichoj 606# TODO maybe we can take an existing zip/jar? -nichoj
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 too jave' 667# --java_args 'Extra arguments to pass to java'
528# --pkg_args 'extra arguments too pass too 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}"
688 local var_tmp="${T}/launcher_variables_tmp"
545 local target_dir pre 689 local target_dir pre
546 shift
547 690
548 echo "#!/bin/bash" > "${target}" 691 # Process the other the rest of the arguments
549 while [[ -n "${1}" && -n "${2}" ]]; do 692 while [[ -n "${1}" && -n "${2}" ]]; do
550 local var=${1} value=${2} 693 local var="${1}" value="${2}"
551 if [[ "${var:0:2}" == "--" ]]; then 694 if [[ "${var:0:2}" == "--" ]]; then
695 local var=${var:2}
552 echo "gjl_${var:2}=\"${value}\"" >> "${target}" 696 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
697 local gjl_${var}="${value}"
553 elif [[ "${var}" == "-into" ]]; then 698 elif [[ "${var}" == "-into" ]]; then
554 target_dir="${value}" 699 target_dir="${value}"
555 elif [[ "${var}" == "-pre" ]]; then 700 elif [[ "${var}" == "-pre" ]]; then
556 pre="${value}" 701 pre="${value}"
557 fi 702 fi
558 shift 2 703 shift 2
559 done 704 done
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
720 # Write the actual script
721 echo "#!/bin/bash" > "${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
560 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 729 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
561 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 730 cat "${var_tmp}" >> "${target}"
731 rm -f "${var_tmp}"
562 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 732 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
563 733
564 if [[ -n "${into}" ]]; then 734 if [[ -n "${target_dir}" ]]; then
565 DESTTREE="${target_dir}" dobin "${target}" 735 DESTTREE="${target_dir}" dobin "${target}"
566 local ret=$? 736 local ret=$?
567 return ${ret} 737 return ${ret}
568 else 738 else
569 dobin "${target}" 739 dobin "${target}"
597 echo "dowar: warning, skipping directory ${war}" 767 echo "dowar: warning, skipping directory ${war}"
598 continue 768 continue
599 else 769 else
600 warpath="${war}" 770 warpath="${war}"
601 fi 771 fi
602 772
603 # Install those files like you mean it 773 # Install those files like you mean it
604 INSOPTIONS="-m 0644" \ 774 INSOPTIONS="-m 0644" \
605 INSDESTTREE=${JAVA_PKG_WARDEST} \ 775 INSDESTTREE=${JAVA_PKG_WARDEST} \
606 doins ${warpath} 776 doins ${warpath}
607 done 777 done
642# @ebuild-function java-pkg_jar-from 812# @ebuild-function java-pkg_jar-from
643# 813#
644# Makes a symlink to a jar from a certain package 814# Makes a symlink to a jar from a certain package
645# A lot of java packages include dependencies in a lib/ directory 815# A lot of java packages include dependencies in a lib/ directory
646# You can use this function to replace these bundled dependencies. 816# You can use this function to replace these bundled dependencies.
817# The dependency is recorded into package.env DEPEND line, unless "--build-only"
818# is passed as the very first argument, for jars that have to be present only
819# at build time and are not needed on runtime (junit testing etc).
647# 820#
648# Example: get all jars from xerces slot 2 821# Example: get all jars from xerces slot 2
649# java-pkg_jar-from xerces-2 822# java-pkg_jar-from xerces-2
650# Example: get a specific jar from xerces slot 2 823# Example: get a specific jar from xerces slot 2
651# java-pkg_jar-from xerces-2 xml-apis.jar 824# java-pkg_jar-from xerces-2 xml-apis.jar
652# 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
653# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 826# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
827# Example: get junit.jar which is needed only for building
828# java-pkg_jar-from --build-only junit junit.jar
654# 829#
655# @param $1 - Package to get jars from. 830# @param $opt
831# --build-only - makes the jar(s) not added into package.env DEPEND line.
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.
656# @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.
657# @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
658# symlink. Defaults to the name of the jar. 840# symlink. Defaults to the name of the jar.
659# ------------------------------------------------------------------------------ 841# ------------------------------------------------------------------------------
660# TODO could probably be cleaned up a little 842# TODO could probably be cleaned up a little
661java-pkg_jar-from() { 843java-pkg_jar-from() {
662 debug-print-function ${FUNCNAME} $* 844 debug-print-function ${FUNCNAME} $*
663 845
846 local build_only=""
847 local destdir="."
848 local deep=""
849
850 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
851
852 while [[ "${1}" == --* ]]; do
853 if [[ "${1}" = "--build-only" ]]; then
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
863 shift
864 done
865
664 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 866 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
665 867
666 [[ -z ${target_pkg} ]] && die "Must specify a package" 868 [[ -z ${target_pkg} ]] && die "Must specify a package"
667 869
668 # default destjar to the target jar 870 # default destjar to the target jar
669 [[ -z "${destjar}" ]] && destjar="${target_jar}" 871 [[ -z "${destjar}" ]] && destjar="${target_jar}"
670 872
873 local error_msg="There was a problem getting the classpath for ${target_pkg}."
874 local classpath
671 local classpath="$(java-config --classpath=${target_pkg})" 875 classpath="$(java-config ${deep} --classpath=${target_pkg})"
672 [[ $? != 0 ]] && die "There was a problem getting the classpath for ${target_pkg}" 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}"
673 894
674 local jar 895 local jar
675 for jar in ${classpath//:/ }; do 896 for jar in ${classpath//:/ }; do
676 local jar_name=$(basename "${jar}") 897 local jar_name=$(basename "${jar}")
677 if [[ ! -f "${jar}" ]] ; then 898 if [[ ! -f "${jar}" ]] ; then
681 # If no specific target jar was indicated, link it 902 # If no specific target jar was indicated, link it
682 if [[ -z "${target_jar}" ]] ; then 903 if [[ -z "${target_jar}" ]] ; then
683 [[ -f "${target_jar}" ]] && rm "${target_jar}" 904 [[ -f "${target_jar}" ]] && rm "${target_jar}"
684 ln -snf "${jar}" \ 905 ln -snf "${jar}" \
685 || die "Failed to make symlink from ${jar} to ${jar_name}" 906 || die "Failed to make symlink from ${jar} to ${jar_name}"
686 java-pkg_record-jar_ "${target_pkg}" "${jar}" 907 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
687 # otherwise, if the current jar is the target jar, link it 908 # otherwise, if the current jar is the target jar, link it
688 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 909 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
689 [[ -f "${destjar}" ]] && rm "${destjar}" 910 [[ -f "${destjar}" ]] && rm "${destjar}"
690 ln -snf "${jar}" "${destjar}" \ 911 ln -snf "${jar}" "${destjar}" \
691 || die "Failed to make symlink from ${jar} to ${destjar}" 912 || die "Failed to make symlink from ${jar} to ${destjar}"
692 java-pkg_record-jar_ "${target_pkg}" "${jar}" 913 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
914 popd > /dev/null
693 return 0 915 return 0
694 fi 916 fi
695 done 917 done
918 popd > /dev/null
696 # if no target was specified, we're ok 919 # if no target was specified, we're ok
697 if [[ -z "${target_jar}" ]] ; then 920 if [[ -z "${target_jar}" ]] ; then
698 return 0 921 return 0
699 # otherwise, die bitterly 922 # otherwise, die bitterly
700 else 923 else
714# ------------------------------------------------------------------------------ 937# ------------------------------------------------------------------------------
715# @ebuild-function java-pkg_getjars 938# @ebuild-function java-pkg_getjars
716# 939#
717# Get the classpath provided by any number of packages 940# Get the classpath provided by any number of packages
718# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'. 941# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
942# The providing packages are recorded as dependencies into package.env DEPEND
943# line, unless "--build-only" is passed as the very first argument, for jars
944# that have to be present only at build time and are not needed on runtime
945# (junit testing etc).
719# 946#
720# Example: Get the classpath for xerces-2, 947# Example: Get the classpath for xerces-2 and xalan,
721# java-pkg_getjars xerces-2 xalan 948# java-pkg_getjars xerces-2,xalan
722# Example Return: 949# Example Return:
723# /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
724# 951#
952# @param $opt
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.
725# @param $@ - list of packages to get jars from 957# @param $1 - list of packages to get jars from
958# (passed to java-config --classpath)
726# ------------------------------------------------------------------------------ 959# ------------------------------------------------------------------------------
727java-pkg_getjars() { 960java-pkg_getjars() {
728 debug-print-function ${FUNCNAME} $* 961 debug-print-function ${FUNCNAME} $*
729 962
730 [[ ${#} -lt 1 ]] && die "At least one argument needed" 963 local build_only=""
964 local deep=""
731 965
732 # NOTE could probably just pass $@ to java-config --classpath. and return it 966 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
733 local classpath pkg 967
734 for pkg in ${@//,/ }; do 968 while [[ "${1}" == --* ]]; do
735 #for pkg in $(echo "$@" | tr ',' ' '); do 969 if [[ "${1}" = "--build-only" ]]; then
736 jars="$(java-config --classpath=${pkg})" 970 build_only="build"
737 debug-print "${pkg}:${jars}" 971 elif [[ "${1}" = "--with-dependencies" ]]; then
738 # TODO should we ensure jars exist? 972 deep="--with-dependencies"
739 if [[ -z "${classpath}" ]]; then
740 classpath="${jars}"
741 else 973 else
742 classpath="${classpath}:${jars}" 974 die "java-pkg_jar-from called with unknown parameter: ${1}"
743 fi 975 fi
744 java-pkg_record-jar_ "${pkg}" 976 shift
745 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
746 echo "${classpath}" 1004 echo "${classpath}"
747} 1005}
748 1006
749# ------------------------------------------------------------------------------ 1007# ------------------------------------------------------------------------------
750# @ebuild-function java-pkg_getjar 1008# @ebuild-function java-pkg_getjar
751# 1009#
752# Get the filename of a single jar from a package 1010# Get the filename of a single jar from a package
1011# The providing package is recorded as runtime dependency into package.env
1012# DEPEND line, unless "--build-only" is passed as the very first argument, for
1013# jars that have to be present only at build time and are not needed on runtime
1014# (junit testing etc).
753# 1015#
754# @example 1016# @example
755# java-pkg_getjar xerces-2 xml-apis.jar 1017# java-pkg_getjar xerces-2 xml-apis.jar
756# @example-return 1018# @example-return
757# /usr/share/xerces-2/lib/xml-apis.jar 1019# /usr/share/xerces-2/lib/xml-apis.jar
758# 1020#
1021# @param $opt
1022# --build-only - makes the jar not added into package.env DEPEND line.
759# @param $1 - package to use 1023# @param $1 - package to use
760# @param $2 - jar to get 1024# @param $2 - jar to get
761# ------------------------------------------------------------------------------ 1025# ------------------------------------------------------------------------------
762java-pkg_getjar() { 1026java-pkg_getjar() {
763 debug-print-function ${FUNCNAME} $* 1027 debug-print-function ${FUNCNAME} $*
1028
1029 local build_only=""
1030
1031 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1032
1033 while [[ "${1}" == --* ]]; do
1034 if [[ "${1}" = "--build-only" ]]; then
1035 build_only="build"
1036 else
1037 die "java-pkg_jar-from called with unknown parameter: ${1}"
1038 fi
1039 shift
1040 done
1041
1042 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
764 1043
765 local pkg="${1}" target_jar="${2}" jar 1044 local pkg="${1}" target_jar="${2}" jar
766 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 1045 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
767 [[ -z ${target_jar} ]] && die "Must specify jar to get" 1046 [[ -z ${target_jar} ]] && die "Must specify jar to get"
768 1047
769 # TODO check that package is actually installed 1048 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
1049 local classpath
770 local classpath=$(java-config --classpath=${pkg}) 1050 classpath=$(java-config --classpath=${pkg})
771 [[ $? != 0 ]] && die "There could not find classpath for ${pkg}. Are you sure its installed?" 1051 [[ $? != 0 ]] && die ${error_msg}
1052
1053 java-pkg_ensure-dep "${build_only}" "${pkg}"
1054
772 for jar in ${classpath//:/ }; do 1055 for jar in ${classpath//:/ }; do
773 if [[ ! -f "${jar}" ]] ; then 1056 if [[ ! -f "${jar}" ]] ; then
774 die "Installation problems with jars in ${pkg} - is it installed?" 1057 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
775 fi 1058 fi
776 1059
777 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then 1060 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
778 java-pkg_record-jar_ "${pkg}" "${jar}" 1061 # Only record jars that aren't build-only
1062 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" "${jar}"
779 echo "${jar}" 1063 echo "${jar}"
780 return 0 1064 return 0
781 fi 1065 fi
782 done 1066 done
783 1067
784 die "Could not find ${target_jar} in ${pkg}" 1068 die "Could not find ${target_jar} in ${pkg}"
785 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#
1082# @param $1 - comma-separated list of packages, or a single package
1083# @param $2 - if param $1 is a single package, optionally specify the jar
1084# to depend on
1085#
1086# Example: Record the dependency on whole xerces-2 and xalan,
1087# java-pkg_register-dependency xerces-2,xalan
1088# Example: Record the dependency on ant.jar from ant-core
1089# java-pkg_register-dependency ant-core ant.jar
1090#
1091# Note: Passing both list of packages as the first parameter AND specifying the
1092# jar as the second is not allowed and will cause the function to die. We assume
1093# that there's more chance one passes such combination as a mistake, than that
1094# there are more packages providing identically named jar without class
1095# collisions.
1096# ------------------------------------------------------------------------------
1097java-pkg_register-dependency() {
1098 debug-print-function ${FUNCNAME} $*
1099
1100 java-pkg_check-phase install
1101
1102 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1103
1104 local pkgs="${1}"
1105 local jar="${2}"
1106
1107 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1108
1109 if [[ -z "${jar}" ]]; then
1110 for pkg in ${pkgs//,/ }; do
1111 java-pkg_ensure-dep runtime "${pkg}"
1112 java-pkg_record-jar_ "${pkg}"
1113 done
1114 else
1115 [[ ${pkgs} == *,* ]] && \
1116 die "${FUNCNAME} called with both package list and jar name"
1117 java-pkg_ensure-dep runtime "${pkgs}"
1118 java-pkg_record-jar_ "${pkgs}" "${jar}"
1119 fi
1120
1121 java-pkg_do_write_
1122}
1123
1124# ------------------------------------------------------------------------------
1125# @ebuild-function java-pkg_register-optional-dependency
1126#
1127# Registers optional runtime dependency on a package, list of packages, or a
1128# single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be
1129# called in src_install phase.
1130# Intended for packages that can use other packages when those are in classpath.
1131# Will be put on classpath by launcher if they are installed. Typical case is
1132# JDBC implementations for various databases. It's better than having USE flag
1133# for each implementation triggering hard dependency.
1134#
1135# @param $1 - comma-separated list of packages, or a single package
1136# @param $2 - if param $1 is a single package, optionally specify the jar
1137# to depend on
1138#
1139# Example: Record the optional dependency on some jdbc providers
1140# java-pkg_register-optional-dependency jdbc-jaybird,jtds-1.2,jdbc-mysql
1141#
1142# Note: Passing both list of packages as the first parameter AND specifying the
1143# jar as the second is not allowed and will cause the function to die. We assume
1144# that there's more chance one passes such combination as a mistake, than that
1145# there are more packages providing identically named jar without class
1146# collisions.
1147# ------------------------------------------------------------------------------
1148java-pkg_register-optional-dependency() {
1149 debug-print-function ${FUNCNAME} $*
1150
1151 java-pkg_check-phase install
1152
1153 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1154
1155 local pkgs="${1}"
1156 local jar="${2}"
1157
1158 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1159
1160 if [[ -z "${jar}" ]]; then
1161 for pkg in ${pkgs//,/ }; do
1162 java-pkg_record-jar_ --optional "${pkg}"
1163 done
1164 else
1165 [[ ${pkgs} == *,* ]] && \
1166 die "${FUNCNAME} called with both package list and jar name"
1167 java-pkg_record-jar_ --optional "${pkgs}" "${jar}"
1168 fi
1169
1170 java-pkg_do_write_
1171}
1172
1173# ------------------------------------------------------------------------------
1174# @ebuild-function java-pkg_register-environment-variable
1175#
1176# Register an arbitrary environment variable into package.env. The gjl launcher
1177# for this package or any package depending on this will export it into
1178# environement before executing java command.
1179# Must only be called in src_install phase.
1180#
1181# @param $1 - variable name
1182# @param $2 - variable value
1183# ------------------------------------------------------------------------------
1184JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
1185JAVA_PKG_EXTRA_ENV_VARS=""
1186java-pkg_register-environment-variable() {
1187 debug-print-function ${FUNCNAME} $*
1188
1189 java-pkg_check-phase install
1190
1191 [[ ${#} != 2 ]] && die "${FUNCNAME} takes two arguments"
1192
1193 echo "${1}=\"${2}\"" >> ${JAVA_PKG_EXTRA_ENV}
1194 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
1195
1196 java-pkg_do_write_
786} 1197}
787 1198
788# This function reads stdin, and based on that input, figures out how to 1199# This function reads stdin, and based on that input, figures out how to
789# populate jars from the filesystem. 1200# populate jars from the filesystem.
790# Need to figure out a good way of making use of this, ie be able to use a 1201# Need to figure out a good way of making use of this, ie be able to use a
802# line="${line// /}" 1213# line="${line// /}"
803# 1214#
804# # format: path=jarinfo 1215# # format: path=jarinfo
805# local path=${line%%=*} 1216# local path=${line%%=*}
806# local jarinfo=${line##*=} 1217# local jarinfo=${line##*=}
807# 1218#
808# # format: jar@package 1219# # format: jar@package
809# local jar=${jarinfo%%@*}.jar 1220# local jar=${jarinfo%%@*}.jar
810# local package=${jarinfo##*@} 1221# local package=${jarinfo##*@}
811# if [[ -n ${replace_only} ]]; then 1222# if [[ -n ${replace_only} ]]; then
812# [[ ! -f $path ]] && die "No jar exists at ${path}" 1223# [[ ! -f $path ]] && die "No jar exists at ${path}"
825# @section-end query 1236# @section-end query
826# ------------------------------------------------------------------------------ 1237# ------------------------------------------------------------------------------
827 1238
828# ------------------------------------------------------------------------------ 1239# ------------------------------------------------------------------------------
829# @section-begin helper 1240# @section-begin helper
830# @section-summary Helper functions 1241# @section-summary Helper functions
831# 1242#
832# Various other functions to use from an ebuild 1243# Various other functions to use from an ebuild
833# ------------------------------------------------------------------------------ 1244# ------------------------------------------------------------------------------
834 1245
835# ------------------------------------------------------------------------------ 1246# ------------------------------------------------------------------------------
841# jdbc-stdext 1252# jdbc-stdext
842# jaf 1253# jaf
843# jdbc-rowset 1254# jdbc-rowset
844# jms 1255# jms
845# 1256#
846# @param $1 - Optionally indicate that the dependencies are controlled by 1257# @param $1 - Optionally indicate that the dependencies are controlled by
847# a use flag by specifying '--use' Requires $2. 1258# a use flag by specifying '--use' Requires $2.
848# @param $2 - USE flag which will enable the dependencies. 1259# @param $2 - USE flag which will enable the dependencies.
849# @param $@ - virtual packages to add depenedencies for 1260# @param $@ - virtual packages to add depenedencies for
850# ------------------------------------------------------------------------------ 1261# ------------------------------------------------------------------------------
851# TODO rewrite to parse a line based declaration file instead -- karltk 1262# TODO rewrite to parse a line based declaration file instead -- karltk
907# 1318#
908# export DEPEND="${DEPEND} ${depstr}" 1319# export DEPEND="${DEPEND} ${depstr}"
909# export RDEPEND="${RDEPEND} ${depstr}" 1320# export RDEPEND="${RDEPEND} ${depstr}"
910#} 1321#}
911 1322
1323# ------------------------------------------------------------------------------
1324# @ebuild-function java-pkg_find-normal-jars
1325#
1326# Find the files with suffix .jar file in the given directory or $WORKDIR
1327#
1328# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1329# ------------------------------------------------------------------------------
1330java-pkg_find-normal-jars() {
1331 local dir=$1
1332 [[ "${dir}" ]] || dir="${WORKDIR}"
1333 local found
1334 for jar in $(find "${dir}" -name "*.jar" -type f); do
1335 echo "${jar}"
1336 found="true"
1337 done
1338 [[ "${found}" ]]
1339 return $?
1340}
1341
1342# ------------------------------------------------------------------------------
1343# @ebuild-function java-pkg_ensure-no-bundled-jars
1344#
1345# Try to locate bundled jar files in ${WORKDIR} and die if found.
912# This should be used after S has been populated with symlinks to jars 1346# This function should be called after WORKDIR has been populated with symlink
913# TODO document 1347# to system jar files or bundled jars removed.
1348# ------------------------------------------------------------------------------
914java-pkg_ensure-no-bundled-jars() { 1349java-pkg_ensure-no-bundled-jars() {
915 debug-print-function ${FUNCNAME} $* 1350 debug-print-function ${FUNCNAME} $*
916 pushd ${WORKDIR} >/dev/null 2>/dev/null
917 1351
918 local bundled_jars=$(find . -name "*.jar" -type f) 1352 local bundled_jars=$(java-pkg_find-normal-jars)
919 if [[ -n ${bundled_jars} ]]; then 1353 if [[ -n ${bundled_jars} ]]; then
920 echo "Bundled jars found:" 1354 echo "Bundled jars found:"
921 local jar 1355 local jar
922 for jar in ${bundled_jars}; do 1356 for jar in ${bundled_jars}; do
923 echo $(pwd)${jar/./} 1357 echo $(pwd)${jar/./}
924 done 1358 done
925 die "Bundled jars found!" 1359 die "Bundled jars found!"
926
927 fi 1360 fi
928 popd >/dev/null 2>/dev/null
929} 1361}
930 1362
931# ------------------------------------------------------------------------------ 1363# ------------------------------------------------------------------------------
932# @internal-function java-pkg_ensure-vm-version-sufficient 1364# @internal-function java-pkg_ensure-vm-version-sufficient
933# 1365#
945 fi 1377 fi
946} 1378}
947 1379
948# ------------------------------------------------------------------------------ 1380# ------------------------------------------------------------------------------
949# @internal-function java-pkg_is-vm-version-sufficient 1381# @internal-function java-pkg_is-vm-version-sufficient
950# 1382#
951# @return zero - VM is sufficient 1383# @return zero - VM is sufficient
952# @return non-zero - VM is not sufficient 1384# @return non-zero - VM is not sufficient
953# ------------------------------------------------------------------------------ 1385# ------------------------------------------------------------------------------
954java-pkg_is-vm-version-sufficient() { 1386java-pkg_is-vm-version-sufficient() {
955 debug-print-function ${FUNCNAME} $* 1387 debug-print-function ${FUNCNAME} $*
975 die "Active Java VM too old" 1407 die "Active Java VM too old"
976 fi 1408 fi
977} 1409}
978 1410
979# ------------------------------------------------------------------------------ 1411# ------------------------------------------------------------------------------
980# @internal-function java-pkg_is-vm-version-eq 1412# @internal-function java-pkg_is-vm-version-eq
981# 1413#
982# @param $@ - VM version to compare current VM to 1414# @param $@ - VM version to compare current VM to
983# @return zero - VM versions are equal 1415# @return zero - VM versions are equal
984# @return non-zero - VM version are not equal 1416# @return non-zero - VM version are not equal
985# ------------------------------------------------------------------------------ 1417# ------------------------------------------------------------------------------
986java-pkg_is-vm-version-eq() { 1418java-pkg_is-vm-version-eq() {
1016# 1448#
1017# @param $@ - VM version to compare current to 1449# @param $@ - VM version to compare current to
1018# ------------------------------------------------------------------------------ 1450# ------------------------------------------------------------------------------
1019java-pkg_ensure-vm-version-ge() { 1451java-pkg_ensure-vm-version-ge() {
1020 debug-print-function ${FUNCNAME} $* 1452 debug-print-function ${FUNCNAME} $*
1021 1453
1022 if ! java-pkg_is-vm-version-ge "$@" ; then 1454 if ! java-pkg_is-vm-version-ge "$@" ; then
1023 debug-print "vm is not suffient" 1455 debug-print "vm is not suffient"
1024 eerror "This package requires a Java VM version >= $@" 1456 eerror "This package requires a Java VM version >= $@"
1025 einfo "Please use java-config -S to set the correct one" 1457 einfo "Please use java-config -S to set the correct one"
1026 die "Active Java VM too old" 1458 die "Active Java VM too old"
1027 fi 1459 fi
1028} 1460}
1029 1461
1030# ------------------------------------------------------------------------------ 1462# ------------------------------------------------------------------------------
1031# @internal-function java-pkg_is-vm-version-ge 1463# @internal-function java-pkg_is-vm-version-ge
1032# 1464#
1033# @param $@ - VM version to compare current VM to 1465# @param $@ - VM version to compare current VM to
1034# @return zero - current VM version is greater than checked version 1466# @return zero - current VM version is greater than checked version
1035# @return non-zero - current VM version is not greater than checked version 1467# @return non-zero - current VM version is not greater than checked version
1036# ------------------------------------------------------------------------------ 1468# ------------------------------------------------------------------------------
1037java-pkg_is-vm-version-ge() { 1469java-pkg_is-vm-version-ge() {
1060java-pkg_get-current-vm() { 1492java-pkg_get-current-vm() {
1061 echo ${GENTOO_VM} 1493 echo ${GENTOO_VM}
1062} 1494}
1063 1495
1064java-pkg_current-vm-matches() { 1496java-pkg_current-vm-matches() {
1065 hasq java-pkg_get-currenv-vm ${@} 1497 hasq $(java-pkg_get-current-vm) ${@}
1066 return $? 1498 return $?
1067} 1499}
1068 1500
1069# ------------------------------------------------------------------------------ 1501# ------------------------------------------------------------------------------
1070# @ebuild-function java-pkg_get-source 1502# @ebuild-function java-pkg_get-source
1071# 1503#
1072# Determines what source version should be used, for passing to -source. 1504# Determines what source version should be used, for passing to -source.
1073# Unless you want to break things you probably shouldn't set _WANT_SOURCE 1505# Unless you want to break things you probably shouldn't set _WANT_SOURCE
1074# 1506#
1075# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE 1507# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1076# ------------------------------------------------------------------------------ 1508# ------------------------------------------------------------------------------
1081# ------------------------------------------------------------------------------ 1513# ------------------------------------------------------------------------------
1082# @ebuild-function java-pkg_get-target 1514# @ebuild-function java-pkg_get-target
1083# 1515#
1084# Determines what target version should be used, for passing to -target. 1516# Determines what target version should be used, for passing to -target.
1085# If you don't care about lower versions, you can set _WANT_TARGET to the 1517# If you don't care about lower versions, you can set _WANT_TARGET to the
1086# version of your JDK. 1518# version of your JDK.
1087# Remember doing this will mostly like cause things to break.
1088# Doesn't allow it to be lower then the one in depend.
1089# Doesn't allow it to be higher then the active vm.
1090# 1519#
1091# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1520# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1092# ------------------------------------------------------------------------------ 1521# ------------------------------------------------------------------------------
1093java-pkg_get-target() { 1522java-pkg_get-target() {
1094 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")
1095 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then
1096 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)"
1097 if version_is_at_least "${min}" "${JAVA_PKG_WANT_TARGET}" && version_is_at_least "${JAVA_PKG_WANT_TARGET}" "${max}"; then
1098 echo ${JAVA_PKG_WANT_TARGET}
1099 else
1100 echo ${min}
1101 fi
1102 else
1103 echo ${min}
1104 fi
1105
1106 #echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND}")} 1523 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1107} 1524}
1108 1525
1109java-pkg_get-javac() { 1526java-pkg_get-javac() {
1110 debug-print-function ${FUNCNAME} $* 1527 debug-print-function ${FUNCNAME} $*
1111 1528
1112 java-pkg_init-compiler_ 1529
1113 local compiler="${GENTOO_COMPILER}" 1530 local compiler="${GENTOO_COMPILER}"
1114 1531
1115 local compiler_executable 1532 local compiler_executable
1116 if [[ "${compiler}" = "javac" ]]; then 1533 if [[ "${compiler}" = "javac" ]]; then
1117 # nothing fancy needs to be done for javac 1534 # nothing fancy needs to be done for javac
1125 unset JAVAC 1542 unset JAVAC
1126 # try to get value of JAVAC 1543 # try to get value of JAVAC
1127 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1544 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1128 export JAVAC=${old_javac} 1545 export JAVAC=${old_javac}
1129 1546
1130 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1547 if [[ -z ${compiler_executable} ]]; then
1131 1548 echo "JAVAC is empty or undefined in ${compiler_env}"
1549 return 1
1550 fi
1551
1132 # check that it's executable 1552 # check that it's executable
1133 if [[ ! -x ${compiler_executable} ]]; then 1553 if [[ ! -x ${compiler_executable} ]]; then
1134 eerror "Could not find ${compiler_executable}!"
1135 die "${compiler_executable} doesn't exist, or isn't executable" 1554 echo "${compiler_executable} doesn't exist, or isn't executable"
1555 return 1
1136 fi 1556 fi
1137 else 1557 else
1138 eerror "Could not find environment file for ${compiler}" 1558 echo "Could not find environment file for ${compiler}"
1139 die "Could not find ${compiler_env}" 1559 return 1
1140 fi 1560 fi
1141 fi 1561 fi
1142 echo ${compiler_executable} 1562 echo ${compiler_executable}
1143} 1563}
1144 1564
1145# ------------------------------------------------------------------------------ 1565# ------------------------------------------------------------------------------
1146# @ebuild-function java-pkg_javac-args 1566# @ebuild-function java-pkg_javac-args
1147# 1567#
1148# If an ebuild uses javac directly, instead of using ejavac, it should call this 1568# If an ebuild uses javac directly, instead of using ejavac, it should call this
1149# to know what -source/-target to use. 1569# to know what -source/-target to use.
1150# 1570#
1151# @return string - arguments to pass to javac, complete with -target and -source 1571# @return string - arguments to pass to javac, complete with -target and -source
1154 debug-print-function ${FUNCNAME} $* 1574 debug-print-function ${FUNCNAME} $*
1155 1575
1156 local want_source="$(java-pkg_get-source)" 1576 local want_source="$(java-pkg_get-source)"
1157 local want_target="$(java-pkg_get-target)" 1577 local want_target="$(java-pkg_get-target)"
1158 1578
1159 local source_str="-source ${want_source}" 1579 local source_str="-source ${want_source}"
1160 local target_str="-target ${want_target}" 1580 local target_str="-target ${want_target}"
1161 1581
1162 debug-print "want source: ${want_source}" 1582 debug-print "want source: ${want_source}"
1163 debug-print "want target: ${want_target}" 1583 debug-print "want target: ${want_target}"
1164 1584
1165 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1585 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1166 debug-print "could not find valid -source/-target values" 1586 debug-print "could not find valid -source/-target values for javac"
1167 die "Could not find valid -source/-target values" 1587 echo "Could not find valid -source/-target values for javac"
1588 return 1
1168 else 1589 else
1169 if java-pkg_is-vm-version-ge "1.4"; then 1590 if java-pkg_is-vm-version-ge "1.4"; then
1170 echo "${source_str} ${target_str}" 1591 echo "${source_str} ${target_str}"
1171 else 1592 else
1172 echo "${target_str}" 1593 echo "${target_str}"
1176 1597
1177# TODO document 1598# TODO document
1178java-pkg_get-jni-cflags() { 1599java-pkg_get-jni-cflags() {
1179 local flags="-I${JAVA_HOME}/include" 1600 local flags="-I${JAVA_HOME}/include"
1180 1601
1602 local platform="linux"
1603 use elibc_FreeBSD && platform="freebsd"
1604
1181 # TODO do a check that the directories are valid 1605 # TODO do a check that the directories are valid
1182 # TODO figure out how to cope with other things than linux...
1183 flags="${flags} -I${JAVA_HOME}/include/linux" 1606 flags="${flags} -I${JAVA_HOME}/include/${platform}"
1184 1607
1185 echo ${flags} 1608 echo ${flags}
1186} 1609}
1187 1610
1188java-pkg_ensure-gcj() { 1611java-pkg_ensure-gcj() {
1193 ebeep 5 1616 ebeep 5
1194 die "No GCJ support found!" 1617 die "No GCJ support found!"
1195 fi 1618 fi
1196} 1619}
1197 1620
1621java-pkg_ensure-test() {
1622 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \
1623 && hasq test ${IUSE} && ! use test;
1624 then
1625 eerror "You specified FEATURES=test, but USE=test is needed"
1626 eerror "to pull in the additional dependencies for testing"
1627 die "Need USE=test enabled"
1628 fi
1629}
1630
1631# ------------------------------------------------------------------------------
1632# @ebuild-function java-pkg_register-ant-task
1633#
1634# Register this package as ant task, so that ant will load it when no specific
1635# ANT_TASKS are specified. Note that even without this registering, all packages
1636# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1637# packages, but can be also used by other ebuilds that used to symlink their
1638# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1639# compatibility.
1640#
1641# @param --version x.y Register only for ant version x.y (otherwise for any ant
1642# version). Used by the ant-* packages to prevent loading of mismatched
1643# ant-core ant tasks after core was updated, before the tasks are updated,
1644# without a need for blockers.
1645# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1646# ------------------------------------------------------------------------------
1647java-pkg_register-ant-task() {
1648 local TASKS_DIR="tasks"
1649
1650 # check for --version x.y parameters
1651 while [[ -n "${1}" && -n "${2}" ]]; do
1652 local var="${1#--}"
1653 local val="${2}"
1654 if [[ "${var}" == "version" ]]; then
1655 TASKS_DIR="tasks-${val}"
1656 else
1657 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1658 fi
1659 shift 2
1660 done
1661
1662 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1663
1664 dodir /usr/share/ant/${TASKS_DIR}
1665 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1666}
1667
1668# ------------------------------------------------------------------------------
1669# @internal-function java-pkg_ant-tasks-from-deps
1670#
1671# Function to determine ANT_TASKS from DEPEND variable for backwards
1672# compatibility with ebuilds that don't set ANT_TASKS before calling eant() or
1673# WANT_ANT_TASKS before inheriting java-pkg-2. If the DEPEND string contains
1674# "dev-java/ant" or "dev-java/ant-tasks", then it returns "all", otherwise
1675# "none". It's not smart enough to cope with USE flag depends but that shouldn't
1676# be a problem, the worst it can do is activace all tasks when not needed.
1677# Note that this is called only with JAVA_PKG_STRICT=1, to find ebuilds with
1678# insufficient dependencies, otherwise all available tasks are used for
1679# backwards compatilbility.
1680#
1681# @return "all" or "none"
1682# ------------------------------------------------------------------------------
1683java-pkg_ant-tasks-from-deps() {
1684 local found_ant found_ant_tasks
1685
1686 for dep in ${DEPEND}
1687 do
1688 local ant="$(awk '/(dev-java\/ant)/ { if (match($1, "(dev-java/ant)((-[0-9])+|$)", m)) print m[1] }' <<< ${dep})"
1689 [[ "${ant}" == "dev-java/ant" ]] && found_ant=true
1690 [[ "${dep}" == *"ant-tasks"* ]] && found_ant_tasks=true
1691 done
1692
1693 if [[ -n "${found_ant}" || -n "${found_ant_tasks}" ]]; then
1694 java-pkg_announce-qa-violation --nodie "The ebuild DEPENDS on deprecated ant or ant-tasks"
1695 echo "all"
1696 else
1697 # ebuild doesn't set ANT_TASKS and doesn't depend on ant-tasks or ant
1698 # so we deactivate all tasks that may be installed
1699 echo "none"
1700 fi
1701}
1702
1703# ------------------------------------------------------------------------------
1704# @internal-function java-pkg_ant-tasks-depend
1705#
1706# Translates the WANT_ANT_TASKS variable into valid dependencies.
1707# ------------------------------------------------------------------------------
1708java-pkg_ant-tasks-depend() {
1709 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1710
1711 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1712 local DEP=""
1713 for i in ${WANT_ANT_TASKS}
1714 do
1715 if [[ ${i} != ant-* ]]; then
1716 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1717 return 1
1718 fi
1719 DEP="${DEP}dev-java/${i} "
1720 done
1721 echo ${DEP}
1722 return 0
1723 else
1724 return 0
1725 fi
1726}
1727
1728# ------------------------------------------------------------------------------
1729# @ebuild-function ejunit
1730#
1731# Junit wrapper function. Makes it easier to run the tests and checks for
1732# dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner.
1733#
1734# Examples:
1735# ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1736# ejunit org.blinkenlights.jid3.test.AllTests
1737#
1738# @param $1 - -cp or -classpath
1739# @param $2 - classpath; junit and recorded dependencies get appended
1740# @param $@ - the rest of the parameters are passed to java
1741# ------------------------------------------------------------------------------
1742ejunit() {
1743 debug-print-function ${FUNCNAME} $*
1744
1745 local pkgs
1746 for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
1747 pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
1748 done
1749
1750 local cp=$(java-pkg_getjars --with-dependencies junit${pkgs})
1751 if [[ ${1} = -cp || ${1} = -classpath ]]; then
1752 cp="${2}:${cp}"
1753 shift 2
1754 else
1755 cp=".:${cp}"
1756 fi
1757
1758 local runner=junit.textui.TestRunner
1759 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}"
1760 java -cp "${cp}" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
1761}
1762
1198# ------------------------------------------------------------------------------ 1763# ------------------------------------------------------------------------------
1199# @section-end helper 1764# @section-end helper
1200# ------------------------------------------------------------------------------ 1765# ------------------------------------------------------------------------------
1201 1766
1202# ------------------------------------------------------------------------------ 1767# ------------------------------------------------------------------------------
1209 1774
1210# ------------------------------------------------------------------------------ 1775# ------------------------------------------------------------------------------
1211# @ebuild-function eant 1776# @ebuild-function eant
1212# 1777#
1213# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1778# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1214# compiler. 1779# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1215# 1780# variables:
1781# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1782# gentoo.classpath property. Be sure to call
1783# java-ant_rewrite-classpath in src_unpack.
1784# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1216# ------------------------------------------------------------------------------ 1785# ------------------------------------------------------------------------------
1217eant() { 1786eant() {
1218 debug-print-function ${FUNCNAME} $* 1787 debug-print-function ${FUNCNAME} $*
1219 1788
1220 # FIXME get this working 1789 if ! hasq java-ant-2 ${INHERITED}; then
1221# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then 1790 local msg="You should inherit java-ant-2 when using eant"
1222# java-pkg_announce-qa-violation \ 1791 java-pkg_announce-qa-violation "${msg}"
1223# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1224# fi 1792 fi
1225 1793
1226 local antflags 1794 local antflags="-Dnoget=true -Dmaven.mode.offline=true"
1795
1227 java-pkg_init-compiler_ 1796 java-pkg_init-compiler_
1228 local compiler="${GENTOO_COMPILER}" 1797 local compiler="${GENTOO_COMPILER}"
1229 1798
1230 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1799 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1231 1800
1233 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1802 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1234 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1803 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1235 fi 1804 fi
1236 1805
1237 if [[ ${compiler} != "javac" ]]; then 1806 if [[ ${compiler} != "javac" ]]; then
1238 antflags="-Dbuild.compiler=${build_compiler}" 1807 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1239 # Figure out any extra stuff to put on the classpath for compilers aside 1808 # Figure out any extra stuff to put on the classpath for compilers aside
1240 # from javac 1809 # from javac
1241 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to 1810 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1242 # java-config -p 1811 # java-config -p
1243 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1812 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})"
1248 1817
1249 if is-java-strict; then 1818 if is-java-strict; then
1250 einfo "Disabling system classpath for ant" 1819 einfo "Disabling system classpath for ant"
1251 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1820 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1252 fi 1821 fi
1253 1822
1254 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1823 for arg in "${@}"; do
1255 antflags="${antflags} -debug" 1824 if [[ ${arg} = -lib ]]; then
1825 if is-java-strict; then
1826 eerror "You should not use the -lib argument to eant because it will fail"
1827 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1828 eerror "or ant properties to make dependencies available."
1829 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1830 eerror "split ant (>=dev-java/ant-core-1.7)."
1831 die "eant -lib is deprecated/forbidden"
1832 else
1833 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1834 echo "more info."
1835 fi
1256 fi 1836 fi
1257 1837 done
1838
1839 if has_version ">=dev-java/ant-core-1.7.0"; then
1840 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1841 ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}"
1842
1843 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1844 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1845
1846 if is-java-strict; then
1847 # if ant-tasks were not set by ebuild or forced, try to determine them from depends
1848 if [[ -z "${ANT_TASKS}" ]]; then
1849 ANT_TASKS="$(java-pkg_ant-tasks-from-deps)"
1850 fi
1851 else
1852 # if ant-tasks is not set by ebuild or forced, activate all of them
1853 ANT_TASKS="${ANT_TASKS:-all}"
1854 fi
1855
1856 # at this point, ANT_TASKS should be "all", "none" or explicit list
1857 if [[ "${ANT_TASKS}" == "all" ]]; then
1858 einfo "Using all available ANT_TASKS"
1859 elif [[ "${ANT_TASKS}" == "none" ]]; then
1860 einfo "Disabling all optional ANT_TASKS"
1861 else
1862 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1863 fi
1864
1865 export ANT_TASKS
1866 fi
1867
1868 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1869 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1870
1871 local gcp="${EANT_GENTOO_CLASSPATH}"
1872 local getjarsarg=""
1873
1874 if [[ ${EBUILD_PHASE} = "test" ]]; then
1875 antflags="${antflags} -DJunit.present=true"
1876 [[ ${gcp} && ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1877 getjarsarg="--with-dependencies"
1878 fi
1879
1880 local cp
1881
1882 for atom in ${gcp}; do
1883 cp="${cp}:$(java-pkg_getjars ${getjarsarg} ${atom})"
1884 done
1885
1886 if [[ ${cp} ]]; then
1887 # It seems ant does not like single quotes around ${cp}
1888 antflags="${antflags} -Dgentoo.classpath=\"${cp#:}\""
1889 fi
1890
1258 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1891 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1892 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
1259 ant ${antflags} "${@}" || die "eant failed" 1893 ant ${antflags} "${@}" || die "eant failed"
1260
1261} 1894}
1262 1895
1263# ------------------------------------------------------------------------------ 1896# ------------------------------------------------------------------------------
1264# @ebuild-function ejavac 1897# @ebuild-function ejavac
1265# 1898#
1266# Javac wrapper function. Will use the appropriate compiler, based on 1899# Javac wrapper function. Will use the appropriate compiler, based on
1267# /etc/java-config/compilers.conf 1900# /etc/java-config/compilers.conf
1268# 1901#
1269# @param $@ - Arguments to be passed to the compiler 1902# @param $@ - Arguments to be passed to the compiler
1270# ------------------------------------------------------------------------------ 1903# ------------------------------------------------------------------------------
1271ejavac() { 1904ejavac() {
1272 debug-print-function ${FUNCNAME} $* 1905 debug-print-function ${FUNCNAME} $*
1273 1906
1274 # FIXME using get-javac ends up printing stuff with einfo 1907 java-pkg_init-compiler_
1908
1909 local compiler_executable
1275# local compiler_executable=$(java-pkg_get-javac) 1910 compiler_executable=$(java-pkg_get-javac)
1276 local compiler_executable="javac" 1911 if [[ ${?} != 0 ]]; then
1912 eerror "There was a problem determining compiler: ${compiler_executable}"
1913 die "get-javac failed"
1914 fi
1277 1915
1916 local javac_args
1917 javac_args="$(java-pkg_javac-args)"
1918 if [[ ${?} != 0 ]]; then
1919 eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
1920 die "java-pkg_javac-args failed"
1921 fi
1922
1278 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 1923 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1279 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 1924 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1280} 1925}
1281 1926
1282# ------------------------------------------------------------------------------ 1927# ------------------------------------------------------------------------------
1283# @ebuild-function java-pkg_filter-compiler 1928# @ebuild-function java-pkg_filter-compiler
1284# 1929#
1285# Used to prevent the use of some compilers. Should be used in src_compile. 1930# Used to prevent the use of some compilers. Should be used in src_compile.
1286# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER 1931# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
1287# 1932#
1288# @param $@ - compilers to filter 1933# @param $@ - compilers to filter
1289# ------------------------------------------------------------------------------ 1934# ------------------------------------------------------------------------------
1307# ------------------------------------------------------------------------------ 1952# ------------------------------------------------------------------------------
1308# @ebuild-function use_doc 1953# @ebuild-function use_doc
1309# 1954#
1310# Helper function for getting ant to build javadocs. If the user has USE=doc, 1955# Helper function for getting ant to build javadocs. If the user has USE=doc,
1311# then 'javadoc' or the argument are returned. Otherwise, there is no return. 1956# then 'javadoc' or the argument are returned. Otherwise, there is no return.
1312# 1957#
1313# The output of this should be passed to ant. 1958# The output of this should be passed to ant.
1314# 1959#
1315# Example: build javadocs by calling 'javadoc' target 1960# Example: build javadocs by calling 'javadoc' target
1316# eant $(use_doc) 1961# eant $(use_doc)
1317# Example: build javadocs by calling 'apidoc' target 1962# Example: build javadocs by calling 'apidoc' target
1322# ------------------------------------------------------------------------------ 1967# ------------------------------------------------------------------------------
1323use_doc() { 1968use_doc() {
1324 use doc && echo ${@:-javadoc} 1969 use doc && echo ${@:-javadoc}
1325} 1970}
1326 1971
1972
1327# ------------------------------------------------------------------------------ 1973# ------------------------------------------------------------------------------
1328# @section-end build 1974# @section-end build
1329# ------------------------------------------------------------------------------ 1975# ------------------------------------------------------------------------------
1330 1976
1331# ------------------------------------------------------------------------------ 1977# ------------------------------------------------------------------------------
1332# @section-begin internal 1978# @section-begin internal
1333# @section-summary Internal functions 1979# @section-summary Internal functions
1334# 1980#
1335# Do __NOT__ use any of these from an ebuild! These are only to be used from 1981# Do __NOT__ use any of these from an ebuild! These are only to be used from
1336# within the java eclasses. 1982# within the java eclasses.
1337# ------------------------------------------------------------------------------ 1983# ------------------------------------------------------------------------------
1338 1984
1339# ----------------------------------------------------------------------------- 1985# -----------------------------------------------------------------------------
1340# @function-internal java-pkg_init 1986# @function-internal java-pkg_init
1341# 1987#
1342# The purpose of this function, as the name might imply, is to initialize the 1988# The purpose of this function, as the name might imply, is to initialize the
1343# Java environment. It ensures that that there aren't any environment variables 1989# Java environment. It ensures that that there aren't any environment variables
1344# that'll muss things up. It initializes some variables, which are used 1990# that'll muss things up. It initializes some variables, which are used
1345# internally. And most importantly, it'll switch the VM if necessary. 1991# internally. And most importantly, it'll switch the VM if necessary.
1346# 1992#
1349# 1995#
1350# ----------------------------------------------------------------------------- 1996# -----------------------------------------------------------------------------
1351java-pkg_init() { 1997java-pkg_init() {
1352 unset JAVAC 1998 unset JAVAC
1353 unset JAVA_HOME 1999 unset JAVA_HOME
2000
2001 # People do all kinds of weird things.
2002 # http://forums.gentoo.org/viewtopic-p-3943166.html
2003 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
2004 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
2005 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
2006 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
2007 ewarn "sun-jdk vms and and as such break configure scripts that"
2008 ewarn "use it (for example app-office/openoffice) so we filter it out."
2009 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
2010 ewarn "make.conf for example) to silence this warning or"
2011 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
2012 fi
2013
2014 if [[ -z ${accept} ]]; then
2015 unset _JAVA_OPTIONS
2016 # phase hooks make this run many times without this
2017 I_WANT_GLOBAL_JAVA_OPTIONS="true"
2018 fi
2019
1354 java-pkg_init_paths_ 2020 java-pkg_init_paths_
1355 java-pkg_switch-vm 2021 java-pkg_switch-vm
1356 PATH=${JAVA_HOME}/bin:${PATH} 2022 PATH=${JAVA_HOME}/bin:${PATH}
1357 2023
1358 # TODO we will probably want to set JAVAC and JAVACFLAGS 2024 # TODO we will probably want to set JAVAC and JAVACFLAGS
1359 2025
1360 # Do some QA checks 2026 # Do some QA checks
1361 java-pkg_check-jikes 2027 java-pkg_check-jikes
1362 2028
1363 # When users have crazy classpaths some packages can fail to compile. 2029 # When users have crazy classpaths some packages can fail to compile.
1364 # and everything should work with empty CLASSPATH. 2030 # and everything should work with empty CLASSPATH.
1365 # This also helps prevent unexpected dependencies on random things 2031 # This also helps prevent unexpected dependencies on random things
1366 # from the CLASSPATH. 2032 # from the CLASSPATH.
1367 unset CLASSPATH 2033 unset CLASSPATH
2034
2035 # Unset external ANT_ stuff
2036 unset ANT_TASKS
2037 unset ANT_OPTS
1368} 2038}
1369 2039
1370# ------------------------------------------------------------------------------ 2040# ------------------------------------------------------------------------------
1371# @function-internal java-pkg-init-compiler_ 2041# @function-internal java-pkg-init-compiler_
1372# 2042#
1373# This function attempts to figure out what compiler should be used. It does 2043# This function attempts to figure out what compiler should be used. It does
1374# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the 2044# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
1375# COMPILERS variable defined there. 2045# COMPILERS variable defined there.
1376# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER 2046# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
1377# 2047#
1378# It will go through the list of compilers, and verify that it supports the 2048# It will go through the list of compilers, and verify that it supports the
1379# target and source that are needed. If it is not suitable, then the next 2049# target and source that are needed. If it is not suitable, then the next
1380# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking 2050# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
1381# isn't done. 2051# isn't done.
1382# 2052#
1404 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 2074 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1405 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})" 2075 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
1406 else 2076 else
1407 compilers=${JAVA_PKG_FORCE_COMPILER} 2077 compilers=${JAVA_PKG_FORCE_COMPILER}
1408 fi 2078 fi
1409 2079
1410 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}" 2080 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
1411 2081
1412 # Figure out if we should announce what compiler we're using 2082 # Figure out if we should announce what compiler we're using
1413 local compiler 2083 local compiler
1414 for compiler in ${compilers}; do 2084 for compiler in ${compilers}; do
1417 if [[ ${compiler} = "javac" ]]; then 2087 if [[ ${compiler} = "javac" ]]; then
1418 debug-print "Found javac... breaking" 2088 debug-print "Found javac... breaking"
1419 export GENTOO_COMPILER="javac" 2089 export GENTOO_COMPILER="javac"
1420 break 2090 break
1421 fi 2091 fi
1422 2092
1423 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then 2093 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
1424 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 2094 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1425 einfo "Filtering ${compiler}" 2095 einfo "Filtering ${compiler}"
1426 continue 2096 continue
1427 fi 2097 fi
1428 fi 2098 fi
1429 2099
1430 # for non-javac, we need to make sure it supports the right target and 2100 # for non-javac, we need to make sure it supports the right target and
1431 # source 2101 # source
1432 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 2102 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1433 if [[ -f ${compiler_env} ]]; then 2103 if [[ -f ${compiler_env} ]]; then
1434 local desired_target="$(java-pkg_get-target)" 2104 local desired_target="$(java-pkg_get-target)"
1516# Writes the package.env out to disk. 2186# Writes the package.env out to disk.
1517# 2187#
1518# ------------------------------------------------------------------------------ 2188# ------------------------------------------------------------------------------
1519# TODO change to do-write, to match everything else 2189# TODO change to do-write, to match everything else
1520java-pkg_do_write_() { 2190java-pkg_do_write_() {
2191 debug-print-function ${FUNCNAME} $*
2192 java-pkg_init_paths_
1521 # Create directory for package.env 2193 # Create directory for package.env
1522 dodir "${JAVA_PKG_SHAREPATH}" 2194 dodir "${JAVA_PKG_SHAREPATH}"
1523 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 2195 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f \
2196 "${JAVA_PKG_DEPEND_FILE}" || -f \
2197 "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]]; then
1524 # Create package.env 2198 # Create package.env
1525 ( 2199 (
1526 echo "DESCRIPTION=\"${DESCRIPTION}\"" 2200 echo "DESCRIPTION=\"${DESCRIPTION}\""
1527 echo "GENERATION=\"2\"" 2201 echo "GENERATION=\"2\""
1528 2202
1529 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\"" 2203 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
1530 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 2204 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1531 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 2205 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1532 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 2206 [[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
2207 && echo "DEPEND=\"$(cat "${JAVA_PKG_DEPEND_FILE}" | uniq | tr '\n' ':')\""
2208 [[ -f "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]] \
2209 && echo "OPTIONAL_DEPEND=\"$(cat "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" | uniq | tr '\n' ':')\""
1533 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 2210 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1534 ) > "${JAVA_PKG_ENV}" 2211 ) > "${JAVA_PKG_ENV}"
1535 2212
1536 # register target/source 2213 # register target/source
1537 local target="$(java-pkg_get-target)" 2214 local target="$(java-pkg_get-target)"
1538 local source="$(java-pkg_get-source)" 2215 local source="$(java-pkg_get-source)"
1539 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}" 2216 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
1540 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}" 2217 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
1548 2225
1549 2226
1550 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}" 2227 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
1551 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}" 2228 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
1552 2229
2230 # extra env variables
2231 if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
2232 cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}" || die
2233 # nested echo to remove leading/trailing spaces
2234 echo "ENV_VARS=\"$(echo ${JAVA_PKG_EXTRA_ENV_VARS})\"" \
2235 >> "${JAVA_PKG_ENV}" || die
2236 fi
2237
1553 # Strip unnecessary leading and trailing colons 2238 # Strip unnecessary leading and trailing colons
1554 # TODO try to cleanup if possible 2239 # TODO try to cleanup if possible
1555 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 2240 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
2241 else
2242 debug-print "JAVA_PKG_CLASSPATH, JAVA_PKG_LIBRARY, JAVA_PKG_DEPEND_FILE"
2243 debug-print "or JAVA_PKG_OPTIONAL_DEPEND_FILE not defined so can't"
2244 debug-print "write package.env."
1556 fi 2245 fi
1557} 2246}
1558
1559 2247
1560# ------------------------------------------------------------------------------ 2248# ------------------------------------------------------------------------------
1561# @internal-function java-pkg_record-jar_ 2249# @internal-function java-pkg_record-jar_
1562# 2250#
1563# Record a dependency to the package.env 2251# Record an (optional) dependency to the package.env
1564# 2252# @param --optional - record dependency as optional
2253# @param $1 - package to record
2254# @param $2 - (optional) jar of package to record
1565# ------------------------------------------------------------------------------ 2255# ------------------------------------------------------------------------------
1566JAVA_PKG_DEPEND="${T}/java-pkg-depend" 2256JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2257JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
1567 2258
1568java-pkg_record-jar_() { 2259java-pkg_record-jar_() {
1569 debug-print-function ${FUNCNAME} $* 2260 debug-print-function ${FUNCNAME} $*
2261
2262 local depend_file="${JAVA_PKG_DEPEND_FILE}"
2263 if [[ "${1}" == "--optional" ]]; then
2264 depend_file="${JAVA_PKG_OPTIONAL_DEPEND_FILE}"
2265 shift
2266 fi
1570 2267
1571 local pkg=${1} jar=${2} append 2268 local pkg=${1} jar=${2} append
1572 if [[ -z "${jar}" ]]; then 2269 if [[ -z "${jar}" ]]; then
1573 append="${pkg}" 2270 append="${pkg}"
1574 else 2271 else
1575 append="$(basename ${jar})@${pkg}" 2272 append="$(basename ${jar})@${pkg}"
1576 fi 2273 fi
1577 2274
1578 echo ${append} >> ${JAVA_PKG_DEPEND} 2275 echo "${append}" >> "${depend_file}"
1579} 2276}
1580 2277
1581# ------------------------------------------------------------------------------ 2278# ------------------------------------------------------------------------------
1582# @internal-function java-pkg_append_ 2279# @internal-function java-pkg_append_
1583# 2280#
1607 fi 2304 fi
1608} 2305}
1609 2306
1610# ------------------------------------------------------------------------------ 2307# ------------------------------------------------------------------------------
1611# @internal-function java-pkg_expand_dir_ 2308# @internal-function java-pkg_expand_dir_
1612# 2309#
1613# Gets the full path of the file/directory's parent. 2310# Gets the full path of the file/directory's parent.
1614# @param $1 - file/directory to find parent directory for 2311# @param $1 - file/directory to find parent directory for
1615# @return - path to $1's parent directory 2312# @return - path to $1's parent directory
1616# ------------------------------------------------------------------------------ 2313# ------------------------------------------------------------------------------
1617java-pkg_expand_dir_() { 2314java-pkg_expand_dir_() {
1643# 2340#
1644# ------------------------------------------------------------------------------ 2341# ------------------------------------------------------------------------------
1645java-pkg_setup-vm() { 2342java-pkg_setup-vm() {
1646 debug-print-function ${FUNCNAME} $* 2343 debug-print-function ${FUNCNAME} $*
1647 2344
2345 export LANG="C" LC_ALL="C"
2346
1648 local vendor="$(java-pkg_get-vm-vendor)" 2347 local vendor="$(java-pkg_get-vm-vendor)"
1649 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge 1 5; then 2348 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1650 addpredict "/dev/random" 2349 addpredict "/dev/random"
1651 elif [[ "${vendor}" == "ibm" ]]; then 2350 elif [[ "${vendor}" == "ibm" ]]; then
1652 addpredict "/proc/self/maps" 2351 addpredict "/proc/self/maps"
1653 addpredict "/proc/cpuinfo" 2352 addpredict "/proc/cpuinfo"
1654 export LANG="C" LC_ALL="C"
1655 elif [[ "${vendor}" == "jrockit" ]]; then 2353 elif [[ "${vendor}" == "jrockit" ]]; then
1656 addpredict "/proc/cpuinfo" 2354 addpredict "/proc/cpuinfo"
1657 fi 2355 fi
1658} 2356}
1659 2357
1703# @return - The version of the current VM 2401# @return - The version of the current VM
1704# ------------------------------------------------------------------------------ 2402# ------------------------------------------------------------------------------
1705java-pkg_get-vm-version() { 2403java-pkg_get-vm-version() {
1706 debug-print-function ${FUNCNAME} $* 2404 debug-print-function ${FUNCNAME} $*
1707 2405
1708 java-pkg_get-current-vm | sed -e "s/.*-\([0-9.]\+\).*/\1/" 2406 java-config -g PROVIDES_VERSION
1709} 2407}
1710 2408
1711# ------------------------------------------------------------------------------ 2409# ------------------------------------------------------------------------------
1712# @internal-function java-pkg_switch-vm 2410# @internal-function java-pkg_switch-vm
1713# 2411#
1714# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 2412# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1715# verify that the current VM is sufficient. 2413# verify that the current VM is sufficient.
1716# Setup the environment for the VM being used. 2414# Setup the environment for the VM being used.
1717# ------------------------------------------------------------------------------ 2415# ------------------------------------------------------------------------------
1718java-pkg_switch-vm() { 2416java-pkg_switch-vm() {
2417 debug-print-function ${FUNCNAME} $*
2418
1719 if java-pkg_needs-vm; then 2419 if java-pkg_needs-vm; then
1720 # Use the VM specified by JAVA_PKG_FORCE_VM 2420 # Use the VM specified by JAVA_PKG_FORCE_VM
1721 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then 2421 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1722 # If you're forcing the VM, I hope you know what your doing... 2422 # If you're forcing the VM, I hope you know what your doing...
2423 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1723 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 2424 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1724 # if we're allowed to switch the vm... 2425 # if we're allowed to switch the vm...
1725 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 2426 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1726 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}" 2427 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1727 if [[ -n ${JAVA_PKG_VNEED} ]]; then 2428 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1728 export GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2429 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1729 else 2430 else
1730 export GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2431 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
2432 fi
2433 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
2434 eerror "Unable to determine VM for building from dependencies:"
2435 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
2436 echo "VNEED: ${JAVA_PKG_VNEED}"
2437 die "Failed to determine VM for building."
2438 else
2439 export GENTOO_VM
1731 fi 2440 fi
1732 # otherwise just make sure the current VM is sufficient 2441 # otherwise just make sure the current VM is sufficient
1733 else 2442 else
1734 java-pkg_ensure-vm-version-sufficient 2443 java-pkg_ensure-vm-version-sufficient
1735 fi 2444 fi
1736 debug-print "Using: $(java-config -f)" 2445 debug-print "Using: $(java-config -f)"
1737 2446
1738 java-pkg_setup-vm 2447 java-pkg_setup-vm
1739 2448
1740 export JAVA=$(java-config --java) 2449 export JAVA=$(java-config --java)
1741 export JAVAC=$(java-config --javac) 2450 export JAVAC=$(java-config --javac)
1742 export JAVACFLAGS="$(java-pkg_javac-args)" 2451 JAVACFLAGS="$(java-pkg_javac-args)"
2452 if [[ ${?} != 0 ]]; then
2453 eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
2454 die "java-pkg_javac-args failed"
2455 fi
1743 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 2456 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
2457 export JAVACFLAGS
1744 2458
1745 export JAVA_HOME="$(java-config -g JAVA_HOME)" 2459 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1746 export JDK_HOME=${JAVA_HOME} 2460 export JDK_HOME=${JAVA_HOME}
1747 2461
1748 #TODO If you know a better solution let us know. 2462 #TODO If you know a better solution let us know.
1749 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 2463 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1750 2464
1751 local tann="${T}/announced-vm" 2465 local tann="${T}/announced-vm"
1752 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 2466 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1753 # Add a check for setup/preinst phase... to avoid duplicate outputs 2467 # Add a check for setup/preinst phase... to avoid duplicate outputs
1754 # for when FEATURES=buildpkg 2468 # for when FEATURES=buildpkg
1755 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]]; 2469 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1794 einfo "Classes" 2508 einfo "Classes"
1795 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR}," 2509 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1796 fi 2510 fi
1797} 2511}
1798 2512
1799# TODO document 2513# ------------------------------------------------------------------------------
2514# @internal-function java-pkg_verify-classes
2515#
1800# Verify that the classes were compiled for the right source / target 2516# Verify that the classes were compiled for the right source / target. Dies if
2517# not.
2518# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2519# ------------------------------------------------------------------------------
1801java-pkg_verify-classes() { 2520java-pkg_verify-classes() {
1802 ebegin "Verifying java class versions"
1803 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 2521 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1804 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 2522 local target=$(java-pkg_get-target)
2523 local result
2524 local log="${T}/class-version-verify.log"
2525 if [[ -n "${1}" ]]; then
2526 class-version-verify.py -v -t ${target} "${1}" > "${log}"
1805 result=$? 2527 result=$?
1806 eend ${result}
1807 if [[ ${result} == 0 ]]; then
1808 einfo "All good"
1809 else 2528 else
1810 ewarn "Possible problem" 2529 ebegin "Verifying java class versions (target: ${target})"
1811 die "Bad class files found" 2530 class-version-verify.py -v -t ${target} -r "${D}" > "${log}"
2531 result=$?
2532 eend ${result}
2533 fi
2534 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2535 if [[ ${result} != 0 ]]; then
2536 eerror "Incorrect bytecode version found"
2537 [[ -n "${1}" ]] && eerror "in file: ${1}"
2538 eerror "See ${log} for more details."
2539 die "Incorrect bytecode found"
2540 fi
2541}
2542
2543# ----------------------------------------------------------------------------
2544# @internal-function java-pkg_ensure-dep
2545# Check that a package being used in jarfrom, getjars and getjar is contained
2546# within DEPEND or RDEPEND.
2547# @param $1 - empty - check both vars; "runtime" or "build" - check only
2548# RDEPEND, resp. DEPEND
2549# @param $2 - Package name and slot.
2550
2551java-pkg_ensure-dep() {
2552 debug-print-function ${FUNCNAME} $*
2553
2554 local limit_to="${1}"
2555 local target_pkg="${2}"
2556 local dev_error=""
2557
2558 local stripped_pkg=$(echo "${target_pkg}" | sed \
2559 's/-[0-9]*\(\.[0-9]\)*$//')
2560
2561 debug-print "Matching against: ${stripped_pkg}"
2562
2563 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2564 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2565 dev_error="${dev_error} declared in DEPEND."
2566 if is-java-strict; then
2567 eerror "${dev_error}"
2568 die "${dev_error}"
2569 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2570 eerror "${dev_error}"
2571 elog "Because you have this package installed the package will"
2572 elog "build without problems, but please report this to"
2573 elog "http://bugs.gentoo.org"
1812 fi 2574 fi
1813} 2575 fi
1814 2576
2577 if [[ ${limit_to} != build ]]; then
2578 if [[ ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2579 if [[ ! ( ${PDEPEND} =~ "${stripped_pkg}" ) ]]; then
2580 dev_error="The ebuild is attempting to use ${target_pkg},"
2581 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND"
2582 dev_error="${dev_error} or PDEPEND."
2583 if is-java-strict; then
2584 eerror "${dev_error}"
2585 die "${dev_error}"
2586 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2587 eerror "${dev_error}"
2588 elog "The package will build without problems, but may fail to run"
2589 elog "if you don't have ${target_pkg} installed, so please report"
2590 elog "this to http://bugs.gentoo.org"
2591 fi
2592 fi
2593 fi
2594 fi
2595}
1815 2596
1816# ------------------------------------------------------------------------------ 2597# ------------------------------------------------------------------------------
1817# @section-end internal 2598# @section-end internal
1818# ------------------------------------------------------------------------------ 2599# ------------------------------------------------------------------------------
1819 2600
1820java-pkg_check-phase() { 2601java-pkg_check-phase() {
1821 local phase=${1} 2602 local phase=${1}
1822 local funcname=${2} 2603 local funcname=${FUNCNAME[1]}
1823 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then 2604 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
1824 java-pkg_announce-qa-violation \
1825 "${funcname} used outside of src_${phase}" 2605 local msg="${funcname} used outside of src_${phase}"
2606 java-pkg_announce-qa-violation "${msg}"
1826 fi 2607 fi
1827} 2608}
1828 2609
1829java-pkg_check-versioned-jar() { 2610java-pkg_check-versioned-jar() {
1830 local jar=${1} 2611 local jar=${1}
1839 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2620 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1840 fi 2621 fi
1841} 2622}
1842 2623
1843java-pkg_announce-qa-violation() { 2624java-pkg_announce-qa-violation() {
1844 if is-java-strict; then 2625 local nodie
2626 if [[ ${1} == "--nodie" ]]; then
2627 nodie="true"
2628 shift
2629 fi
1845 echo "Java QA Notice: $@" >&2 2630 echo "Java QA Notice: $@" >&2
1846 increment-qa-violations 2631 increment-qa-violations
1847 fi 2632 [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
1848} 2633}
1849 2634
1850increment-qa-violations() { 2635increment-qa-violations() {
1851 let "JAVA_PKG_QA_VIOLATIONS+=1" 2636 let "JAVA_PKG_QA_VIOLATIONS+=1"
1852 export JAVA_PKG_QA_VIOLATIONS 2637 export JAVA_PKG_QA_VIOLATIONS
1853} 2638}
1854 2639
1855is-java-strict() { 2640is-java-strict() {
1856 hasq java-strict ${FEATURES} && ! hasq -java-strict ${FEATURES} 2641 [[ -n ${JAVA_PKG_STRICT} ]]
1857 return $? 2642 return $?
1858} 2643}
1859 2644
1860# ------------------------------------------------------------------------------ 2645# ------------------------------------------------------------------------------
1861# @eclass-end 2646# @eclass-end

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.88

  ViewVC Help
Powered by ViewVC 1.1.20