/[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.13 Revision 1.93
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.93 2007/09/27 19:47:08 betelgeuse Exp $
10 10
11# ----------------------------------------------------------------------------- 11# -----------------------------------------------------------------------------
12# @eclass-begin 12# @eclass-begin
13# @eclass-shortdesc Java Utility eclass 13# @eclass-shortdesc Java Utility eclass
14# @eclass-maintainer java@gentoo.org 14# @eclass-maintainer java@gentoo.org
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. Previously it was
63# portage with phase hooks support but now we use a version with proper env
64# saving.
65# -----------------------------------------------------------------------------
39JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1" 66JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1.2.7"
40 67
41# ----------------------------------------------------------------------------- 68# -----------------------------------------------------------------------------
42# @variable-internal JAVA_PKG_E_DEPEND 69# @variable-internal JAVA_PKG_E_DEPEND
43# 70#
44# This is a convience variable to be used from the other java eclasses. This is 71# 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 72# the version of java-config we want to use. Usually the latest stable version
46# portage, that includes phase hooks. 73# so that ebuilds can use new features without depending on specific versions.
47# ----------------------------------------------------------------------------- 74# -----------------------------------------------------------------------------
48JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 ${JAVA_PKG_PORTAGE_DEP}" 75JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.33-r1 ${JAVA_PKG_PORTAGE_DEP}"
49 76
50# ----------------------------------------------------------------------------- 77# -----------------------------------------------------------------------------
51# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 78# @variable-external JAVA_PKG_ALLOW_VM_CHANGE
52# @variable-default yes 79# @variable-default yes
53# 80#
100# ----------------------------------------------------------------------------- 127# -----------------------------------------------------------------------------
101 128
102# ----------------------------------------------------------------------------- 129# -----------------------------------------------------------------------------
103# @variable-internal JAVA_PKG_COMPILER_DIR 130# @variable-internal JAVA_PKG_COMPILER_DIR
104# @default /usr/share/java-config-2/compiler 131# @default /usr/share/java-config-2/compiler
105# 132#
106# Directory where compiler settings are saved, without trailing slash. 133# Directory where compiler settings are saved, without trailing slash.
107# Probably shouldn't touch this variable. 134# Probably shouldn't touch this variable.
108# ----------------------------------------------------------------------------- 135# -----------------------------------------------------------------------------
109JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"} 136JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"}
110 137
120 147
121# ----------------------------------------------------------------------------- 148# -----------------------------------------------------------------------------
122# @variable-external JAVA_PKG_FORCE_COMPILER 149# @variable-external JAVA_PKG_FORCE_COMPILER
123# 150#
124# Explicitly set a list of compilers to use. This is normally read from 151# Explicitly set a list of compilers to use. This is normally read from
125# JAVA_PKG_COMPILERS_CONF. 152# JAVA_PKG_COMPILERS_CONF.
126# 153#
127# @note This should only be used internally or for testing. 154# @note This should only be used internally or for testing.
128# @example Use jikes and javac, in that order 155# @example Use jikes and javac, in that order
129# JAVA_PKG_FORCE_COMPILER="jikes javac" 156# JAVA_PKG_FORCE_COMPILER="jikes javac"
130# ----------------------------------------------------------------------------- 157# -----------------------------------------------------------------------------
131 158
159# -----------------------------------------------------------------------------
160# @variable-external JAVA_PKG_FORCE_ANT_TASKS
161#
162# An $IFS separated list of ant tasks. Can be set in environment before calling
163# emerge/ebuild to override variables set in ebuild, mainly for testing before
164# putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in
165# eant() call, not the dependencies specified in WANT_ANT_TASKS.
166#
167# @example JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \
168# ebuild foo.ebuild compile
169#
170# @seealso WANT_ANT_TASKS
171# -----------------------------------------------------------------------------
172
132# TODO document me 173# TODO document me
133JAVA_PKG_QA_VIOLATIONS=0 174JAVA_PKG_QA_VIOLATIONS=0
134 175
135# ----------------------------------------------------------------------------- 176# -----------------------------------------------------------------------------
136# @section-end variables 177# @section-end variables
143# 184#
144# These are used to install Java-related things, such as jars, Javadocs, JNI 185# These are used to install Java-related things, such as jars, Javadocs, JNI
145# libraries, etc. 186# libraries, etc.
146# ----------------------------------------------------------------------------- 187# -----------------------------------------------------------------------------
147 188
189# -----------------------------------------------------------------------------
190# @ebuild-function java-pkg_doexamples
191#
192# Installs given arguments to /usr/share/doc/${PF}/examples
193# If you give it only one parameter and it is a directory it will install
194# everything in that directory to the examples directory.
195#
196# @example
197# java-pkg_doexamples demo
198# java-pkg_doexamples demo/* examples/*
199#
200# @param --subdir - If the examples need a certain directory structure
201# @param $* - list of files to install
202# ------------------------------------------------------------------------------
203java-pkg_doexamples() {
204 debug-print-function ${FUNCNAME} $*
205
206 [[ ${#} -lt 1 ]] && die "At least one argument needed"
207
208 java-pkg_check-phase install
209
210 local dest=/usr/share/doc/${PF}/examples
211 if [[ ${1} == --subdir ]]; then
212 local dest=${dest}/${2}
213 dodir ${dest}
214 shift 2
215 fi
216
217 if [[ ${#} = 1 && -d ${1} ]]; then
218 ( # dont want to pollute calling env
219 insinto "${dest}"
220 doins -r ${1}/*
221 ) || die "Installing examples failed"
222 else
223 ( # dont want to pollute calling env
224 insinto "${dest}"
225 doins -r "$@"
226 ) || die "Installing examples failed"
227 fi
228}
148 229
149# ----------------------------------------------------------------------------- 230# -----------------------------------------------------------------------------
150# @ebuild-function java-pkg_dojar 231# @ebuild-function java-pkg_dojar
151# 232#
152# Installs any number of jars. 233# Installs any number of jars.
153# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default. 234# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default.
154# You can use java-pkg_jarinto to change this path. 235# You can use java-pkg_jarinto to change this path.
155# You should never install a jar with a package version in the filename. 236# You should never install a jar with a package version in the filename.
156# Instead, use java-pkg_newjar defined below. 237# Instead, use java-pkg_newjar defined below.
157# 238#
158# @example 239# @example
159# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar 240# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar
160# 241#
171 # Create JARDEST if it doesn't exist 252 # Create JARDEST if it doesn't exist
172 dodir ${JAVA_PKG_JARDEST} 253 dodir ${JAVA_PKG_JARDEST}
173 254
174 local jar 255 local jar
175 # for each jar 256 # for each jar
176 for jar in "$@"; do 257 for jar in "${@}"; do
177 local jar_basename=$(basename "${jar}") 258 local jar_basename=$(basename "${jar}")
178 259
179 java-pkg_check-versioned-jar ${jar_basename} 260 java-pkg_check-versioned-jar ${jar_basename}
180 261
181 # check if it exists 262 # check if it exists
182 if [[ -e "${jar}" ]] ; then 263 if [[ -e "${jar}" ]] ; then
264 # Don't overwrite if jar has already been installed with the same
265 # name
266 local dest="${D}${JAVA_PKG_JARDEST}/${jar_basename}"
267 if [[ -e "${dest}" ]]; then
268 ewarn "Overwriting ${dest}"
269 fi
270
183 # install it into JARDEST if it's a non-symlink 271 # install it into JARDEST if it's a non-symlink
184 if [[ ! -L "${jar}" ]] ; then 272 if [[ ! -L "${jar}" ]] ; then
273 #but first check class version when in strict mode.
274 is-java-strict && java-pkg_verify-classes "${jar}"
275
185 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 276 INSDESTTREE="${JAVA_PKG_JARDEST}" \
186 doins "${jar}" || die "failed to install ${jar}" 277 doins "${jar}" || die "failed to install ${jar}"
187 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 278 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
188 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}" 279 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}"
189 # make a symlink to the original jar if it's symlink 280 # make a symlink to the original jar if it's symlink
200 291
201 java-pkg_do_write_ 292 java-pkg_do_write_
202} 293}
203 294
204 295
296# ------------------------------------------------------------------------------
297# @internal-function depend-java-query
298#
299# Wrapper for the depend-java-query binary to enable passing USE in env.
300# Using env variables keeps this eclass working with java-config versions that
301# do not handle use flags.
302# ------------------------------------------------------------------------------
303
304depend-java-query() {
305 # Used to have a which call here but it caused endless loops for some people
306 # that had some weird bashrc voodoo for which.
307 USE="${USE}" /usr/bin/depend-java-query "${@}"
308}
205 309
206# ------------------------------------------------------------------------------ 310# ------------------------------------------------------------------------------
207# @ebuild-function java-pkg_regjar 311# @ebuild-function java-pkg_regjar
208# 312#
209# Records an already installed jar in the package.env 313# Records an already installed jar in the package.env
222# will not work, because: 326# will not work, because:
223# * the `for jar in "$@"` can't expand the path to jar file names, as they 327# * the `for jar in "$@"` can't expand the path to jar file names, as they
224# don't exist yet 328# don't exist yet
225# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar' 329# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar'
226# doesn't exist 330# doesn't exist
227# 331#
228# you have to use it as: 332# you have to use it as:
229# 333#
230# java-pkg_regjar ${D}/opt/my-java/lib/*.jar 334# java-pkg_regjar ${D}/opt/my-java/lib/*.jar
231# 335#
232# @param $@ - jars to record 336# @param $@ - jars to record
240 [[ ${#} -lt 1 ]] && die "at least one argument needed" 344 [[ ${#} -lt 1 ]] && die "at least one argument needed"
241 345
242 java-pkg_init_paths_ 346 java-pkg_init_paths_
243 347
244 local jar jar_dir jar_file 348 local jar jar_dir jar_file
245 for jar in "$@"; do 349 for jar in "${@}"; do
246 # TODO use java-pkg_check-versioned-jar 350 # TODO use java-pkg_check-versioned-jar
247 if [[ -e "${jar}" ]]; then 351 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
352 [[ -d "${jar}" || -d "${D}${jar}" ]] \
353 && die "Called ${FUNCNAME} on a directory $*"
354
355 #check that class version correct when in strict mode
356 is-java-strict && java-pkg_verify-classes "${jar}"
357
248 # nelchael: we should strip ${D} in this case too, here's why: 358 # nelchael: we should strip ${D} in this case too, here's why:
249 # imagine such call: 359 # imagine such call:
250 # java-pkg_regjar ${D}/opt/java/*.jar 360 # java-pkg_regjar ${D}/opt/java/*.jar
251 # such call will fall into this case (-e ${jar}) and will 361 # such call will fall into this case (-e ${jar}) and will
252 # record paths with ${D} in package.env 362 # record paths with ${D} in package.env
253 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 363 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 364 else
365 if [[ ${jar} = *\** ]]; then
366 eerror "The argument ${jar} to ${FUNCNAME}"
367 eerror "has * in it. If you want it to glob in"
368 eerror '${D} add ${D} to the argument.'
369 fi
257 die "${jar} does not exist" 370 die "${jar} does not exist"
258 fi 371 fi
259 done 372 done
260 373
261 java-pkg_do_write_ 374 java-pkg_do_write_
262} 375}
263
264 376
265# ------------------------------------------------------------------------------ 377# ------------------------------------------------------------------------------
266# @ebuild-function java-pkg_newjar 378# @ebuild-function java-pkg_newjar
267# 379#
268# Installs a jar with a new name 380# Installs a jar with a new name
279 local original_jar="${1}" 391 local original_jar="${1}"
280 local new_jar="${2:-${PN}.jar}" 392 local new_jar="${2:-${PN}.jar}"
281 local new_jar_dest="${T}/${new_jar}" 393 local new_jar_dest="${T}/${new_jar}"
282 394
283 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 395 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
284 [[ ! -f ${original_jar} ]] && die "${original_jar} does not exist!" 396 [[ ! -f ${original_jar} ]] \
397 && die "${original_jar} does not exist or is not a file!"
285 398
286 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 399 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
287 cp "${original_jar}" "${new_jar_dest}" \ 400 cp "${original_jar}" "${new_jar_dest}" \
288 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 401 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
289 java-pkg_dojar "${new_jar_dest}" 402 java-pkg_dojar "${new_jar_dest}"
290} 403}
291 404
292
293# ------------------------------------------------------------------------------ 405# ------------------------------------------------------------------------------
294# @ebuild-function java-pkg_addcp 406# @ebuild-function java-pkg_addcp
295# 407#
296# Add something to the package's classpath. For jars, you should use dojar, 408# 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. 409# newjar, or regjar. This is typically used to add directories to the classpath.
302java-pkg_addcp() { 414java-pkg_addcp() {
303 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}" 415 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
304 java-pkg_do_write_ 416 java-pkg_do_write_
305} 417}
306 418
307
308# ------------------------------------------------------------------------------ 419# ------------------------------------------------------------------------------
309# @ebuild-function java-pkg_doso 420# @ebuild-function java-pkg_doso
310# 421#
311# Installs any number of JNI libraries 422# Installs any number of JNI libraries
312# They will be installed into /usr/lib by default, but java-pkg_sointo 423# They will be installed into /usr/lib by default, but java-pkg_sointo
313# can be used change this path 424# can be used change this path
314# 425#
315# Example: 426# Example:
340 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 451 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
341 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 452 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
342 # otherwise make a symlink to the symlink's origin 453 # otherwise make a symlink to the symlink's origin
343 else 454 else
344 # TODO use dosym 455 # TODO use dosym
456 ln -s "$(readlink "${lib}")" \
345 ln -s "$(readlink "${lib}")" "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")" 457 "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")"
346 debug-print "${lib} is a symlink, linking accordanly" 458 debug-print "${lib} is a symlink, linking accordanly"
347 fi 459 fi
348 # otherwise die 460 # otherwise die
349 else 461 else
350 die "${lib} does not exist" 462 die "${lib} does not exist"
370 java-pkg_check-phase install 482 java-pkg_check-phase install
371 483
372 [[ ${#} -lt 1 ]] && "at least one argument needed" 484 [[ ${#} -lt 1 ]] && "at least one argument needed"
373 485
374 java-pkg_init_paths_ 486 java-pkg_init_paths_
375 487
376 local lib target_dir 488 local lib target_dir
377 for lib in "$@" ; do 489 for lib in "$@" ; do
378 # Check the absolute path of the lib 490 # Check the absolute path of the lib
379 if [[ -e "${lib}" ]] ; then 491 if [[ -e "${lib}" ]] ; then
380 target_dir="$(java-pkg_expand_dir_ ${lib})" 492 target_dir="$(java-pkg_expand_dir_ ${lib})"
428# ------------------------------------------------------------------------------ 540# ------------------------------------------------------------------------------
429java-pkg_dohtml() { 541java-pkg_dohtml() {
430 debug-print-function ${FUNCNAME} $* 542 debug-print-function ${FUNCNAME} $*
431 543
432 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 544 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
433 # TODO-nichoj find out what exactly -f package-list does 545
546 # from /usr/lib/portage/bin/dohtml -h
547 # -f Set list of allowed extensionless file names.
434 dohtml -f package-list "$@" 548 dohtml -f package-list "$@"
549
435 # this probably shouldn't be here but it provides 550 # this probably shouldn't be here but it provides
436 # a reasonable way to catch # docs for all of the 551 # a reasonable way to catch # docs for all of the
437 # old ebuilds. 552 # old ebuilds.
438 java-pkg_recordjavadoc 553 java-pkg_recordjavadoc
439} 554}
440 555
441# TODO document 556# ------------------------------------------------------------------------------
557# @ebuild-function java-pkg_dojavadoc
558#
559# Installs javadoc documentation. This should be controlled by the doc use flag.
560#
561# @param $1: - The javadoc root directory.
562#
563# @example:
564# java-pkg_dojavadoc docs/api
565#
566# ------------------------------------------------------------------------------
442java-pkg_dojavadoc() { 567java-pkg_dojavadoc() {
568 debug-print-function ${FUNCNAME} $*
443 local dir="$1" 569 local dir="$1"
570
571 # QA checks
444 572
445 java-pkg_check-phase install 573 java-pkg_check-phase install
446 574
447 [[ -z "${dir}" ]] && die "Must specify a directory!" 575 [[ -z "${dir}" ]] && die "Must specify a directory!"
448 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!" 576 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!"
577 if [[ ! -e "${dir}/index.html" ]]; then
578 local msg="No index.html in javadoc directory"
579 ewarn "${msg}"
580 is-java-strict && die "${msg}"
581 fi
582
583 # Renaming to match our directory layout
449 584
450 local dir_to_install="${dir}" 585 local dir_to_install="${dir}"
451 if [[ "$(basename "${dir}")" != "api" ]]; then 586 if [[ "$(basename "${dir}")" != "api" ]]; then
452 dir_to_install="${T}/api" 587 dir_to_install="${T}/api"
453 # TODO use doins 588 # TODO use doins
454 cp -r "${dir}" "${dir_to_install}" || die "cp failed" 589 cp -r "${dir}" "${dir_to_install}" || die "cp failed"
455 fi 590 fi
456 591
592 # Actual installation
593
457 java-pkg_dohtml -r ${dir_to_install} 594 java-pkg_dohtml -r ${dir_to_install}
458} 595}
459 596
460# ------------------------------------------------------------------------------ 597# ------------------------------------------------------------------------------
461# @ebuild-function java-pkg_dosrc 598# @ebuild-function java-pkg_dosrc
462# 599#
463# Installs a zip containing the source for a package, so it can used in 600# Installs a zip containing the source for a package, so it can used in
464# from IDEs like eclipse and netbeans. 601# from IDEs like eclipse and netbeans.
465# 602#
466# Ebuild needs to DEPEND on app-arch/zip to use this. 603# Ebuild needs to DEPEND on app-arch/zip to use this.
467# 604#
468# It also should be controlled by USE=source. 605# It also should be controlled by USE=source.
469# 606#
470# @example: 607# @example:
471# java-pkg_dosrc src/* 608# java-pkg_dosrc src/*
472# 609#
473# ------------------------------------------------------------------------------ 610# ------------------------------------------------------------------------------
474# TODO change so it the arguments it takes are the base directories containing 611# TODO change so it the arguments it takes are the base directories containing
475# source -nichoj 612# source -nichoj
476# TODO should we be able to handle multiple calls to dosrc? -nichoj 613# TODO should we be able to handle multiple calls to dosrc? -nichoj
477# TODO maybe we can take an existing zip/jar? -nichoj 614# TODO maybe we can take an existing zip/jar? -nichoj
478# FIXME apparently this fails if you give it an empty directories 615# FIXME apparently this fails if you give it an empty directories
479java-pkg_dosrc() { 616java-pkg_dosrc() {
480 debug-print-function ${FUNCNAME} $* 617 debug-print-function ${FUNCNAME} $*
481 618
482 [ ${#} -lt 1 ] && die "At least one argument needed" 619 [ ${#} -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 620
487 java-pkg_check-phase install 621 java-pkg_check-phase install
488 622
489 [[ ${#} -lt 1 ]] && die "At least one argument needed" 623 [[ ${#} -lt 1 ]] && die "At least one argument needed"
624
625 if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
626 local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
627 if is-java-strict; then
628 eerror "${msg}"
629 die "${msg}"
630 else
631 echo "${msg}"
632 echo "Please report this to http://bugs.gentoo.org."
633 fi
634 fi
490 635
491 java-pkg_init_paths_ 636 java-pkg_init_paths_
492 637
493 local zip_name="${PN}-src.zip" 638 local zip_name="${PN}-src.zip"
494 local zip_path="${T}/${zip_name}" 639 local zip_path="${T}/${zip_name}"
495 local dir 640 local dir
496 for dir in ${@}; do 641 for dir in "${@}"; do
497 local dir_parent=$(dirname "${dir}") 642 local dir_parent=$(dirname "${dir}")
498 local dir_name=$(basename "${dir}") 643 local dir_name=$(basename "${dir}")
499 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 644 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
500 zip -q -r ${zip_path} ${dir_name} -i '*.java' 645 zip -q -r ${zip_path} ${dir_name} -i '*.java'
501 local result=$? 646 local result=$?
518# @ebuild-function java-pkg_dolauncher 663# @ebuild-function java-pkg_dolauncher
519# 664#
520# Make a wrapper script to lauch/start this package 665# Make a wrapper script to lauch/start this package
521# If necessary, the wrapper will switch to the appropriate VM. 666# If necessary, the wrapper will switch to the appropriate VM.
522# 667#
668# Can be called without parameters if the package installs only one jar
669# that has the Main-class attribute set. The wrapper will be named ${PN}.
670#
523# @param $1 - filename of launcher to create 671# @param $1 - filename of launcher to create
524# @param $2 - options, as follows: 672# @param $2 - options, as follows:
525# --main the.main.class.too.start 673# --main the.main.class.too.start
526# --jar /the/jar/too/launch.jar 674# --jar /the/jar/too/launch.jar or just <name>.jar
527# --java_args 'Extra arguments to pass too jave' 675# --java_args 'Extra arguments to pass to java'
528# --pkg_args 'extra arguments too pass too the package' 676# --pkg_args 'Extra arguments to pass to the package'
529# --pwd 677# --pwd Directory the launcher changes to before executing java
530# -into 678# -into Directory to install the launcher to, instead of /usr/bin
531# -pre 679# -pre Prepend contents of this file to the launcher
532# ------------------------------------------------------------------------------ 680# ------------------------------------------------------------------------------
533java-pkg_dolauncher() { 681java-pkg_dolauncher() {
534 debug-print-function ${FUNCNAME} $* 682 debug-print-function ${FUNCNAME} $*
535 683
536 java-pkg_check-phase install 684 java-pkg_check-phase install
537
538 [[ ${#} -lt 1 ]] && die "Need at least one argument"
539
540 java-pkg_init_paths_ 685 java-pkg_init_paths_
541 686
687 if [[ ${#} = 0 ]]; then
688 local name="${PN}"
689 else
542 local name="${1}" 690 local name="${1}"
691 shift
692 fi
693
543 # TODO rename to launcher 694 # TODO rename to launcher
544 local target="${T}/${name}" 695 local target="${T}/${name}"
696 local var_tmp="${T}/launcher_variables_tmp"
545 local target_dir pre 697 local target_dir pre
546 shift
547 698
548 echo "#!/bin/bash" > "${target}" 699 # Process the other the rest of the arguments
549 while [[ -n "${1}" && -n "${2}" ]]; do 700 while [[ -n "${1}" && -n "${2}" ]]; do
550 local var=${1} value=${2} 701 local var="${1}" value="${2}"
551 if [[ "${var:0:2}" == "--" ]]; then 702 if [[ "${var:0:2}" == "--" ]]; then
703 local var=${var:2}
552 echo "gjl_${var:2}=\"${value}\"" >> "${target}" 704 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
705 local gjl_${var}="${value}"
553 elif [[ "${var}" == "-into" ]]; then 706 elif [[ "${var}" == "-into" ]]; then
554 target_dir="${value}" 707 target_dir="${value}"
555 elif [[ "${var}" == "-pre" ]]; then 708 elif [[ "${var}" == "-pre" ]]; then
556 pre="${value}" 709 pre="${value}"
557 fi 710 fi
558 shift 2 711 shift 2
559 done 712 done
713
714 # Test if no --jar and --main arguments were given and
715 # in that case check if the package only installs one jar
716 # and use that jar.
717 if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
718 local cp="${JAVA_PKG_CLASSPATH}"
719 if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
720 echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
721 else
722 local msg="Not enough information to create a launcher given."
723 msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
724 die "${msg}"
725 fi
726 fi
727
728 # Write the actual script
729 echo "#!/bin/bash" > "${target}"
730 if [[ -n "${pre}" ]]; then
731 if [[ -f "${pre}" ]]; then
732 cat "${pre}" >> "${target}"
733 else
734 die "-pre specified file '${pre}' does not exist"
735 fi
736 fi
560 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 737 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
561 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 738 cat "${var_tmp}" >> "${target}"
739 rm -f "${var_tmp}"
562 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 740 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
563 741
564 if [[ -n "${into}" ]]; then 742 if [[ -n "${target_dir}" ]]; then
565 DESTTREE="${target_dir}" dobin "${target}" 743 DESTTREE="${target_dir}" dobin "${target}"
566 local ret=$? 744 local ret=$?
567 return ${ret} 745 return ${ret}
568 else 746 else
569 dobin "${target}" 747 dobin "${target}"
597 echo "dowar: warning, skipping directory ${war}" 775 echo "dowar: warning, skipping directory ${war}"
598 continue 776 continue
599 else 777 else
600 warpath="${war}" 778 warpath="${war}"
601 fi 779 fi
602 780
603 # Install those files like you mean it 781 # Install those files like you mean it
604 INSOPTIONS="-m 0644" \ 782 INSOPTIONS="-m 0644" \
605 INSDESTTREE=${JAVA_PKG_WARDEST} \ 783 INSDESTTREE=${JAVA_PKG_WARDEST} \
606 doins ${warpath} 784 doins ${warpath}
607 done 785 done
642# @ebuild-function java-pkg_jar-from 820# @ebuild-function java-pkg_jar-from
643# 821#
644# Makes a symlink to a jar from a certain package 822# Makes a symlink to a jar from a certain package
645# A lot of java packages include dependencies in a lib/ directory 823# A lot of java packages include dependencies in a lib/ directory
646# You can use this function to replace these bundled dependencies. 824# You can use this function to replace these bundled dependencies.
825# The dependency is recorded into package.env DEPEND line, unless "--build-only"
826# is passed as the very first argument, for jars that have to be present only
827# at build time and are not needed on runtime (junit testing etc).
647# 828#
648# Example: get all jars from xerces slot 2 829# Example: get all jars from xerces slot 2
649# java-pkg_jar-from xerces-2 830# java-pkg_jar-from xerces-2
650# Example: get a specific jar from xerces slot 2 831# Example: get a specific jar from xerces slot 2
651# java-pkg_jar-from xerces-2 xml-apis.jar 832# java-pkg_jar-from xerces-2 xml-apis.jar
652# Example get a specific jar from xerces slot 2, and name it diffrently 833# 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 834# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
835# Example: get junit.jar which is needed only for building
836# java-pkg_jar-from --build-only junit junit.jar
654# 837#
655# @param $1 - Package to get jars from. 838# @param $opt
839# --build-only - makes the jar(s) not added into package.env DEPEND line.
840# (assumed automatically when called inside src_test)
841# --with-dependencies - get jars also from requested package's dependencies
842# transitively.
843# --into $dir - symlink jar(s) into $dir (must exist) instead of .
844# @param $1 - Package to get jars from, or comma-separated list of packages in
845# case other parameters are not used.
656# @param $2 - jar from package. If not specified, all jars will be used. 846# @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 847# @param $3 - When a single jar is specified, destination filename of the
658# symlink. Defaults to the name of the jar. 848# symlink. Defaults to the name of the jar.
659# ------------------------------------------------------------------------------ 849# ------------------------------------------------------------------------------
660# TODO could probably be cleaned up a little 850# TODO could probably be cleaned up a little
661java-pkg_jar-from() { 851java-pkg_jar-from() {
662 debug-print-function ${FUNCNAME} $* 852 debug-print-function ${FUNCNAME} $*
663 853
854 local build_only=""
855 local destdir="."
856 local deep=""
857
858 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
859
860 while [[ "${1}" == --* ]]; do
861 if [[ "${1}" = "--build-only" ]]; then
862 build_only="build"
863 elif [[ "${1}" = "--with-dependencies" ]]; then
864 deep="--with-dependencies"
865 elif [[ "${1}" = "--into" ]]; then
866 destdir="${2}"
867 shift
868 else
869 die "java-pkg_jar-from called with unknown parameter: ${1}"
870 fi
871 shift
872 done
873
664 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 874 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
665 875
666 [[ -z ${target_pkg} ]] && die "Must specify a package" 876 [[ -z ${target_pkg} ]] && die "Must specify a package"
667 877
668 # default destjar to the target jar 878 # default destjar to the target jar
669 [[ -z "${destjar}" ]] && destjar="${target_jar}" 879 [[ -z "${destjar}" ]] && destjar="${target_jar}"
670 880
881 local error_msg="There was a problem getting the classpath for ${target_pkg}."
882 local classpath
671 local classpath="$(java-config --classpath=${target_pkg})" 883 classpath="$(java-config ${deep} --classpath=${target_pkg})"
672 [[ $? != 0 ]] && die "There was a problem getting the classpath for ${target_pkg}" 884 [[ $? != 0 ]] && die ${error_msg}
885
886 # When we have commas this functions is called to bring jars from multiple
887 # packages. This affects recording of dependencencies performed later
888 # which expects one package only, so we do it here.
889 if [[ ${target_pkg} = *,* ]]; then
890 for pkg in ${target_pkg//,/ }; do
891 java-pkg_ensure-dep "${build_only}" "${pkg}"
892 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
893 done
894 # setting this disables further record-jar_ calls later
895 build_only="build"
896 else
897 java-pkg_ensure-dep "${build_only}" "${target_pkg}"
898 fi
899
900 pushd ${destdir} > /dev/null \
901 || die "failed to change directory to ${destdir}"
673 902
674 local jar 903 local jar
675 for jar in ${classpath//:/ }; do 904 for jar in ${classpath//:/ }; do
676 local jar_name=$(basename "${jar}") 905 local jar_name=$(basename "${jar}")
677 if [[ ! -f "${jar}" ]] ; then 906 if [[ ! -f "${jar}" ]] ; then
681 # If no specific target jar was indicated, link it 910 # If no specific target jar was indicated, link it
682 if [[ -z "${target_jar}" ]] ; then 911 if [[ -z "${target_jar}" ]] ; then
683 [[ -f "${target_jar}" ]] && rm "${target_jar}" 912 [[ -f "${target_jar}" ]] && rm "${target_jar}"
684 ln -snf "${jar}" \ 913 ln -snf "${jar}" \
685 || die "Failed to make symlink from ${jar} to ${jar_name}" 914 || die "Failed to make symlink from ${jar} to ${jar_name}"
686 java-pkg_record-jar_ "${target_pkg}" "${jar}" 915 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
687 # otherwise, if the current jar is the target jar, link it 916 # otherwise, if the current jar is the target jar, link it
688 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 917 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
689 [[ -f "${destjar}" ]] && rm "${destjar}" 918 [[ -f "${destjar}" ]] && rm "${destjar}"
690 ln -snf "${jar}" "${destjar}" \ 919 ln -snf "${jar}" "${destjar}" \
691 || die "Failed to make symlink from ${jar} to ${destjar}" 920 || die "Failed to make symlink from ${jar} to ${destjar}"
692 java-pkg_record-jar_ "${target_pkg}" "${jar}" 921 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
922 popd > /dev/null
693 return 0 923 return 0
694 fi 924 fi
695 done 925 done
926 popd > /dev/null
696 # if no target was specified, we're ok 927 # if no target was specified, we're ok
697 if [[ -z "${target_jar}" ]] ; then 928 if [[ -z "${target_jar}" ]] ; then
698 return 0 929 return 0
699 # otherwise, die bitterly 930 # otherwise, die bitterly
700 else 931 else
714# ------------------------------------------------------------------------------ 945# ------------------------------------------------------------------------------
715# @ebuild-function java-pkg_getjars 946# @ebuild-function java-pkg_getjars
716# 947#
717# Get the classpath provided by any number of packages 948# Get the classpath provided by any number of packages
718# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'. 949# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
950# The providing packages are recorded as dependencies into package.env DEPEND
951# line, unless "--build-only" is passed as the very first argument, for jars
952# that have to be present only at build time and are not needed on runtime
953# (junit testing etc).
719# 954#
720# Example: Get the classpath for xerces-2, 955# Example: Get the classpath for xerces-2 and xalan,
721# java-pkg_getjars xerces-2 xalan 956# java-pkg_getjars xerces-2,xalan
722# Example Return: 957# Example Return:
723# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 958# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
724# 959#
960# @param $opt
961# --build-only - makes the jar(s) not added into package.env DEPEND line.
962# (assumed automatically when called inside src_test)
963# --with-dependencies - get jars also from requested package's dependencies
964# transitively.
725# @param $@ - list of packages to get jars from 965# @param $1 - list of packages to get jars from
966# (passed to java-config --classpath)
726# ------------------------------------------------------------------------------ 967# ------------------------------------------------------------------------------
727java-pkg_getjars() { 968java-pkg_getjars() {
728 debug-print-function ${FUNCNAME} $* 969 debug-print-function ${FUNCNAME} $*
729 970
730 [[ ${#} -lt 1 ]] && die "At least one argument needed" 971 local build_only=""
972 local deep=""
731 973
732 # NOTE could probably just pass $@ to java-config --classpath. and return it 974 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
733 local classpath pkg 975
734 for pkg in ${@//,/ }; do 976 while [[ "${1}" == --* ]]; do
735 #for pkg in $(echo "$@" | tr ',' ' '); do 977 if [[ "${1}" = "--build-only" ]]; then
736 jars="$(java-config --classpath=${pkg})" 978 build_only="build"
737 debug-print "${pkg}:${jars}" 979 elif [[ "${1}" = "--with-dependencies" ]]; then
738 # TODO should we ensure jars exist? 980 deep="--with-dependencies"
739 if [[ -z "${classpath}" ]]; then
740 classpath="${jars}"
741 else 981 else
742 classpath="${classpath}:${jars}" 982 die "java-pkg_jar-from called with unknown parameter: ${1}"
743 fi 983 fi
744 java-pkg_record-jar_ "${pkg}" 984 shift
745 done 985 done
986
987 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
988
989
990 local classpath pkgs="${1}"
991 jars="$(java-config ${deep} --classpath=${pkgs})"
992 [[ $? != 0 || -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed"
993 debug-print "${pkgs}:${jars}"
994
995 for pkg in ${pkgs//,/ }; do
996 java-pkg_ensure-dep "${build_only}" "${pkg}"
997 done
998
999 if [[ -z "${classpath}" ]]; then
1000 classpath="${jars}"
1001 else
1002 classpath="${classpath}:${jars}"
1003 fi
1004
1005 # Only record jars that aren't build-only
1006 if [[ -z "${build_only}" ]]; then
1007 for pkg in ${pkgs//,/ }; do
1008 java-pkg_record-jar_ "${pkg}"
1009 done
1010 fi
1011
746 echo "${classpath}" 1012 echo "${classpath}"
747} 1013}
748 1014
749# ------------------------------------------------------------------------------ 1015# ------------------------------------------------------------------------------
750# @ebuild-function java-pkg_getjar 1016# @ebuild-function java-pkg_getjar
751# 1017#
752# Get the filename of a single jar from a package 1018# Get the filename of a single jar from a package
1019# The providing package is recorded as runtime dependency into package.env
1020# DEPEND line, unless "--build-only" is passed as the very first argument, for
1021# jars that have to be present only at build time and are not needed on runtime
1022# (junit testing etc).
753# 1023#
754# @example 1024# @example
755# java-pkg_getjar xerces-2 xml-apis.jar 1025# java-pkg_getjar xerces-2 xml-apis.jar
756# @example-return 1026# @example-return
757# /usr/share/xerces-2/lib/xml-apis.jar 1027# /usr/share/xerces-2/lib/xml-apis.jar
758# 1028#
1029# @param $opt
1030# --build-only - makes the jar not added into package.env DEPEND line.
759# @param $1 - package to use 1031# @param $1 - package to use
760# @param $2 - jar to get 1032# @param $2 - jar to get
761# ------------------------------------------------------------------------------ 1033# ------------------------------------------------------------------------------
762java-pkg_getjar() { 1034java-pkg_getjar() {
763 debug-print-function ${FUNCNAME} $* 1035 debug-print-function ${FUNCNAME} $*
1036
1037 local build_only=""
1038
1039 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1040
1041 while [[ "${1}" == --* ]]; do
1042 if [[ "${1}" = "--build-only" ]]; then
1043 build_only="build"
1044 else
1045 die "java-pkg_jar-from called with unknown parameter: ${1}"
1046 fi
1047 shift
1048 done
1049
1050 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
764 1051
765 local pkg="${1}" target_jar="${2}" jar 1052 local pkg="${1}" target_jar="${2}" jar
766 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 1053 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
767 [[ -z ${target_jar} ]] && die "Must specify jar to get" 1054 [[ -z ${target_jar} ]] && die "Must specify jar to get"
768 1055
769 # TODO check that package is actually installed 1056 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
1057 local classpath
770 local classpath=$(java-config --classpath=${pkg}) 1058 classpath=$(java-config --classpath=${pkg})
771 [[ $? != 0 ]] && die "There could not find classpath for ${pkg}. Are you sure its installed?" 1059 [[ $? != 0 ]] && die ${error_msg}
1060
1061 java-pkg_ensure-dep "${build_only}" "${pkg}"
1062
772 for jar in ${classpath//:/ }; do 1063 for jar in ${classpath//:/ }; do
773 if [[ ! -f "${jar}" ]] ; then 1064 if [[ ! -f "${jar}" ]] ; then
774 die "Installation problems with jars in ${pkg} - is it installed?" 1065 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
775 fi 1066 fi
776 1067
777 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then 1068 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
778 java-pkg_record-jar_ "${pkg}" "${jar}" 1069 # Only record jars that aren't build-only
1070 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" "${jar}"
779 echo "${jar}" 1071 echo "${jar}"
780 return 0 1072 return 0
781 fi 1073 fi
782 done 1074 done
783 1075
784 die "Could not find ${target_jar} in ${pkg}" 1076 die "Could not find ${target_jar} in ${pkg}"
785 return 1 1077 return 1
1078}
1079
1080# ------------------------------------------------------------------------------
1081# @ebuild-function java-pkg_register-dependency
1082#
1083# Registers runtime dependency on a package, list of packages, or a single jar
1084# from a package, into package.env DEPEND line. Can only be called in
1085# src_install phase.
1086# Intended for binary packages where you don't need to symlink the jars or get
1087# their classpath during build. As such, the dependencies only need to be
1088# specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1089#
1090# @param $1 - comma-separated list of packages, or a single package
1091# @param $2 - if param $1 is a single package, optionally specify the jar
1092# to depend on
1093#
1094# Example: Record the dependency on whole xerces-2 and xalan,
1095# java-pkg_register-dependency xerces-2,xalan
1096# Example: Record the dependency on ant.jar from ant-core
1097# java-pkg_register-dependency ant-core ant.jar
1098#
1099# Note: Passing both list of packages as the first parameter AND specifying the
1100# jar as the second is not allowed and will cause the function to die. We assume
1101# that there's more chance one passes such combination as a mistake, than that
1102# there are more packages providing identically named jar without class
1103# collisions.
1104# ------------------------------------------------------------------------------
1105java-pkg_register-dependency() {
1106 debug-print-function ${FUNCNAME} $*
1107
1108 java-pkg_check-phase install
1109
1110 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1111
1112 local pkgs="${1}"
1113 local jar="${2}"
1114
1115 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1116
1117 if [[ -z "${jar}" ]]; then
1118 for pkg in ${pkgs//,/ }; do
1119 java-pkg_ensure-dep runtime "${pkg}"
1120 java-pkg_record-jar_ "${pkg}"
1121 done
1122 else
1123 [[ ${pkgs} == *,* ]] && \
1124 die "${FUNCNAME} called with both package list and jar name"
1125 java-pkg_ensure-dep runtime "${pkgs}"
1126 java-pkg_record-jar_ "${pkgs}" "${jar}"
1127 fi
1128
1129 java-pkg_do_write_
1130}
1131
1132# ------------------------------------------------------------------------------
1133# @ebuild-function java-pkg_register-optional-dependency
1134#
1135# Registers optional runtime dependency on a package, list of packages, or a
1136# single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be
1137# called in src_install phase.
1138# Intended for packages that can use other packages when those are in classpath.
1139# Will be put on classpath by launcher if they are installed. Typical case is
1140# JDBC implementations for various databases. It's better than having USE flag
1141# for each implementation triggering hard dependency.
1142#
1143# @param $1 - comma-separated list of packages, or a single package
1144# @param $2 - if param $1 is a single package, optionally specify the jar
1145# to depend on
1146#
1147# Example: Record the optional dependency on some jdbc providers
1148# java-pkg_register-optional-dependency jdbc-jaybird,jtds-1.2,jdbc-mysql
1149#
1150# Note: Passing both list of packages as the first parameter AND specifying the
1151# jar as the second is not allowed and will cause the function to die. We assume
1152# that there's more chance one passes such combination as a mistake, than that
1153# there are more packages providing identically named jar without class
1154# collisions.
1155# ------------------------------------------------------------------------------
1156java-pkg_register-optional-dependency() {
1157 debug-print-function ${FUNCNAME} $*
1158
1159 java-pkg_check-phase install
1160
1161 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1162
1163 local pkgs="${1}"
1164 local jar="${2}"
1165
1166 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1167
1168 if [[ -z "${jar}" ]]; then
1169 for pkg in ${pkgs//,/ }; do
1170 java-pkg_record-jar_ --optional "${pkg}"
1171 done
1172 else
1173 [[ ${pkgs} == *,* ]] && \
1174 die "${FUNCNAME} called with both package list and jar name"
1175 java-pkg_record-jar_ --optional "${pkgs}" "${jar}"
1176 fi
1177
1178 java-pkg_do_write_
1179}
1180
1181# ------------------------------------------------------------------------------
1182# @ebuild-function java-pkg_register-environment-variable
1183#
1184# Register an arbitrary environment variable into package.env. The gjl launcher
1185# for this package or any package depending on this will export it into
1186# environement before executing java command.
1187# Must only be called in src_install phase.
1188#
1189# @param $1 - variable name
1190# @param $2 - variable value
1191# ------------------------------------------------------------------------------
1192JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
1193JAVA_PKG_EXTRA_ENV_VARS=""
1194java-pkg_register-environment-variable() {
1195 debug-print-function ${FUNCNAME} $*
1196
1197 java-pkg_check-phase install
1198
1199 [[ ${#} != 2 ]] && die "${FUNCNAME} takes two arguments"
1200
1201 echo "${1}=\"${2}\"" >> ${JAVA_PKG_EXTRA_ENV}
1202 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
1203
1204 java-pkg_do_write_
786} 1205}
787 1206
788# This function reads stdin, and based on that input, figures out how to 1207# This function reads stdin, and based on that input, figures out how to
789# populate jars from the filesystem. 1208# populate jars from the filesystem.
790# Need to figure out a good way of making use of this, ie be able to use a 1209# Need to figure out a good way of making use of this, ie be able to use a
802# line="${line// /}" 1221# line="${line// /}"
803# 1222#
804# # format: path=jarinfo 1223# # format: path=jarinfo
805# local path=${line%%=*} 1224# local path=${line%%=*}
806# local jarinfo=${line##*=} 1225# local jarinfo=${line##*=}
807# 1226#
808# # format: jar@package 1227# # format: jar@package
809# local jar=${jarinfo%%@*}.jar 1228# local jar=${jarinfo%%@*}.jar
810# local package=${jarinfo##*@} 1229# local package=${jarinfo##*@}
811# if [[ -n ${replace_only} ]]; then 1230# if [[ -n ${replace_only} ]]; then
812# [[ ! -f $path ]] && die "No jar exists at ${path}" 1231# [[ ! -f $path ]] && die "No jar exists at ${path}"
825# @section-end query 1244# @section-end query
826# ------------------------------------------------------------------------------ 1245# ------------------------------------------------------------------------------
827 1246
828# ------------------------------------------------------------------------------ 1247# ------------------------------------------------------------------------------
829# @section-begin helper 1248# @section-begin helper
830# @section-summary Helper functions 1249# @section-summary Helper functions
831# 1250#
832# Various other functions to use from an ebuild 1251# Various other functions to use from an ebuild
833# ------------------------------------------------------------------------------ 1252# ------------------------------------------------------------------------------
834 1253
835# ------------------------------------------------------------------------------ 1254# ------------------------------------------------------------------------------
841# jdbc-stdext 1260# jdbc-stdext
842# jaf 1261# jaf
843# jdbc-rowset 1262# jdbc-rowset
844# jms 1263# jms
845# 1264#
846# @param $1 - Optionally indicate that the dependencies are controlled by 1265# @param $1 - Optionally indicate that the dependencies are controlled by
847# a use flag by specifying '--use' Requires $2. 1266# a use flag by specifying '--use' Requires $2.
848# @param $2 - USE flag which will enable the dependencies. 1267# @param $2 - USE flag which will enable the dependencies.
849# @param $@ - virtual packages to add depenedencies for 1268# @param $@ - virtual packages to add depenedencies for
850# ------------------------------------------------------------------------------ 1269# ------------------------------------------------------------------------------
851# TODO rewrite to parse a line based declaration file instead -- karltk 1270# TODO rewrite to parse a line based declaration file instead -- karltk
907# 1326#
908# export DEPEND="${DEPEND} ${depstr}" 1327# export DEPEND="${DEPEND} ${depstr}"
909# export RDEPEND="${RDEPEND} ${depstr}" 1328# export RDEPEND="${RDEPEND} ${depstr}"
910#} 1329#}
911 1330
1331# ------------------------------------------------------------------------------
1332# @ebuild-function java-pkg_find-normal-jars
1333#
1334# Find the files with suffix .jar file in the given directory or $WORKDIR
1335#
1336# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1337# ------------------------------------------------------------------------------
1338java-pkg_find-normal-jars() {
1339 local dir=$1
1340 [[ "${dir}" ]] || dir="${WORKDIR}"
1341 local found
1342 for jar in $(find "${dir}" -name "*.jar" -type f); do
1343 echo "${jar}"
1344 found="true"
1345 done
1346 [[ "${found}" ]]
1347 return $?
1348}
1349
1350# ------------------------------------------------------------------------------
1351# @ebuild-function java-pkg_ensure-no-bundled-jars
1352#
1353# 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 1354# This function should be called after WORKDIR has been populated with symlink
913# TODO document 1355# to system jar files or bundled jars removed.
1356# ------------------------------------------------------------------------------
914java-pkg_ensure-no-bundled-jars() { 1357java-pkg_ensure-no-bundled-jars() {
915 debug-print-function ${FUNCNAME} $* 1358 debug-print-function ${FUNCNAME} $*
916 pushd ${WORKDIR} >/dev/null 2>/dev/null
917 1359
918 local bundled_jars=$(find . -name "*.jar" -type f) 1360 local bundled_jars=$(java-pkg_find-normal-jars)
919 if [[ -n ${bundled_jars} ]]; then 1361 if [[ -n ${bundled_jars} ]]; then
920 echo "Bundled jars found:" 1362 echo "Bundled jars found:"
921 local jar 1363 local jar
922 for jar in ${bundled_jars}; do 1364 for jar in ${bundled_jars}; do
923 echo $(pwd)${jar/./} 1365 echo $(pwd)${jar/./}
924 done 1366 done
925 die "Bundled jars found!" 1367 die "Bundled jars found!"
926
927 fi 1368 fi
928 popd >/dev/null 2>/dev/null
929} 1369}
930 1370
931# ------------------------------------------------------------------------------ 1371# ------------------------------------------------------------------------------
932# @internal-function java-pkg_ensure-vm-version-sufficient 1372# @internal-function java-pkg_ensure-vm-version-sufficient
933# 1373#
945 fi 1385 fi
946} 1386}
947 1387
948# ------------------------------------------------------------------------------ 1388# ------------------------------------------------------------------------------
949# @internal-function java-pkg_is-vm-version-sufficient 1389# @internal-function java-pkg_is-vm-version-sufficient
950# 1390#
951# @return zero - VM is sufficient 1391# @return zero - VM is sufficient
952# @return non-zero - VM is not sufficient 1392# @return non-zero - VM is not sufficient
953# ------------------------------------------------------------------------------ 1393# ------------------------------------------------------------------------------
954java-pkg_is-vm-version-sufficient() { 1394java-pkg_is-vm-version-sufficient() {
955 debug-print-function ${FUNCNAME} $* 1395 debug-print-function ${FUNCNAME} $*
975 die "Active Java VM too old" 1415 die "Active Java VM too old"
976 fi 1416 fi
977} 1417}
978 1418
979# ------------------------------------------------------------------------------ 1419# ------------------------------------------------------------------------------
980# @internal-function java-pkg_is-vm-version-eq 1420# @internal-function java-pkg_is-vm-version-eq
981# 1421#
982# @param $@ - VM version to compare current VM to 1422# @param $@ - VM version to compare current VM to
983# @return zero - VM versions are equal 1423# @return zero - VM versions are equal
984# @return non-zero - VM version are not equal 1424# @return non-zero - VM version are not equal
985# ------------------------------------------------------------------------------ 1425# ------------------------------------------------------------------------------
986java-pkg_is-vm-version-eq() { 1426java-pkg_is-vm-version-eq() {
1016# 1456#
1017# @param $@ - VM version to compare current to 1457# @param $@ - VM version to compare current to
1018# ------------------------------------------------------------------------------ 1458# ------------------------------------------------------------------------------
1019java-pkg_ensure-vm-version-ge() { 1459java-pkg_ensure-vm-version-ge() {
1020 debug-print-function ${FUNCNAME} $* 1460 debug-print-function ${FUNCNAME} $*
1021 1461
1022 if ! java-pkg_is-vm-version-ge "$@" ; then 1462 if ! java-pkg_is-vm-version-ge "$@" ; then
1023 debug-print "vm is not suffient" 1463 debug-print "vm is not suffient"
1024 eerror "This package requires a Java VM version >= $@" 1464 eerror "This package requires a Java VM version >= $@"
1025 einfo "Please use java-config -S to set the correct one" 1465 einfo "Please use java-config -S to set the correct one"
1026 die "Active Java VM too old" 1466 die "Active Java VM too old"
1027 fi 1467 fi
1028} 1468}
1029 1469
1030# ------------------------------------------------------------------------------ 1470# ------------------------------------------------------------------------------
1031# @internal-function java-pkg_is-vm-version-ge 1471# @internal-function java-pkg_is-vm-version-ge
1032# 1472#
1033# @param $@ - VM version to compare current VM to 1473# @param $@ - VM version to compare current VM to
1034# @return zero - current VM version is greater than checked version 1474# @return zero - current VM version is greater than checked version
1035# @return non-zero - current VM version is not greater than checked version 1475# @return non-zero - current VM version is not greater than checked version
1036# ------------------------------------------------------------------------------ 1476# ------------------------------------------------------------------------------
1037java-pkg_is-vm-version-ge() { 1477java-pkg_is-vm-version-ge() {
1060java-pkg_get-current-vm() { 1500java-pkg_get-current-vm() {
1061 echo ${GENTOO_VM} 1501 echo ${GENTOO_VM}
1062} 1502}
1063 1503
1064java-pkg_current-vm-matches() { 1504java-pkg_current-vm-matches() {
1065 hasq java-pkg_get-currenv-vm ${@} 1505 hasq $(java-pkg_get-current-vm) ${@}
1066 return $? 1506 return $?
1067} 1507}
1068 1508
1069# ------------------------------------------------------------------------------ 1509# ------------------------------------------------------------------------------
1070# @ebuild-function java-pkg_get-source 1510# @ebuild-function java-pkg_get-source
1071# 1511#
1072# Determines what source version should be used, for passing to -source. 1512# 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 1513# Unless you want to break things you probably shouldn't set _WANT_SOURCE
1074# 1514#
1075# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE 1515# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1076# ------------------------------------------------------------------------------ 1516# ------------------------------------------------------------------------------
1081# ------------------------------------------------------------------------------ 1521# ------------------------------------------------------------------------------
1082# @ebuild-function java-pkg_get-target 1522# @ebuild-function java-pkg_get-target
1083# 1523#
1084# Determines what target version should be used, for passing to -target. 1524# 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 1525# If you don't care about lower versions, you can set _WANT_TARGET to the
1086# version of your JDK. 1526# 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# 1527#
1091# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1528# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1092# ------------------------------------------------------------------------------ 1529# ------------------------------------------------------------------------------
1093java-pkg_get-target() { 1530java-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}")} 1531 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1107} 1532}
1108 1533
1109java-pkg_get-javac() { 1534java-pkg_get-javac() {
1110 debug-print-function ${FUNCNAME} $* 1535 debug-print-function ${FUNCNAME} $*
1111 1536
1112 java-pkg_init-compiler_ 1537
1113 local compiler="${GENTOO_COMPILER}" 1538 local compiler="${GENTOO_COMPILER}"
1114 1539
1115 local compiler_executable 1540 local compiler_executable
1116 if [[ "${compiler}" = "javac" ]]; then 1541 if [[ "${compiler}" = "javac" ]]; then
1117 # nothing fancy needs to be done for javac 1542 # nothing fancy needs to be done for javac
1125 unset JAVAC 1550 unset JAVAC
1126 # try to get value of JAVAC 1551 # try to get value of JAVAC
1127 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1552 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1128 export JAVAC=${old_javac} 1553 export JAVAC=${old_javac}
1129 1554
1130 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1555 if [[ -z ${compiler_executable} ]]; then
1131 1556 echo "JAVAC is empty or undefined in ${compiler_env}"
1557 return 1
1558 fi
1559
1132 # check that it's executable 1560 # check that it's executable
1133 if [[ ! -x ${compiler_executable} ]]; then 1561 if [[ ! -x ${compiler_executable} ]]; then
1134 eerror "Could not find ${compiler_executable}!"
1135 die "${compiler_executable} doesn't exist, or isn't executable" 1562 echo "${compiler_executable} doesn't exist, or isn't executable"
1563 return 1
1136 fi 1564 fi
1137 else 1565 else
1138 eerror "Could not find environment file for ${compiler}" 1566 echo "Could not find environment file for ${compiler}"
1139 die "Could not find ${compiler_env}" 1567 return 1
1140 fi 1568 fi
1141 fi 1569 fi
1142 echo ${compiler_executable} 1570 echo ${compiler_executable}
1143} 1571}
1144 1572
1145# ------------------------------------------------------------------------------ 1573# ------------------------------------------------------------------------------
1146# @ebuild-function java-pkg_javac-args 1574# @ebuild-function java-pkg_javac-args
1147# 1575#
1148# If an ebuild uses javac directly, instead of using ejavac, it should call this 1576# If an ebuild uses javac directly, instead of using ejavac, it should call this
1149# to know what -source/-target to use. 1577# to know what -source/-target to use.
1150# 1578#
1151# @return string - arguments to pass to javac, complete with -target and -source 1579# @return string - arguments to pass to javac, complete with -target and -source
1154 debug-print-function ${FUNCNAME} $* 1582 debug-print-function ${FUNCNAME} $*
1155 1583
1156 local want_source="$(java-pkg_get-source)" 1584 local want_source="$(java-pkg_get-source)"
1157 local want_target="$(java-pkg_get-target)" 1585 local want_target="$(java-pkg_get-target)"
1158 1586
1159 local source_str="-source ${want_source}" 1587 local source_str="-source ${want_source}"
1160 local target_str="-target ${want_target}" 1588 local target_str="-target ${want_target}"
1161 1589
1162 debug-print "want source: ${want_source}" 1590 debug-print "want source: ${want_source}"
1163 debug-print "want target: ${want_target}" 1591 debug-print "want target: ${want_target}"
1164 1592
1165 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1593 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1166 debug-print "could not find valid -source/-target values" 1594 debug-print "could not find valid -source/-target values for javac"
1167 die "Could not find valid -source/-target values" 1595 echo "Could not find valid -source/-target values for javac"
1596 return 1
1168 else 1597 else
1169 if java-pkg_is-vm-version-ge "1.4"; then 1598 if java-pkg_is-vm-version-ge "1.4"; then
1170 echo "${source_str} ${target_str}" 1599 echo "${source_str} ${target_str}"
1171 else 1600 else
1172 echo "${target_str}" 1601 echo "${target_str}"
1176 1605
1177# TODO document 1606# TODO document
1178java-pkg_get-jni-cflags() { 1607java-pkg_get-jni-cflags() {
1179 local flags="-I${JAVA_HOME}/include" 1608 local flags="-I${JAVA_HOME}/include"
1180 1609
1610 local platform="linux"
1611 use elibc_FreeBSD && platform="freebsd"
1612
1181 # TODO do a check that the directories are valid 1613 # 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" 1614 flags="${flags} -I${JAVA_HOME}/include/${platform}"
1184 1615
1185 echo ${flags} 1616 echo ${flags}
1186} 1617}
1187 1618
1188java-pkg_ensure-gcj() { 1619java-pkg_ensure-gcj() {
1194 die "No GCJ support found!" 1625 die "No GCJ support found!"
1195 fi 1626 fi
1196} 1627}
1197 1628
1198java-pkg_ensure-test() { 1629java-pkg_ensure-test() {
1199 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} && ! use test; then 1630 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \
1631 && hasq test ${IUSE} && ! use test;
1632 then
1200 eerror "You specified FEATURES=test, but USE=test is needed" 1633 eerror "You specified FEATURES=test, but USE=test is needed"
1201 eerror "to pull in the additional dependencies for testing" 1634 eerror "to pull in the additional dependencies for testing"
1202 die "Need USE=test enabled" 1635 die "Need USE=test enabled"
1203 fi 1636 fi
1204} 1637}
1205 1638
1206# ------------------------------------------------------------------------------ 1639# ------------------------------------------------------------------------------
1640# @ebuild-function java-pkg_register-ant-task
1641#
1642# Register this package as ant task, so that ant will load it when no specific
1643# ANT_TASKS are specified. Note that even without this registering, all packages
1644# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1645# packages, but can be also used by other ebuilds that used to symlink their
1646# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1647# compatibility.
1648#
1649# @param --version x.y Register only for ant version x.y (otherwise for any ant
1650# version). Used by the ant-* packages to prevent loading of mismatched
1651# ant-core ant tasks after core was updated, before the tasks are updated,
1652# without a need for blockers.
1653# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1654# ------------------------------------------------------------------------------
1655java-pkg_register-ant-task() {
1656 local TASKS_DIR="tasks"
1657
1658 # check for --version x.y parameters
1659 while [[ -n "${1}" && -n "${2}" ]]; do
1660 local var="${1#--}"
1661 local val="${2}"
1662 if [[ "${var}" == "version" ]]; then
1663 TASKS_DIR="tasks-${val}"
1664 else
1665 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1666 fi
1667 shift 2
1668 done
1669
1670 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1671
1672 dodir /usr/share/ant/${TASKS_DIR}
1673 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1674}
1675
1676# ------------------------------------------------------------------------------
1677# @internal-function java-pkg_ant-tasks-from-deps
1678#
1679# Function to determine ANT_TASKS from DEPEND variable for backwards
1680# compatibility with ebuilds that don't set ANT_TASKS before calling eant() or
1681# WANT_ANT_TASKS before inheriting java-pkg-2. If the DEPEND string contains
1682# "dev-java/ant" or "dev-java/ant-tasks", then it returns "all", otherwise
1683# "none". It's not smart enough to cope with USE flag depends but that shouldn't
1684# be a problem, the worst it can do is activace all tasks when not needed.
1685# Note that this is called only with JAVA_PKG_STRICT=1, to find ebuilds with
1686# insufficient dependencies, otherwise all available tasks are used for
1687# backwards compatilbility.
1688#
1689# @return "all" or "none"
1690# ------------------------------------------------------------------------------
1691java-pkg_ant-tasks-from-deps() {
1692 local found_ant found_ant_tasks
1693
1694 for dep in ${DEPEND}
1695 do
1696 local ant="$(awk '/(dev-java\/ant)/ { if (match($1, "(dev-java/ant)((-[0-9])+|$)", m)) print m[1] }' <<< ${dep})"
1697 [[ "${ant}" == "dev-java/ant" ]] && found_ant=true
1698 [[ "${dep}" == *"ant-tasks"* ]] && found_ant_tasks=true
1699 done
1700
1701 if [[ -n "${found_ant}" || -n "${found_ant_tasks}" ]]; then
1702 java-pkg_announce-qa-violation --nodie "The ebuild DEPENDS on deprecated ant or ant-tasks"
1703 echo "all"
1704 else
1705 # ebuild doesn't set ANT_TASKS and doesn't depend on ant-tasks or ant
1706 # so we deactivate all tasks that may be installed
1707 echo "none"
1708 fi
1709}
1710
1711# ------------------------------------------------------------------------------
1712# @internal-function java-pkg_ant-tasks-depend
1713#
1714# Translates the WANT_ANT_TASKS variable into valid dependencies.
1715# ------------------------------------------------------------------------------
1716java-pkg_ant-tasks-depend() {
1717 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1718
1719 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1720 local DEP=""
1721 for i in ${WANT_ANT_TASKS}
1722 do
1723 if [[ ${i} != ant-* ]]; then
1724 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1725 return 1
1726 fi
1727 DEP="${DEP}dev-java/${i} "
1728 done
1729 echo ${DEP}
1730 return 0
1731 else
1732 return 0
1733 fi
1734}
1735
1736# ------------------------------------------------------------------------------
1737# @ebuild-function ejunit
1738#
1739# Junit wrapper function. Makes it easier to run the tests and checks for
1740# dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner.
1741#
1742# Examples:
1743# ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1744# ejunit org.blinkenlights.jid3.test.AllTests
1745#
1746# @param $1 - -cp or -classpath
1747# @param $2 - classpath; junit and recorded dependencies get appended
1748# @param $@ - the rest of the parameters are passed to java
1749# ------------------------------------------------------------------------------
1750ejunit() {
1751 debug-print-function ${FUNCNAME} $*
1752
1753 local pkgs
1754 for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
1755 pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
1756 done
1757
1758 local cp=$(java-pkg_getjars --with-dependencies junit${pkgs})
1759 if [[ ${1} = -cp || ${1} = -classpath ]]; then
1760 cp="${2}:${cp}"
1761 shift 2
1762 else
1763 cp=".:${cp}"
1764 fi
1765
1766 local runner=junit.textui.TestRunner
1767 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}"
1768 java -cp "${cp}" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
1769}
1770
1771# ------------------------------------------------------------------------------
1207# @section-end helper 1772# @section-end helper
1208# ------------------------------------------------------------------------------ 1773# ------------------------------------------------------------------------------
1209 1774
1210# ------------------------------------------------------------------------------ 1775# ------------------------------------------------------------------------------
1211# @section-begin build 1776# @section-begin build
1217 1782
1218# ------------------------------------------------------------------------------ 1783# ------------------------------------------------------------------------------
1219# @ebuild-function eant 1784# @ebuild-function eant
1220# 1785#
1221# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1786# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1222# compiler. 1787# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1223# 1788# variables:
1789# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1790# gentoo.classpath property. Be sure to call
1791# java-ant_rewrite-classpath in src_unpack.
1792# JAVA_PKG_NO_BUNDLED_SEARCH - Don't search for bundled jars or class files
1793# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1224# ------------------------------------------------------------------------------ 1794# ------------------------------------------------------------------------------
1225eant() { 1795eant() {
1226 debug-print-function ${FUNCNAME} $* 1796 debug-print-function ${FUNCNAME} $*
1227 1797
1228 # FIXME get this working 1798 if [[ ${EBUILD_PHASE} = compile ]]; then
1229# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then 1799 # Used to be done in hooks in java-ant-2.eclass but moved here so that we can
1800 # finally get rid of the hooks without breaking stuff
1801
1802 [[ "${JAVA_ANT_IGNORE_SYSTEM_CLASSES}" && "${JAVA_PKG_BSFIX}" ]] \
1803 && java-ant_ignore-system-classes "${S}/build.xml"
1804
1805 if hasq java-ant-2 ${INHERITED}; then
1806 java-ant_bsfix
1807 fi
1808
1809 # eant can be called multiple times
1810 JAVA_PKG_BSFIX="off"
1811
1812 if [[ -z ${JAVA_PKG_NO_BUNDLED_SEARCH} ]] && is-java-strict; then
1813 echo "Searching for bundled jars:"
1814 java-pkg_find-normal-jars || echo "None found."
1815 echo "Searching for bundled classes (no output if none found):"
1816 find "${WORKDIR}" -name "*.class"
1817 echo "Search done."
1818 JAVA_PKG_NO_BUNDLED_SEARCH=true # eant can be called many times
1819 fi
1820 fi
1821
1822 if ! hasq java-ant-2 ${INHERITED}; then
1823 local msg="You should inherit java-ant-2 when using eant"
1230# java-pkg_announce-qa-violation \ 1824 java-pkg_announce-qa-violation "${msg}"
1231# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1232# fi 1825 fi
1233 1826
1234 local antflags 1827 local antflags="-Dnoget=true -Dmaven.mode.offline=true"
1828
1235 java-pkg_init-compiler_ 1829 java-pkg_init-compiler_
1236 local compiler="${GENTOO_COMPILER}" 1830 local compiler="${GENTOO_COMPILER}"
1237 1831
1238 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1832 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1239
1240 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})" 1833 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})"
1241 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1834 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1242 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1835 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1243 fi 1836 fi
1244 1837
1245 if [[ ${compiler} != "javac" ]]; then 1838 if [[ ${compiler} != "javac" ]]; then
1246 antflags="-Dbuild.compiler=${build_compiler}" 1839 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1247 # Figure out any extra stuff to put on the classpath for compilers aside 1840 # Figure out any extra stuff to put on the classpath for compilers aside
1248 # from javac 1841 # from javac
1249 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to 1842 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1250 # java-config -p 1843 # java-config -p
1251 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1844 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})"
1256 1849
1257 if is-java-strict; then 1850 if is-java-strict; then
1258 einfo "Disabling system classpath for ant" 1851 einfo "Disabling system classpath for ant"
1259 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1852 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1260 fi 1853 fi
1261 1854
1262 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1855 for arg in "${@}"; do
1263 antflags="${antflags} -debug" 1856 if [[ ${arg} = -lib ]]; then
1857 if is-java-strict; then
1858 eerror "You should not use the -lib argument to eant because it will fail"
1859 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1860 eerror "or ant properties to make dependencies available."
1861 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1862 eerror "split ant (>=dev-java/ant-core-1.7)."
1863 die "eant -lib is deprecated/forbidden"
1864 else
1865 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1866 echo "more info."
1867 fi
1264 fi 1868 fi
1265 1869 done
1870
1871 # we use this in src_* so we run ant from /
1872 if ROOT=/ has_version ">=dev-java/ant-core-1.7.0"; then
1873 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1874 ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}"
1875
1876 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1877 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1878
1879 if is-java-strict; then
1880 # if ant-tasks were not set by ebuild or forced, try to determine them from depends
1881 if [[ -z "${ANT_TASKS}" ]]; then
1882 ANT_TASKS="$(java-pkg_ant-tasks-from-deps)"
1883 fi
1884 else
1885 # if ant-tasks is not set by ebuild or forced, activate all of them
1886 ANT_TASKS="${ANT_TASKS:-all}"
1887 fi
1888
1889 # at this point, ANT_TASKS should be "all", "none" or explicit list
1890 if [[ "${ANT_TASKS}" == "all" ]]; then
1891 einfo "Using all available ANT_TASKS"
1892 elif [[ "${ANT_TASKS}" == "none" ]]; then
1893 einfo "Disabling all optional ANT_TASKS"
1894 else
1895 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1896 fi
1897
1898 export ANT_TASKS
1899 fi
1900
1901 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1902 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1903
1904 local gcp="${EANT_GENTOO_CLASSPATH}"
1905 local getjarsarg=""
1906
1907 if [[ ${EBUILD_PHASE} = "test" ]]; then
1908 antflags="${antflags} -DJunit.present=true"
1909 [[ ${gcp} && ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1910 getjarsarg="--with-dependencies"
1911 fi
1912
1913 local cp
1914
1915 for atom in ${gcp}; do
1916 cp="${cp}:$(java-pkg_getjars ${getjarsarg} ${atom})"
1917 done
1918
1919 if [[ ${cp} ]]; then
1920 # It seems ant does not like single quotes around ${cp}
1921 antflags="${antflags} -Dgentoo.classpath=\"${cp#:}\""
1922 fi
1923
1266 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1924 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1925 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
1267 ant ${antflags} "${@}" || die "eant failed" 1926 ant ${antflags} "${@}" || die "eant failed"
1268
1269} 1927}
1270 1928
1271# ------------------------------------------------------------------------------ 1929# ------------------------------------------------------------------------------
1272# @ebuild-function ejavac 1930# @ebuild-function ejavac
1273# 1931#
1274# Javac wrapper function. Will use the appropriate compiler, based on 1932# Javac wrapper function. Will use the appropriate compiler, based on
1275# /etc/java-config/compilers.conf 1933# /etc/java-config/compilers.conf
1276# 1934#
1277# @param $@ - Arguments to be passed to the compiler 1935# @param $@ - Arguments to be passed to the compiler
1278# ------------------------------------------------------------------------------ 1936# ------------------------------------------------------------------------------
1279ejavac() { 1937ejavac() {
1280 debug-print-function ${FUNCNAME} $* 1938 debug-print-function ${FUNCNAME} $*
1281 1939
1282 # FIXME using get-javac ends up printing stuff with einfo 1940 java-pkg_init-compiler_
1941
1942 local compiler_executable
1283# local compiler_executable=$(java-pkg_get-javac) 1943 compiler_executable=$(java-pkg_get-javac)
1284 local compiler_executable="javac" 1944 if [[ ${?} != 0 ]]; then
1945 eerror "There was a problem determining compiler: ${compiler_executable}"
1946 die "get-javac failed"
1947 fi
1285 1948
1949 local javac_args
1950 javac_args="$(java-pkg_javac-args)"
1951 if [[ ${?} != 0 ]]; then
1952 eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
1953 die "java-pkg_javac-args failed"
1954 fi
1955
1286 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 1956 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1287 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 1957 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1288} 1958}
1289 1959
1290# ------------------------------------------------------------------------------ 1960# ------------------------------------------------------------------------------
1291# @ebuild-function java-pkg_filter-compiler 1961# @ebuild-function java-pkg_filter-compiler
1292# 1962#
1293# Used to prevent the use of some compilers. Should be used in src_compile. 1963# Used to prevent the use of some compilers. Should be used in src_compile.
1294# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER 1964# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
1295# 1965#
1296# @param $@ - compilers to filter 1966# @param $@ - compilers to filter
1297# ------------------------------------------------------------------------------ 1967# ------------------------------------------------------------------------------
1315# ------------------------------------------------------------------------------ 1985# ------------------------------------------------------------------------------
1316# @ebuild-function use_doc 1986# @ebuild-function use_doc
1317# 1987#
1318# Helper function for getting ant to build javadocs. If the user has USE=doc, 1988# Helper function for getting ant to build javadocs. If the user has USE=doc,
1319# then 'javadoc' or the argument are returned. Otherwise, there is no return. 1989# then 'javadoc' or the argument are returned. Otherwise, there is no return.
1320# 1990#
1321# The output of this should be passed to ant. 1991# The output of this should be passed to ant.
1322# 1992#
1323# Example: build javadocs by calling 'javadoc' target 1993# Example: build javadocs by calling 'javadoc' target
1324# eant $(use_doc) 1994# eant $(use_doc)
1325# Example: build javadocs by calling 'apidoc' target 1995# Example: build javadocs by calling 'apidoc' target
1330# ------------------------------------------------------------------------------ 2000# ------------------------------------------------------------------------------
1331use_doc() { 2001use_doc() {
1332 use doc && echo ${@:-javadoc} 2002 use doc && echo ${@:-javadoc}
1333} 2003}
1334 2004
2005
1335# ------------------------------------------------------------------------------ 2006# ------------------------------------------------------------------------------
1336# @section-end build 2007# @section-end build
1337# ------------------------------------------------------------------------------ 2008# ------------------------------------------------------------------------------
1338 2009
1339# ------------------------------------------------------------------------------ 2010# ------------------------------------------------------------------------------
1340# @section-begin internal 2011# @section-begin internal
1341# @section-summary Internal functions 2012# @section-summary Internal functions
1342# 2013#
1343# Do __NOT__ use any of these from an ebuild! These are only to be used from 2014# Do __NOT__ use any of these from an ebuild! These are only to be used from
1344# within the java eclasses. 2015# within the java eclasses.
1345# ------------------------------------------------------------------------------ 2016# ------------------------------------------------------------------------------
1346 2017
1347# ----------------------------------------------------------------------------- 2018# -----------------------------------------------------------------------------
1348# @function-internal java-pkg_init 2019# @function-internal java-pkg_init
1349# 2020#
1350# The purpose of this function, as the name might imply, is to initialize the 2021# The purpose of this function, as the name might imply, is to initialize the
1351# Java environment. It ensures that that there aren't any environment variables 2022# Java environment. It ensures that that there aren't any environment variables
1352# that'll muss things up. It initializes some variables, which are used 2023# that'll muss things up. It initializes some variables, which are used
1353# internally. And most importantly, it'll switch the VM if necessary. 2024# internally. And most importantly, it'll switch the VM if necessary.
1354# 2025#
1357# 2028#
1358# ----------------------------------------------------------------------------- 2029# -----------------------------------------------------------------------------
1359java-pkg_init() { 2030java-pkg_init() {
1360 unset JAVAC 2031 unset JAVAC
1361 unset JAVA_HOME 2032 unset JAVA_HOME
2033
2034 # People do all kinds of weird things.
2035 # http://forums.gentoo.org/viewtopic-p-3943166.html
2036 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
2037 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
2038 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
2039 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
2040 ewarn "sun-jdk vms and and as such break configure scripts that"
2041 ewarn "use it (for example app-office/openoffice) so we filter it out."
2042 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
2043 ewarn "make.conf for example) to silence this warning or"
2044 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
2045 fi
2046
2047 if [[ -z ${accept} ]]; then
2048 unset _JAVA_OPTIONS
2049 # phase hooks make this run many times without this
2050 I_WANT_GLOBAL_JAVA_OPTIONS="true"
2051 fi
2052
2053 if java-pkg_func-exists ant_src_unpack; then
2054 java-pkg_announce-qa-violation "Using old ant_src_unpack. Should be src_unpack"
2055 fi
2056
1362 java-pkg_init_paths_ 2057 java-pkg_init_paths_
1363 java-pkg_switch-vm 2058 java-pkg_switch-vm
1364 PATH=${JAVA_HOME}/bin:${PATH} 2059 PATH=${JAVA_HOME}/bin:${PATH}
1365 2060
1366 # TODO we will probably want to set JAVAC and JAVACFLAGS 2061 # TODO we will probably want to set JAVAC and JAVACFLAGS
1367 2062
1368 # Do some QA checks 2063 # Do some QA checks
1369 java-pkg_check-jikes 2064 java-pkg_check-jikes
1370 2065
1371 # When users have crazy classpaths some packages can fail to compile. 2066 # When users have crazy classpaths some packages can fail to compile.
1372 # and everything should work with empty CLASSPATH. 2067 # and everything should work with empty CLASSPATH.
1373 # This also helps prevent unexpected dependencies on random things 2068 # This also helps prevent unexpected dependencies on random things
1374 # from the CLASSPATH. 2069 # from the CLASSPATH.
1375 unset CLASSPATH 2070 unset CLASSPATH
2071
2072 # Unset external ANT_ stuff
2073 unset ANT_TASKS
2074 unset ANT_OPTS
1376} 2075}
1377 2076
1378# ------------------------------------------------------------------------------ 2077# ------------------------------------------------------------------------------
1379# @function-internal java-pkg-init-compiler_ 2078# @function-internal java-pkg-init-compiler_
1380# 2079#
1381# This function attempts to figure out what compiler should be used. It does 2080# This function attempts to figure out what compiler should be used. It does
1382# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the 2081# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
1383# COMPILERS variable defined there. 2082# COMPILERS variable defined there.
1384# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER 2083# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
1385# 2084#
1386# It will go through the list of compilers, and verify that it supports the 2085# It will go through the list of compilers, and verify that it supports the
1387# target and source that are needed. If it is not suitable, then the next 2086# target and source that are needed. If it is not suitable, then the next
1388# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking 2087# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
1389# isn't done. 2088# isn't done.
1390# 2089#
1412 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 2111 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1413 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})" 2112 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
1414 else 2113 else
1415 compilers=${JAVA_PKG_FORCE_COMPILER} 2114 compilers=${JAVA_PKG_FORCE_COMPILER}
1416 fi 2115 fi
1417 2116
1418 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}" 2117 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
1419 2118
1420 # Figure out if we should announce what compiler we're using 2119 # Figure out if we should announce what compiler we're using
1421 local compiler 2120 local compiler
1422 for compiler in ${compilers}; do 2121 for compiler in ${compilers}; do
1425 if [[ ${compiler} = "javac" ]]; then 2124 if [[ ${compiler} = "javac" ]]; then
1426 debug-print "Found javac... breaking" 2125 debug-print "Found javac... breaking"
1427 export GENTOO_COMPILER="javac" 2126 export GENTOO_COMPILER="javac"
1428 break 2127 break
1429 fi 2128 fi
1430 2129
1431 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then 2130 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
1432 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 2131 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1433 einfo "Filtering ${compiler}" 2132 einfo "Filtering ${compiler}"
1434 continue 2133 continue
1435 fi 2134 fi
1436 fi 2135 fi
1437 2136
1438 # for non-javac, we need to make sure it supports the right target and 2137 # for non-javac, we need to make sure it supports the right target and
1439 # source 2138 # source
1440 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 2139 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1441 if [[ -f ${compiler_env} ]]; then 2140 if [[ -f ${compiler_env} ]]; then
1442 local desired_target="$(java-pkg_get-target)" 2141 local desired_target="$(java-pkg_get-target)"
1524# Writes the package.env out to disk. 2223# Writes the package.env out to disk.
1525# 2224#
1526# ------------------------------------------------------------------------------ 2225# ------------------------------------------------------------------------------
1527# TODO change to do-write, to match everything else 2226# TODO change to do-write, to match everything else
1528java-pkg_do_write_() { 2227java-pkg_do_write_() {
2228 debug-print-function ${FUNCNAME} $*
2229 java-pkg_init_paths_
1529 # Create directory for package.env 2230 # Create directory for package.env
1530 dodir "${JAVA_PKG_SHAREPATH}" 2231 dodir "${JAVA_PKG_SHAREPATH}"
1531 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 2232 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f \
2233 "${JAVA_PKG_DEPEND_FILE}" || -f \
2234 "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]]; then
1532 # Create package.env 2235 # Create package.env
1533 ( 2236 (
1534 echo "DESCRIPTION=\"${DESCRIPTION}\"" 2237 echo "DESCRIPTION=\"${DESCRIPTION}\""
1535 echo "GENERATION=\"2\"" 2238 echo "GENERATION=\"2\""
1536 2239
1537 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\"" 2240 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
1538 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 2241 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1539 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 2242 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1540 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 2243 [[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
2244 && echo "DEPEND=\"$(cat "${JAVA_PKG_DEPEND_FILE}" | uniq | tr '\n' ':')\""
2245 [[ -f "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]] \
2246 && echo "OPTIONAL_DEPEND=\"$(cat "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" | uniq | tr '\n' ':')\""
1541 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 2247 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1542 ) > "${JAVA_PKG_ENV}" 2248 ) > "${JAVA_PKG_ENV}"
1543 2249
1544 # register target/source 2250 # register target/source
1545 local target="$(java-pkg_get-target)" 2251 local target="$(java-pkg_get-target)"
1546 local source="$(java-pkg_get-source)" 2252 local source="$(java-pkg_get-source)"
1547 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}" 2253 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
1548 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}" 2254 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
1556 2262
1557 2263
1558 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}" 2264 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
1559 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}" 2265 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
1560 2266
2267 # extra env variables
2268 if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
2269 cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}" || die
2270 # nested echo to remove leading/trailing spaces
2271 echo "ENV_VARS=\"$(echo ${JAVA_PKG_EXTRA_ENV_VARS})\"" \
2272 >> "${JAVA_PKG_ENV}" || die
2273 fi
2274
1561 # Strip unnecessary leading and trailing colons 2275 # Strip unnecessary leading and trailing colons
1562 # TODO try to cleanup if possible 2276 # TODO try to cleanup if possible
1563 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 2277 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
2278 else
2279 debug-print "JAVA_PKG_CLASSPATH, JAVA_PKG_LIBRARY, JAVA_PKG_DEPEND_FILE"
2280 debug-print "or JAVA_PKG_OPTIONAL_DEPEND_FILE not defined so can't"
2281 debug-print "write package.env."
1564 fi 2282 fi
1565} 2283}
1566
1567 2284
1568# ------------------------------------------------------------------------------ 2285# ------------------------------------------------------------------------------
1569# @internal-function java-pkg_record-jar_ 2286# @internal-function java-pkg_record-jar_
1570# 2287#
1571# Record a dependency to the package.env 2288# Record an (optional) dependency to the package.env
1572# 2289# @param --optional - record dependency as optional
2290# @param $1 - package to record
2291# @param $2 - (optional) jar of package to record
1573# ------------------------------------------------------------------------------ 2292# ------------------------------------------------------------------------------
1574JAVA_PKG_DEPEND="${T}/java-pkg-depend" 2293JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2294JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
1575 2295
1576java-pkg_record-jar_() { 2296java-pkg_record-jar_() {
1577 debug-print-function ${FUNCNAME} $* 2297 debug-print-function ${FUNCNAME} $*
2298
2299 local depend_file="${JAVA_PKG_DEPEND_FILE}"
2300 if [[ "${1}" == "--optional" ]]; then
2301 depend_file="${JAVA_PKG_OPTIONAL_DEPEND_FILE}"
2302 shift
2303 fi
1578 2304
1579 local pkg=${1} jar=${2} append 2305 local pkg=${1} jar=${2} append
1580 if [[ -z "${jar}" ]]; then 2306 if [[ -z "${jar}" ]]; then
1581 append="${pkg}" 2307 append="${pkg}"
1582 else 2308 else
1583 append="$(basename ${jar})@${pkg}" 2309 append="$(basename ${jar})@${pkg}"
1584 fi 2310 fi
1585 2311
1586 echo ${append} >> ${JAVA_PKG_DEPEND} 2312 echo "${append}" >> "${depend_file}"
1587} 2313}
1588 2314
1589# ------------------------------------------------------------------------------ 2315# ------------------------------------------------------------------------------
1590# @internal-function java-pkg_append_ 2316# @internal-function java-pkg_append_
1591# 2317#
1615 fi 2341 fi
1616} 2342}
1617 2343
1618# ------------------------------------------------------------------------------ 2344# ------------------------------------------------------------------------------
1619# @internal-function java-pkg_expand_dir_ 2345# @internal-function java-pkg_expand_dir_
1620# 2346#
1621# Gets the full path of the file/directory's parent. 2347# Gets the full path of the file/directory's parent.
1622# @param $1 - file/directory to find parent directory for 2348# @param $1 - file/directory to find parent directory for
1623# @return - path to $1's parent directory 2349# @return - path to $1's parent directory
1624# ------------------------------------------------------------------------------ 2350# ------------------------------------------------------------------------------
1625java-pkg_expand_dir_() { 2351java-pkg_expand_dir_() {
1651# 2377#
1652# ------------------------------------------------------------------------------ 2378# ------------------------------------------------------------------------------
1653java-pkg_setup-vm() { 2379java-pkg_setup-vm() {
1654 debug-print-function ${FUNCNAME} $* 2380 debug-print-function ${FUNCNAME} $*
1655 2381
2382 export LANG="C" LC_ALL="C"
2383
1656 local vendor="$(java-pkg_get-vm-vendor)" 2384 local vendor="$(java-pkg_get-vm-vendor)"
1657 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge 1 5; then 2385 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1658 addpredict "/dev/random" 2386 addpredict "/dev/random"
1659 elif [[ "${vendor}" == "ibm" ]]; then 2387 elif [[ "${vendor}" == "ibm" ]]; then
1660 addpredict "/proc/self/maps" 2388 addpredict "/proc/self/maps"
1661 addpredict "/proc/cpuinfo" 2389 addpredict "/proc/cpuinfo"
1662 export LANG="C" LC_ALL="C"
1663 elif [[ "${vendor}" == "jrockit" ]]; then 2390 elif [[ "${vendor}" == "jrockit" ]]; then
1664 addpredict "/proc/cpuinfo" 2391 addpredict "/proc/cpuinfo"
1665 fi 2392 fi
1666} 2393}
1667 2394
1711# @return - The version of the current VM 2438# @return - The version of the current VM
1712# ------------------------------------------------------------------------------ 2439# ------------------------------------------------------------------------------
1713java-pkg_get-vm-version() { 2440java-pkg_get-vm-version() {
1714 debug-print-function ${FUNCNAME} $* 2441 debug-print-function ${FUNCNAME} $*
1715 2442
1716 java-pkg_get-current-vm | sed -e "s/.*-\([0-9.]\+\).*/\1/" 2443 java-config -g PROVIDES_VERSION
1717} 2444}
1718 2445
1719# ------------------------------------------------------------------------------ 2446# ------------------------------------------------------------------------------
1720# @internal-function java-pkg_switch-vm 2447# @internal-function java-pkg_switch-vm
1721# 2448#
1722# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 2449# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1723# verify that the current VM is sufficient. 2450# verify that the current VM is sufficient.
1724# Setup the environment for the VM being used. 2451# Setup the environment for the VM being used.
1725# ------------------------------------------------------------------------------ 2452# ------------------------------------------------------------------------------
1726java-pkg_switch-vm() { 2453java-pkg_switch-vm() {
2454 debug-print-function ${FUNCNAME} $*
2455
1727 if java-pkg_needs-vm; then 2456 if java-pkg_needs-vm; then
1728 # Use the VM specified by JAVA_PKG_FORCE_VM 2457 # Use the VM specified by JAVA_PKG_FORCE_VM
1729 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then 2458 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1730 # If you're forcing the VM, I hope you know what your doing... 2459 # If you're forcing the VM, I hope you know what your doing...
2460 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1731 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 2461 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1732 # if we're allowed to switch the vm... 2462 # if we're allowed to switch the vm...
1733 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 2463 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1734 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}" 2464 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1735 if [[ -n ${JAVA_PKG_VNEED} ]]; then 2465 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1736 export GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2466 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1737 else 2467 else
1738 export GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2468 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
2469 fi
2470 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
2471 eerror "Unable to determine VM for building from dependencies:"
2472 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
2473 echo "VNEED: ${JAVA_PKG_VNEED}"
2474 die "Failed to determine VM for building."
2475 else
2476 export GENTOO_VM
1739 fi 2477 fi
1740 # otherwise just make sure the current VM is sufficient 2478 # otherwise just make sure the current VM is sufficient
1741 else 2479 else
1742 java-pkg_ensure-vm-version-sufficient 2480 java-pkg_ensure-vm-version-sufficient
1743 fi 2481 fi
1744 debug-print "Using: $(java-config -f)" 2482 debug-print "Using: $(java-config -f)"
1745 2483
1746 java-pkg_setup-vm 2484 java-pkg_setup-vm
1747 2485
1748 export JAVA=$(java-config --java) 2486 export JAVA=$(java-config --java)
1749 export JAVAC=$(java-config --javac) 2487 export JAVAC=$(java-config --javac)
1750 export JAVACFLAGS="$(java-pkg_javac-args)" 2488 JAVACFLAGS="$(java-pkg_javac-args)"
2489 if [[ ${?} != 0 ]]; then
2490 eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
2491 die "java-pkg_javac-args failed"
2492 fi
1751 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 2493 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
2494 export JAVACFLAGS
1752 2495
1753 export JAVA_HOME="$(java-config -g JAVA_HOME)" 2496 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1754 export JDK_HOME=${JAVA_HOME} 2497 export JDK_HOME=${JAVA_HOME}
1755 2498
1756 #TODO If you know a better solution let us know. 2499 #TODO If you know a better solution let us know.
1757 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 2500 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1758 2501
1759 local tann="${T}/announced-vm" 2502 local tann="${T}/announced-vm"
2503 # With the hooks we should only get here once from pkg_setup but better safe than sorry
2504 # if people have for example modified eclasses some where
1760 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 2505 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1761 # Add a check for setup/preinst phase... to avoid duplicate outputs
1762 # for when FEATURES=buildpkg
1763 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1764 then
1765 einfo "Using: $(java-config -f)" 2506 einfo "Using: $(java-config -f)"
1766 [[ ! -f "${tann}" ]] && touch "${tann}" 2507 [[ ! -f "${tann}" ]] && touch "${tann}"
1767 fi
1768 fi 2508 fi
1769 2509
1770 else 2510 else
1771 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!" 2511 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!"
1772 fi 2512 fi
1802 einfo "Classes" 2542 einfo "Classes"
1803 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR}," 2543 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1804 fi 2544 fi
1805} 2545}
1806 2546
1807# TODO document 2547# ------------------------------------------------------------------------------
2548# @internal-function java-pkg_verify-classes
2549#
1808# Verify that the classes were compiled for the right source / target 2550# Verify that the classes were compiled for the right source / target. Dies if
2551# not.
2552# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2553# ------------------------------------------------------------------------------
1809java-pkg_verify-classes() { 2554java-pkg_verify-classes() {
1810 ebegin "Verifying java class versions"
1811 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 2555 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1812 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 2556 local target=$(java-pkg_get-target)
2557 local result
2558 local log="${T}/class-version-verify.log"
2559 if [[ -n "${1}" ]]; then
2560 class-version-verify.py -v -t ${target} "${1}" > "${log}"
1813 result=$? 2561 result=$?
1814 eend ${result}
1815 if [[ ${result} == 0 ]]; then
1816 einfo "All good"
1817 else 2562 else
1818 ewarn "Possible problem" 2563 ebegin "Verifying java class versions (target: ${target})"
1819 die "Bad class files found" 2564 class-version-verify.py -v -t ${target} -r "${D}" > "${log}"
2565 result=$?
2566 eend ${result}
2567 fi
2568 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2569 if [[ ${result} != 0 ]]; then
2570 eerror "Incorrect bytecode version found"
2571 [[ -n "${1}" ]] && eerror "in file: ${1}"
2572 eerror "See ${log} for more details."
2573 die "Incorrect bytecode found"
2574 fi
2575}
2576
2577# ----------------------------------------------------------------------------
2578# @internal-function java-pkg_ensure-dep
2579# Check that a package being used in jarfrom, getjars and getjar is contained
2580# within DEPEND or RDEPEND.
2581# @param $1 - empty - check both vars; "runtime" or "build" - check only
2582# RDEPEND, resp. DEPEND
2583# @param $2 - Package name and slot.
2584
2585java-pkg_ensure-dep() {
2586 debug-print-function ${FUNCNAME} $*
2587
2588 local limit_to="${1}"
2589 local target_pkg="${2}"
2590 local dev_error=""
2591
2592 local stripped_pkg=$(echo "${target_pkg}" | sed \
2593 's/-[0-9]*\(\.[0-9]\)*$//')
2594
2595 debug-print "Matching against: ${stripped_pkg}"
2596
2597 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2598 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2599 dev_error="${dev_error} declared in DEPEND."
2600 if is-java-strict; then
2601 eerror "${dev_error}"
2602 die "${dev_error}"
2603 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2604 eerror "${dev_error}"
2605 elog "Because you have this package installed the package will"
2606 elog "build without problems, but please report this to"
2607 elog "http://bugs.gentoo.org"
1820 fi 2608 fi
1821} 2609 fi
1822 2610
2611 if [[ ${limit_to} != build ]]; then
2612 if [[ ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2613 if [[ ! ( ${PDEPEND} =~ "${stripped_pkg}" ) ]]; then
2614 dev_error="The ebuild is attempting to use ${target_pkg},"
2615 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND"
2616 dev_error="${dev_error} or PDEPEND."
2617 if is-java-strict; then
2618 eerror "${dev_error}"
2619 die "${dev_error}"
2620 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2621 eerror "${dev_error}"
2622 elog "The package will build without problems, but may fail to run"
2623 elog "if you don't have ${target_pkg} installed, so please report"
2624 elog "this to http://bugs.gentoo.org"
2625 fi
2626 fi
2627 fi
2628 fi
2629}
1823 2630
1824# ------------------------------------------------------------------------------ 2631# ------------------------------------------------------------------------------
1825# @section-end internal 2632# @section-end internal
1826# ------------------------------------------------------------------------------ 2633# ------------------------------------------------------------------------------
1827 2634
1828java-pkg_check-phase() { 2635java-pkg_check-phase() {
1829 local phase=${1} 2636 local phase=${1}
1830 local funcname=${2} 2637 local funcname=${FUNCNAME[1]}
1831 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then 2638 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
1832 java-pkg_announce-qa-violation \
1833 "${funcname} used outside of src_${phase}" 2639 local msg="${funcname} used outside of src_${phase}"
2640 java-pkg_announce-qa-violation "${msg}"
1834 fi 2641 fi
1835} 2642}
1836 2643
1837java-pkg_check-versioned-jar() { 2644java-pkg_check-versioned-jar() {
1838 local jar=${1} 2645 local jar=${1}
1847 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2654 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1848 fi 2655 fi
1849} 2656}
1850 2657
1851java-pkg_announce-qa-violation() { 2658java-pkg_announce-qa-violation() {
1852 if is-java-strict; then 2659 local nodie
2660 if [[ ${1} == "--nodie" ]]; then
2661 nodie="true"
2662 shift
2663 fi
1853 echo "Java QA Notice: $@" >&2 2664 echo "Java QA Notice: $@" >&2
1854 increment-qa-violations 2665 increment-qa-violations
1855 fi 2666 [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
1856} 2667}
1857 2668
1858increment-qa-violations() { 2669increment-qa-violations() {
1859 let "JAVA_PKG_QA_VIOLATIONS+=1" 2670 let "JAVA_PKG_QA_VIOLATIONS+=1"
1860 export JAVA_PKG_QA_VIOLATIONS 2671 export JAVA_PKG_QA_VIOLATIONS
1861} 2672}
1862 2673
1863is-java-strict() { 2674is-java-strict() {
1864 hasq java-strict ${FEATURES} && ! hasq -java-strict ${FEATURES} 2675 [[ -n ${JAVA_PKG_STRICT} ]]
1865 return $? 2676 return $?
1866} 2677}
1867 2678
1868# ------------------------------------------------------------------------------ 2679# ------------------------------------------------------------------------------
1869# @eclass-end 2680# @eclass-end

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.93

  ViewVC Help
Powered by ViewVC 1.1.20