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

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

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

Revision 1.3 Revision 1.68
4# Copyright (c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org> 4# Copyright (c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
5# Copyright (c) 2004-2005, Gentoo Foundation 5# Copyright (c) 2004-2005, Gentoo Foundation
6# 6#
7# Licensed under the GNU General Public License, v2 7# Licensed under the GNU General Public License, v2
8# 8#
9# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.68 2007/03/25 10:02:09 betelgeuse Exp $
9 10
10 11
11# ----------------------------------------------------------------------------- 12# -----------------------------------------------------------------------------
12# @eclass-begin 13# @eclass-begin
13# @eclass-shortdesc Java Utility eclass 14# @eclass-shortdesc Java Utility eclass
14# @eclass-maintainer java@gentoo.org 15# @eclass-maintainer java@gentoo.org
15# 16#
16# This eclass provides functionality which is used by 17# This eclass provides functionality which is used by
17# java-pkg.eclass and java-pkg-opt.eclass as well as from ebuilds. 18# java-pkg.eclass and java-pkg-opt.eclass as well as from ebuilds.
18# 19#
19# @warning 20# @warning
20# You probably don't want to inherit this directly from an ebuild. Instead, 21# You probably don't want to inherit this directly from an ebuild. Instead,
21# you should inherit java-ant for Ant-based Java packages, java-pkg for other 22# you should inherit java-ant for Ant-based Java packages, java-pkg for other
22# Java packages, or java-pkg-opt for packages that have optional Java support. 23# Java packages, or java-pkg-opt for packages that have optional Java support.
23# 24#
24# ----------------------------------------------------------------------------- 25# -----------------------------------------------------------------------------
25 26
26inherit eutils versionator multilib 27inherit eutils versionator multilib
28
29IUSE="elibc_FreeBSD"
27 30
28# ----------------------------------------------------------------------------- 31# -----------------------------------------------------------------------------
29# @section-begin variables 32# @section-begin variables
30# @section-title Variables 33# @section-title Variables
31# 34#
34 37
35# Make sure we use java-config-2 38# Make sure we use java-config-2
36export WANT_JAVA_CONFIG="2" 39export WANT_JAVA_CONFIG="2"
37 40
38# ----------------------------------------------------------------------------- 41# -----------------------------------------------------------------------------
42# @variable-external WANT_ANT_TASKS
43# @variable-default ""
44#
45# An $IFS separated list of ant tasks.
46# Ebuild can specify this variable before inheriting java-ant-2 eclass to
47# determine ANT_TASKS it needs. They will be automatically translated to
48# DEPEND variable and ANT_TASKS variable. JAVA_PKG_FORCE_ANT_TASKS can override
49# ANT_TASKS set by WANT_ANT_TASKS, but not the DEPEND due to caching.
50# Ebuilds that need to depend conditionally on certain tasks and specify them
51# differently for different eant calls can't use this simplified approach.
52# You also cannot specify version or anything else than ant-*.
53#
54# @example WANT_ANT_TASKS="ant-junit ant-trax"
55#
56# @seealso JAVA_PKG_FORCE_ANT_TASKS
57# -----------------------------------------------------------------------------
58#WANT_ANT_TASKS
59
60# -----------------------------------------------------------------------------
61# @variable-internal JAVA_PKG_PORTAGE_DEP
62#
63# The version of portage we need to function properly. At this moment it's
64# portage with phase hooks support.
65# -----------------------------------------------------------------------------
66JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1"
67
68# -----------------------------------------------------------------------------
39# @variable-internal JAVA_PKG_E_DEPEND 69# @variable-internal JAVA_PKG_E_DEPEND
40# 70#
41# 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
42# 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. We also need a recent version
43# portage, that includes phase hooks. 73# portage, that includes phase hooks.
44# ----------------------------------------------------------------------------- 74# -----------------------------------------------------------------------------
45JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 >=sys-apps/portage-2.1_pre1" 75JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.31 ${JAVA_PKG_PORTAGE_DEP}"
46 76
47# ----------------------------------------------------------------------------- 77# -----------------------------------------------------------------------------
48# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 78# @variable-external JAVA_PKG_ALLOW_VM_CHANGE
49# @variable-default yes 79# @variable-default yes
50# 80#
97# ----------------------------------------------------------------------------- 127# -----------------------------------------------------------------------------
98 128
99# ----------------------------------------------------------------------------- 129# -----------------------------------------------------------------------------
100# @variable-internal JAVA_PKG_COMPILER_DIR 130# @variable-internal JAVA_PKG_COMPILER_DIR
101# @default /usr/share/java-config-2/compiler 131# @default /usr/share/java-config-2/compiler
102# 132#
103# Directory where compiler settings are saved, without trailing slash. 133# Directory where compiler settings are saved, without trailing slash.
104# Probably shouldn't touch this variable. 134# Probably shouldn't touch this variable.
105# ----------------------------------------------------------------------------- 135# -----------------------------------------------------------------------------
106JAVA_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"}
107 137
117 147
118# ----------------------------------------------------------------------------- 148# -----------------------------------------------------------------------------
119# @variable-external JAVA_PKG_FORCE_COMPILER 149# @variable-external JAVA_PKG_FORCE_COMPILER
120# 150#
121# 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
122# JAVA_PKG_COMPILERS_CONF. 152# JAVA_PKG_COMPILERS_CONF.
123# 153#
124# @note This should only be used internally or for testing. 154# @note This should only be used internally or for testing.
125# @example Use jikes and javac, in that order 155# @example Use jikes and javac, in that order
126# JAVA_PKG_FORCE_COMPILER="jikes javac" 156# JAVA_PKG_FORCE_COMPILER="jikes javac"
127# ----------------------------------------------------------------------------- 157# -----------------------------------------------------------------------------
128 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
129# TODO document me 173# TODO document me
130JAVA_PKG_QA_VIOLATIONS=0 174JAVA_PKG_QA_VIOLATIONS=0
131 175
132# ----------------------------------------------------------------------------- 176# -----------------------------------------------------------------------------
133# @section-end variables 177# @section-end variables
140# 184#
141# 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
142# libraries, etc. 186# libraries, etc.
143# ----------------------------------------------------------------------------- 187# -----------------------------------------------------------------------------
144 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 $* - list of files to install
201# ------------------------------------------------------------------------------
202java-pkg_doexamples() {
203 debug-print-function ${FUNCNAME} $*
204
205 [[ ${#} -lt 1 ]] && die "At least one argument needed"
206
207 java-pkg_check-phase install
208
209 local dest=/usr/share/doc/${PF}/examples
210 if [[ ${#} = 1 && -d ${1} ]]; then
211 INSDESTTREE="${dest}" doins -r ${1}/* || die "Installing examples failed"
212 else
213 INSDESTTREE="${dest}" doins -r "${@}" || die "Installing examples failed"
214 fi
215}
145 216
146# ----------------------------------------------------------------------------- 217# -----------------------------------------------------------------------------
147# @ebuild-function java-pkg_dojar 218# @ebuild-function java-pkg_dojar
148# 219#
149# Installs any number of jars. 220# Installs any number of jars.
150# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default. 221# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default.
151# You can use java-pkg_jarinto to change this path. 222# You can use java-pkg_jarinto to change this path.
152# You should never install a jar with a package version in the filename. 223# You should never install a jar with a package version in the filename.
153# Instead, use java-pkg_newjar defined below. 224# Instead, use java-pkg_newjar defined below.
154# 225#
155# @example 226# @example
156# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar 227# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar
157# 228#
168 # Create JARDEST if it doesn't exist 239 # Create JARDEST if it doesn't exist
169 dodir ${JAVA_PKG_JARDEST} 240 dodir ${JAVA_PKG_JARDEST}
170 241
171 local jar 242 local jar
172 # for each jar 243 # for each jar
173 for jar in "$@"; do 244 for jar in "${@}"; do
174 local jar_basename=$(basename "${jar}") 245 local jar_basename=$(basename "${jar}")
175 246
176 java-pkg_check-versioned-jar ${jar_basename} 247 java-pkg_check-versioned-jar ${jar_basename}
177 248
178 # check if it exists 249 # check if it exists
179 if [[ -e "${jar}" ]] ; then 250 if [[ -e "${jar}" ]] ; then
251 # Don't overwrite if jar has already been installed with the same
252 # name
253 local dest="${D}${JAVA_PKG_JARDEST}/${jar_basename}"
254 if [[ -e "${dest}" ]]; then
255 ewarn "Overwriting ${dest}"
256 fi
257
180 # install it into JARDEST if it's a non-symlink 258 # install it into JARDEST if it's a non-symlink
181 if [[ ! -L "${jar}" ]] ; then 259 if [[ ! -L "${jar}" ]] ; then
260 #but first check class version when in strict mode.
261 is-java-strict && java-pkg_verify-classes "${jar}"
262
182 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 263 INSDESTTREE="${JAVA_PKG_JARDEST}" \
183 doins "${jar}" || die "failed to install ${jar}" 264 doins "${jar}" || die "failed to install ${jar}"
184 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 265 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
185 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}" 266 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}"
186 # make a symlink to the original jar if it's symlink 267 # make a symlink to the original jar if it's symlink
197 278
198 java-pkg_do_write_ 279 java-pkg_do_write_
199} 280}
200 281
201 282
283# ------------------------------------------------------------------------------
284# @internal-function depend-java-query
285#
286# Wrapper for the depend-java-query binary to enable passing USE in env.
287# Using env variables keeps this eclass working with java-config versions that
288# do not handle use flags.
289# ------------------------------------------------------------------------------
290
291depend-java-query() {
292 # Used to have a which call here but it caused endless loops for some people
293 # that had some weird bashrc voodoo for which.
294 USE="${USE}" /usr/bin/depend-java-query "${@}"
295}
202 296
203# ------------------------------------------------------------------------------ 297# ------------------------------------------------------------------------------
204# @ebuild-function java-pkg_regjar 298# @ebuild-function java-pkg_regjar
205# 299#
206# Records an already installed jar in the package.env 300# Records an already installed jar in the package.env
207# This would mostly be used if the package has make or a custom script to 301# This would mostly be used if the package has make or a custom script to
208# install things. 302# install things.
209# 303#
210# Example: 304# Example:
211# java-pkg-regjar ${D}/opt/foo/lib/foo.jar 305# java-pkg_regjar ${D}/opt/foo/lib/foo.jar
306#
307# WARNING:
308# if you want to use shell expansion, you have to use ${D}/... as the for in
309# this function will not be able to expand the path, here's an example:
310#
311# java-pkg_regjar /opt/my-java/lib/*.jar
312#
313# will not work, because:
314# * the `for jar in "$@"` can't expand the path to jar file names, as they
315# don't exist yet
316# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar'
317# doesn't exist
318#
319# you have to use it as:
320#
321# java-pkg_regjar ${D}/opt/my-java/lib/*.jar
212# 322#
213# @param $@ - jars to record 323# @param $@ - jars to record
214# ------------------------------------------------------------------------------ 324# ------------------------------------------------------------------------------
215# TODO fix me! 325# TODO should we be making sure the jar is present on ${D} or wherever?
216java-pkg_regjar() { 326java-pkg_regjar() {
217 debug-print-function ${FUNCNAME} $* 327 debug-print-function ${FUNCNAME} $*
218 328
219 java-pkg_check-phase install 329 java-pkg_check-phase install
220 330
221 [[ ${#} -lt 1 ]] && die "at least one argument needed" 331 [[ ${#} -lt 1 ]] && die "at least one argument needed"
222 332
223 java-pkg_init_paths_ 333 java-pkg_init_paths_
224 334
225 local jar jar_dir jar_file 335 local jar jar_dir jar_file
226 for jar in "$@"; do 336 for jar in "${@}"; do
227 # TODO use java-pkg_check-versioned-jar 337 # TODO use java-pkg_check-versioned-jar
228 if [[ -e "${jar}" ]]; then
229 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar}"
230 elif [[ -e "${D}${jar}" ]]; then 338 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
339 [[ -d "${jar}" || -d "${D}${jar}" ]] \
340 && die "Called ${FUNCNAME} on a directory $*"
341
342 #check that class version correct when in strict mode
343 is-java-strict && java-pkg_verify-classes "${jar}"
344
345 # nelchael: we should strip ${D} in this case too, here's why:
346 # imagine such call:
347 # java-pkg_regjar ${D}/opt/java/*.jar
348 # such call will fall into this case (-e ${jar}) and will
349 # record paths with ${D} in package.env
231 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 350 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
232 else 351 else
352 if [[ ${jar} = *\** ]]; then
353 eerror "The argument ${jar} to ${FUNCNAME}"
354 eerror "has * in it. If you want it to glob in"
355 eerror '${D} add ${D} to the argument.'
356 fi
233 die "${jar} does not exist" 357 die "${jar} does not exist"
234 fi 358 fi
235 done 359 done
236 360
237 java-pkg_do_write_ 361 java-pkg_do_write_
238} 362}
239
240 363
241# ------------------------------------------------------------------------------ 364# ------------------------------------------------------------------------------
242# @ebuild-function java-pkg_newjar 365# @ebuild-function java-pkg_newjar
243# 366#
244# Installs a jar with a new name 367# Installs a jar with a new name
255 local original_jar="${1}" 378 local original_jar="${1}"
256 local new_jar="${2:-${PN}.jar}" 379 local new_jar="${2:-${PN}.jar}"
257 local new_jar_dest="${T}/${new_jar}" 380 local new_jar_dest="${T}/${new_jar}"
258 381
259 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 382 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
260 [[ ! -f ${original_jar} ]] && die "${new_jar} does not exist!" 383 [[ ! -f ${original_jar} ]] \
384 && die "${original_jar} does not exist or is not a file!"
261 385
262 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 386 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
263 cp "${original_jar}" "${new_jar_dest}" \ 387 cp "${original_jar}" "${new_jar_dest}" \
264 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 388 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
265 java-pkg_dojar "${new_jar_dest}" 389 java-pkg_dojar "${new_jar_dest}"
266} 390}
267 391
268
269# ------------------------------------------------------------------------------ 392# ------------------------------------------------------------------------------
270# @ebuild-function java-pkg_addcp 393# @ebuild-function java-pkg_addcp
271# 394#
272# Add something to the package's classpath. For jars, you should use dojar, 395# Add something to the package's classpath. For jars, you should use dojar,
273# newjar, or regjar. This is typically used to add directories to the classpath. 396# newjar, or regjar. This is typically used to add directories to the classpath.
278java-pkg_addcp() { 401java-pkg_addcp() {
279 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}" 402 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
280 java-pkg_do_write_ 403 java-pkg_do_write_
281} 404}
282 405
283
284# ------------------------------------------------------------------------------ 406# ------------------------------------------------------------------------------
285# @ebuild-function java-pkg_doso 407# @ebuild-function java-pkg_doso
286# 408#
287# Installs any number of JNI libraries 409# Installs any number of JNI libraries
288# They will be installed into /usr/lib by default, but java-pkg_sointo 410# They will be installed into /usr/lib by default, but java-pkg_sointo
289# can be used change this path 411# can be used change this path
290# 412#
291# Example: 413# Example:
316 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 438 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
317 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 439 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
318 # otherwise make a symlink to the symlink's origin 440 # otherwise make a symlink to the symlink's origin
319 else 441 else
320 # TODO use dosym 442 # TODO use dosym
443 ln -s "$(readlink "${lib}")" \
321 ln -s "$(readlink "${lib}")" "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")" 444 "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")"
322 debug-print "${lib} is a symlink, linking accordanly" 445 debug-print "${lib} is a symlink, linking accordanly"
323 fi 446 fi
324 # otherwise die 447 # otherwise die
325 else 448 else
326 die "${lib} does not exist" 449 die "${lib} does not exist"
346 java-pkg_check-phase install 469 java-pkg_check-phase install
347 470
348 [[ ${#} -lt 1 ]] && "at least one argument needed" 471 [[ ${#} -lt 1 ]] && "at least one argument needed"
349 472
350 java-pkg_init_paths_ 473 java-pkg_init_paths_
351 474
352 local lib target_dir 475 local lib target_dir
353 for lib in "$@" ; do 476 for lib in "$@" ; do
354 # Check the absolute path of the lib 477 # Check the absolute path of the lib
355 if [[ -e "${lib}" ]] ; then 478 if [[ -e "${lib}" ]] ; then
356 target_dir="$(java-pkg_expand_dir_ ${lib})" 479 target_dir="$(java-pkg_expand_dir_ ${lib})"
404# ------------------------------------------------------------------------------ 527# ------------------------------------------------------------------------------
405java-pkg_dohtml() { 528java-pkg_dohtml() {
406 debug-print-function ${FUNCNAME} $* 529 debug-print-function ${FUNCNAME} $*
407 530
408 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 531 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
409 # TODO-nichoj find out what exactly -f package-list does 532
533 # from /usr/lib/portage/bin/dohtml -h
534 # -f Set list of allowed extensionless file names.
410 dohtml -f package-list "$@" 535 dohtml -f package-list "$@"
536
411 # this probably shouldn't be here but it provides 537 # this probably shouldn't be here but it provides
412 # a reasonable way to catch # docs for all of the 538 # a reasonable way to catch # docs for all of the
413 # old ebuilds. 539 # old ebuilds.
414 java-pkg_recordjavadoc 540 java-pkg_recordjavadoc
415} 541}
416 542
417# TODO document 543# ------------------------------------------------------------------------------
544# @ebuild-function java-pkg_dojavadoc
545#
546# Installs javadoc documentation. This should be controlled by the doc use flag.
547#
548# @param $1: - The javadoc root directory.
549#
550# @example:
551# java-pkg_dojavadoc docs/api
552#
553# ------------------------------------------------------------------------------
418java-pkg_dojavadoc() { 554java-pkg_dojavadoc() {
419 local dir="$1" 555 local dir="$1"
420 556
421 java-pkg_check-phase install 557 java-pkg_check-phase install
422 558
434} 570}
435 571
436# ------------------------------------------------------------------------------ 572# ------------------------------------------------------------------------------
437# @ebuild-function java-pkg_dosrc 573# @ebuild-function java-pkg_dosrc
438# 574#
439# Installs a zip containing the source for a package, so it can used in 575# Installs a zip containing the source for a package, so it can used in
440# from IDEs like eclipse and netbeans. 576# from IDEs like eclipse and netbeans.
441# 577#
442# Ebuild needs to DEPEND on app-arch/zip to use this. 578# Ebuild needs to DEPEND on app-arch/zip to use this.
443# 579#
444# It also should be controlled by USE=source. 580# It also should be controlled by USE=source.
445# 581#
446# @example: 582# @example:
447# java-pkg_dosrc src/* 583# java-pkg_dosrc src/*
448# 584#
449# ------------------------------------------------------------------------------ 585# ------------------------------------------------------------------------------
450# TODO change so it the arguments it takes are the base directories containing 586# TODO change so it the arguments it takes are the base directories containing
451# source -nichoj 587# source -nichoj
452# TODO should we be able to handle multiple calls to dosrc? -nichoj 588# TODO should we be able to handle multiple calls to dosrc? -nichoj
453# TODO maybe we can take an existing zip/jar? -nichoj 589# TODO maybe we can take an existing zip/jar? -nichoj
454# FIXME apparently this fails if you give it an empty directories 590# FIXME apparently this fails if you give it an empty directories
455java-pkg_dosrc() { 591java-pkg_dosrc() {
456 debug-print-function ${FUNCNAME} $* 592 debug-print-function ${FUNCNAME} $*
457 593
458 [ ${#} -lt 1 ] && die "At least one argument needed" 594 [ ${#} -lt 1 ] && die "At least one argument needed"
459 if ! hasq source ${IUSE}; then
460 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
461 fi
462 595
463 java-pkg_check-phase install 596 java-pkg_check-phase install
464 597
465 [[ ${#} -lt 1 ]] && die "At least one argument needed" 598 [[ ${#} -lt 1 ]] && die "At least one argument needed"
599
600 if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
601 local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
602 if is-java-strict; then
603 eerror "${msg}"
604 die "${msg}"
605 else
606 echo "${msg}"
607 echo "Please report this to http://bugs.gentoo.org."
608 fi
609 fi
466 610
467 java-pkg_init_paths_ 611 java-pkg_init_paths_
468 612
469 local zip_name="${PN}-src.zip" 613 local zip_name="${PN}-src.zip"
470 local zip_path="${T}/${zip_name}" 614 local zip_path="${T}/${zip_name}"
471 local dir 615 local dir
472 for dir in ${@}; do 616 for dir in "${@}"; do
473 local dir_parent=$(dirname "${dir}") 617 local dir_parent=$(dirname "${dir}")
474 local dir_name=$(basename "${dir}") 618 local dir_name=$(basename "${dir}")
475 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 619 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
476 zip -q -r ${zip_path} ${dir_name} -i '*.java' 620 zip -q -r ${zip_path} ${dir_name} -i '*.java'
477 local result=$? 621 local result=$?
494# @ebuild-function java-pkg_dolauncher 638# @ebuild-function java-pkg_dolauncher
495# 639#
496# Make a wrapper script to lauch/start this package 640# Make a wrapper script to lauch/start this package
497# If necessary, the wrapper will switch to the appropriate VM. 641# If necessary, the wrapper will switch to the appropriate VM.
498# 642#
643# Can be called without parameters if the package installs only one jar
644# that has the Main-class attribute set. The wrapper will be named ${PN}.
645#
499# @param $1 - filename of launcher to create 646# @param $1 - filename of launcher to create
500# @param $2 - options, as follows: 647# @param $2 - options, as follows:
501# --main the.main.class.too.start 648# --main the.main.class.too.start
502# --jar /the/jar/too/launch.jar 649# --jar /the/jar/too/launch.jar or just <name>.jar
503# --java_args 'Extra arguments to pass too jave' 650# --java_args 'Extra arguments to pass to java'
504# --pkg_args 'extra arguments too pass too the package' 651# --pkg_args 'Extra arguments to pass to the package'
505# --pwd 652# --pwd Directory the launcher changes to before executing java
506# -into 653# -into Directory to install the launcher to, instead of /usr/bin
507# -pre 654# -pre Prepend contents of this file to the launcher
508# ------------------------------------------------------------------------------ 655# ------------------------------------------------------------------------------
509java-pkg_dolauncher() { 656java-pkg_dolauncher() {
510 debug-print-function ${FUNCNAME} $* 657 debug-print-function ${FUNCNAME} $*
511 658
512 java-pkg_check-phase install 659 java-pkg_check-phase install
513
514 [[ ${#} -lt 1 ]] && die "Need at least one argument"
515
516 java-pkg_init_paths_ 660 java-pkg_init_paths_
517 661
662 if [[ ${#} = 0 ]]; then
663 local name="${PN}"
664 else
518 local name="${1}" 665 local name="${1}"
666 shift
667 fi
668
519 # TODO rename to launcher 669 # TODO rename to launcher
520 local target="${T}/${name}" 670 local target="${T}/${name}"
671 local var_tmp="${T}/launcher_variables_tmp"
521 local target_dir pre 672 local target_dir pre
522 shift
523 673
524 echo "#!/bin/bash" > "${target}" 674 # Process the other the rest of the arguments
525 while [[ -n "${1}" && -n "${2}" ]]; do 675 while [[ -n "${1}" && -n "${2}" ]]; do
526 local var=${1} value=${2} 676 local var="${1}" value="${2}"
527 if [[ "${var:0:2}" == "--" ]]; then 677 if [[ "${var:0:2}" == "--" ]]; then
678 local var=${var:2}
528 echo "gjl_${var:2}=\"${value}\"" >> "${target}" 679 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
680 local gjl_${var}="${value}"
529 elif [[ "${var}" == "-into" ]]; then 681 elif [[ "${var}" == "-into" ]]; then
530 target_dir="${value}" 682 target_dir="${value}"
531 elif [[ "${var}" == "-pre" ]]; then 683 elif [[ "${var}" == "-pre" ]]; then
532 pre="${value}" 684 pre="${value}"
533 fi 685 fi
534 shift 2 686 shift 2
535 done 687 done
688
689 # Test if no --jar and --main arguments were given and
690 # in that case check if the package only installs one jar
691 # and use that jar.
692 if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
693 local cp="${JAVA_PKG_CLASSPATH}"
694 if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
695 echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
696 else
697 local msg="Not enough information to create a launcher given."
698 msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
699 die "${msg}"
700 fi
701 fi
702
703 # Write the actual script
704 echo "#!/bin/bash" > "${target}"
705 if [[ -n "${pre}" ]]; then
706 if [[ -f "${pre}" ]]; then
707 cat "${pre}" >> "${target}"
708 else
709 die "-pre specified file '${pre}' does not exist"
710 fi
711 fi
536 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 712 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
537 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 713 cat "${var_tmp}" >> "${target}"
714 rm -f "${var_tmp}"
538 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 715 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
539 716
540 if [[ -n "${into}" ]]; then 717 if [[ -n "${target_dir}" ]]; then
541 DESTTREE="${target_dir}" dobin "${target}" 718 DESTTREE="${target_dir}" dobin "${target}"
542 local ret=$? 719 local ret=$?
543 return ${ret} 720 return ${ret}
544 else 721 else
545 dobin "${target}" 722 dobin "${target}"
573 echo "dowar: warning, skipping directory ${war}" 750 echo "dowar: warning, skipping directory ${war}"
574 continue 751 continue
575 else 752 else
576 warpath="${war}" 753 warpath="${war}"
577 fi 754 fi
578 755
579 # Install those files like you mean it 756 # Install those files like you mean it
580 INSOPTIONS="-m 0644" \ 757 INSOPTIONS="-m 0644" \
581 INSDESTTREE=${JAVA_PKG_WARDEST} \ 758 INSDESTTREE=${JAVA_PKG_WARDEST} \
582 doins ${warpath} 759 doins ${warpath}
583 done 760 done
618# @ebuild-function java-pkg_jar-from 795# @ebuild-function java-pkg_jar-from
619# 796#
620# Makes a symlink to a jar from a certain package 797# Makes a symlink to a jar from a certain package
621# A lot of java packages include dependencies in a lib/ directory 798# A lot of java packages include dependencies in a lib/ directory
622# You can use this function to replace these bundled dependencies. 799# You can use this function to replace these bundled dependencies.
800# The dependency is recorded into package.env DEPEND line, unless "--build-only"
801# is passed as the very first argument, for jars that have to be present only
802# at build time and are not needed on runtime (junit testing etc).
623# 803#
624# Example: get all jars from xerces slot 2 804# Example: get all jars from xerces slot 2
625# java-pkg_jar-from xerces-2 805# java-pkg_jar-from xerces-2
626# Example: get a specific jar from xerces slot 2 806# Example: get a specific jar from xerces slot 2
627# java-pkg_jar-from xerces-2 xml-apis.jar 807# java-pkg_jar-from xerces-2 xml-apis.jar
628# Example get a specific jar from xerces slot 2, and name it diffrently 808# Example: get a specific jar from xerces slot 2, and name it diffrently
629# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 809# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
810# Example: get junit.jar which is needed only for building
811# java-pkg_jar-from --build-only junit junit.jar
630# 812#
813# @param $opt
814# --build-only - makes the jar(s) not added into package.env DEPEND line.
815# (assumed automatically when called inside src_test)
816# --with-dependencies - get jars also from requested package's dependencies
817# transitively.
818# --into $dir - symlink jar(s) into $dir (must exist) instead of .
631# @param $1 - Package to get jars from. 819# @param $1 - Package to get jars from.
632# @param $2 - jar from package. If not specified, all jars will be used. 820# @param $2 - jar from package. If not specified, all jars will be used.
633# @param $3 - When a single jar is specified, destination filename of the 821# @param $3 - When a single jar is specified, destination filename of the
634# symlink. Defaults to the name of the jar. 822# symlink. Defaults to the name of the jar.
635# ------------------------------------------------------------------------------ 823# ------------------------------------------------------------------------------
636# TODO could probably be cleaned up a little 824# TODO could probably be cleaned up a little
637java-pkg_jar-from() { 825java-pkg_jar-from() {
638 debug-print-function ${FUNCNAME} $* 826 debug-print-function ${FUNCNAME} $*
639 827
828 local build_only=""
829 local destdir="."
830 local deep=""
831
832 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true"
833
834 while [[ "${1}" == --* ]]; do
835 if [[ "${1}" = "--build-only" ]]; then
836 build_only="true"
837 elif [[ "${1}" = "--with-dependencies" ]]; then
838 deep="--with-dependencies"
839 elif [[ "${1}" = "--into" ]]; then
840 destdir="${2}"
841 shift
842 else
843 die "java-pkg_jar-from called with unknown parameter: ${1}"
844 fi
845 shift
846 done
847
640 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 848 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
641 849
642 [[ -z ${target_pkg} ]] && die "Must specify a package" 850 [[ -z ${target_pkg} ]] && die "Must specify a package"
643 851
644 # default destjar to the target jar 852 # default destjar to the target jar
645 [[ -z "${destjar}" ]] && destjar="${target_jar}" 853 [[ -z "${destjar}" ]] && destjar="${target_jar}"
646 854
855 local error_msg="There was a problem getting the classpath for ${target_pkg}."
856 local classpath
647 local classpath="$(java-config --classpath=${target_pkg})" 857 classpath="$(java-config ${deep} --classpath=${target_pkg})"
648 [[ $? != 0 ]] && die "There was a problem getting the classpath for ${target_pkg}" 858 [[ $? != 0 ]] && die ${error_msg}
859
860 pushd ${destdir} > /dev/null \
861 || die "failed to change directory to ${destdir}"
862
863 # When we have commas this functions is called to bring jars from multiple
864 # packages. This affects recording of dependencencies because that syntax uses :
865 # if we don't change them to : gjl and java-config -d -p break
866 if [[ ${target_pkg} = *,* ]]; then
867 build_only="true"
868 java-pkg_record-jar_ ${target_pkg//,/:}
869 fi
649 870
650 local jar 871 local jar
651 for jar in ${classpath//:/ }; do 872 for jar in ${classpath//:/ }; do
652 local jar_name=$(basename "${jar}") 873 local jar_name=$(basename "${jar}")
653 if [[ ! -f "${jar}" ]] ; then 874 if [[ ! -f "${jar}" ]] ; then
657 # If no specific target jar was indicated, link it 878 # If no specific target jar was indicated, link it
658 if [[ -z "${target_jar}" ]] ; then 879 if [[ -z "${target_jar}" ]] ; then
659 [[ -f "${target_jar}" ]] && rm "${target_jar}" 880 [[ -f "${target_jar}" ]] && rm "${target_jar}"
660 ln -snf "${jar}" \ 881 ln -snf "${jar}" \
661 || die "Failed to make symlink from ${jar} to ${jar_name}" 882 || die "Failed to make symlink from ${jar} to ${jar_name}"
662 java-pkg_record-jar_ "${target_pkg}" "${jar}" 883 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
663 # otherwise, if the current jar is the target jar, link it 884 # otherwise, if the current jar is the target jar, link it
664 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 885 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
665 [[ -f "${destjar}" ]] && rm "${destjar}" 886 [[ -f "${destjar}" ]] && rm "${destjar}"
666 ln -snf "${jar}" "${destjar}" \ 887 ln -snf "${jar}" "${destjar}" \
667 || die "Failed to make symlink from ${jar} to ${destjar}" 888 || die "Failed to make symlink from ${jar} to ${destjar}"
668 java-pkg_record-jar_ "${target_pkg}" "${jar}" 889 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
890 popd > /dev/null
669 return 0 891 return 0
670 fi 892 fi
671 done 893 done
894 popd > /dev/null
672 # if no target was specified, we're ok 895 # if no target was specified, we're ok
673 if [[ -z "${target_jar}" ]] ; then 896 if [[ -z "${target_jar}" ]] ; then
674 return 0 897 return 0
675 # otherwise, die bitterly 898 # otherwise, die bitterly
676 else 899 else
690# ------------------------------------------------------------------------------ 913# ------------------------------------------------------------------------------
691# @ebuild-function java-pkg_getjars 914# @ebuild-function java-pkg_getjars
692# 915#
693# Get the classpath provided by any number of packages 916# Get the classpath provided by any number of packages
694# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'. 917# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
918# The providing packages are recorded as dependencies into package.env DEPEND
919# line, unless "--build-only" is passed as the very first argument, for jars
920# that have to be present only at build time and are not needed on runtime
921# (junit testing etc).
695# 922#
696# Example: Get the classpath for xerces-2, 923# Example: Get the classpath for xerces-2 and xalan,
697# java-pkg_getjars xerces-2 xalan 924# java-pkg_getjars xerces-2,xalan
698# Example Return: 925# Example Return:
699# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 926# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
700# 927#
928# @param $opt
929# --build-only - makes the jar(s) not added into package.env DEPEND line.
930# (assumed automatically when called inside src_test)
931# --with-dependencies - get jars also from requested package's dependencies
932# transitively.
701# @param $@ - list of packages to get jars from 933# @param $1 - list of packages to get jars from
934# (passed to java-config --classpath)
702# ------------------------------------------------------------------------------ 935# ------------------------------------------------------------------------------
703java-pkg_getjars() { 936java-pkg_getjars() {
704 debug-print-function ${FUNCNAME} $* 937 debug-print-function ${FUNCNAME} $*
705 938
706 [[ ${#} -lt 1 ]] && die "At least one argument needed" 939 local build_only=""
940 local deep=""
707 941
708 # NOTE could probably just pass $@ to java-config --classpath. and return it 942 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true"
709 local classpath pkg 943
710 for pkg in ${@//,/ }; do 944 while [[ "${1}" == --* ]]; do
711 #for pkg in $(echo "$@" | tr ',' ' '); do 945 if [[ "${1}" = "--build-only" ]]; then
712 jars="$(java-config --classpath=${pkg})" 946 build_only="true"
713 debug-print "${pkg}:${jars}" 947 elif [[ "${1}" = "--with-dependencies" ]]; then
714 # TODO should we ensure jars exist? 948 deep="--with-dependencies"
715 if [[ -z "${classpath}" ]]; then
716 classpath="${jars}"
717 else 949 else
718 classpath="${classpath}:${jars}" 950 die "java-pkg_jar-from called with unknown parameter: ${1}"
719 fi 951 fi
720 java-pkg_record-jar_ "${pkg}" 952 shift
721 done 953 done
954
955 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
956
957 local classpath pkgs="${1}"
958 jars="$(java-config ${deep} --classpath=${pkgs})"
959 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed"
960 debug-print "${pkgs}:${jars}"
961
962 if [[ -z "${classpath}" ]]; then
963 classpath="${jars}"
964 else
965 classpath="${classpath}:${jars}"
966 fi
967
968 # Only record jars that aren't build-only
969 if [[ -z "${build_only}" ]]; then
970 oldifs="${IFS}"
971 IFS=","
972 for pkg in ${pkgs}; do
973 java-pkg_record-jar_ "${pkg}"
974 done
975 IFS="${oldifs}"
976 fi
977
722 echo "${classpath}" 978 echo "${classpath}"
723} 979}
724 980
725# ------------------------------------------------------------------------------ 981# ------------------------------------------------------------------------------
726# @ebuild-function java-pkg_getjar 982# @ebuild-function java-pkg_getjar
727# 983#
728# Get the filename of a single jar from a package 984# Get the filename of a single jar from a package
985# The providing package is recorded as runtime dependency into package.env
986# DEPEND line, unless "--build-only" is passed as the very first argument, for
987# jars that have to be present only at build time and are not needed on runtime
988# (junit testing etc).
729# 989#
730# @example 990# @example
731# java-pkg_getjar xerces-2 xml-apis.jar 991# java-pkg_getjar xerces-2 xml-apis.jar
732# @example-return 992# @example-return
733# /usr/share/xerces-2/lib/xml-apis.jar 993# /usr/share/xerces-2/lib/xml-apis.jar
734# 994#
995# @param $opt
996# --build-only - makes the jar not added into package.env DEPEND line.
735# @param $1 - package to use 997# @param $1 - package to use
736# @param $2 - jar to get 998# @param $2 - jar to get
737# ------------------------------------------------------------------------------ 999# ------------------------------------------------------------------------------
738java-pkg_getjar() { 1000java-pkg_getjar() {
739 debug-print-function ${FUNCNAME} $* 1001 debug-print-function ${FUNCNAME} $*
1002
1003 local build_only=""
1004
1005 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true"
1006
1007 while [[ "${1}" == --* ]]; do
1008 if [[ "${1}" = "--build-only" ]]; then
1009 build_only="true"
1010 else
1011 die "java-pkg_jar-from called with unknown parameter: ${1}"
1012 fi
1013 shift
1014 done
1015
1016 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
740 1017
741 local pkg="${1}" target_jar="${2}" jar 1018 local pkg="${1}" target_jar="${2}" jar
742 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 1019 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
743 [[ -z ${target_jar} ]] && die "Must specify jar to get" 1020 [[ -z ${target_jar} ]] && die "Must specify jar to get"
744 1021
745 # TODO check that package is actually installed 1022 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
1023 local classpath
746 local classpath=$(java-config --classpath=${pkg}) 1024 classpath=$(java-config --classpath=${pkg})
747 [[ $? != 0 ]] && die "There could not find classpath for ${pkg}. Are you sure its installed?" 1025 [[ $? != 0 ]] && die ${error_msg}
1026
748 for jar in ${classpath//:/ }; do 1027 for jar in ${classpath//:/ }; do
749 if [[ ! -f "${jar}" ]] ; then 1028 if [[ ! -f "${jar}" ]] ; then
750 die "Installation problems with jars in ${pkg} - is it installed?" 1029 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
751 fi 1030 fi
752 1031
753 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then 1032 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
754 java-pkg_record-jar_ "${pkg}" "${jar}" 1033 # Only record jars that aren't build-only
1034 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" "${jar}"
755 echo "${jar}" 1035 echo "${jar}"
756 return 0 1036 return 0
757 fi 1037 fi
758 done 1038 done
759 1039
760 die "Could not find ${target_jar} in ${pkg}" 1040 die "Could not find ${target_jar} in ${pkg}"
761 return 1 1041 return 1
762} 1042}
763 1043
764# This function reads stdin, and based on that input, figures out how to 1044# This function reads stdin, and based on that input, figures out how to
778# line="${line// /}" 1058# line="${line// /}"
779# 1059#
780# # format: path=jarinfo 1060# # format: path=jarinfo
781# local path=${line%%=*} 1061# local path=${line%%=*}
782# local jarinfo=${line##*=} 1062# local jarinfo=${line##*=}
783# 1063#
784# # format: jar@package 1064# # format: jar@package
785# local jar=${jarinfo%%@*}.jar 1065# local jar=${jarinfo%%@*}.jar
786# local package=${jarinfo##*@} 1066# local package=${jarinfo##*@}
787# if [[ -n ${replace_only} ]]; then 1067# if [[ -n ${replace_only} ]]; then
788# [[ ! -f $path ]] && die "No jar exists at ${path}" 1068# [[ ! -f $path ]] && die "No jar exists at ${path}"
801# @section-end query 1081# @section-end query
802# ------------------------------------------------------------------------------ 1082# ------------------------------------------------------------------------------
803 1083
804# ------------------------------------------------------------------------------ 1084# ------------------------------------------------------------------------------
805# @section-begin helper 1085# @section-begin helper
806# @section-summary Helper functions 1086# @section-summary Helper functions
807# 1087#
808# Various other functions to use from an ebuild 1088# Various other functions to use from an ebuild
809# ------------------------------------------------------------------------------ 1089# ------------------------------------------------------------------------------
810 1090
811# ------------------------------------------------------------------------------ 1091# ------------------------------------------------------------------------------
817# jdbc-stdext 1097# jdbc-stdext
818# jaf 1098# jaf
819# jdbc-rowset 1099# jdbc-rowset
820# jms 1100# jms
821# 1101#
822# @param $1 - Optionally indicate that the dependencies are controlled by 1102# @param $1 - Optionally indicate that the dependencies are controlled by
823# a use flag by specifying '--use' Requires $2. 1103# a use flag by specifying '--use' Requires $2.
824# @param $2 - USE flag which will enable the dependencies. 1104# @param $2 - USE flag which will enable the dependencies.
825# @param $@ - virtual packages to add depenedencies for 1105# @param $@ - virtual packages to add depenedencies for
826# ------------------------------------------------------------------------------ 1106# ------------------------------------------------------------------------------
827# TODO rewrite to parse a line based declaration file instead -- karltk 1107# TODO rewrite to parse a line based declaration file instead -- karltk
883# 1163#
884# export DEPEND="${DEPEND} ${depstr}" 1164# export DEPEND="${DEPEND} ${depstr}"
885# export RDEPEND="${RDEPEND} ${depstr}" 1165# export RDEPEND="${RDEPEND} ${depstr}"
886#} 1166#}
887 1167
1168# ------------------------------------------------------------------------------
1169# @ebuild-function java-pkg_find-normal-jars
1170#
1171# Find the files with suffix .jar file in the given directory or $WORKDIR
1172#
1173# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1174# ------------------------------------------------------------------------------
1175java-pkg_find-normal-jars() {
1176 local dir=$1
1177 [[ "${dir}" ]] || dir="${WORKDIR}"
1178 local found
1179 for jar in $(find "${dir}" -name "*.jar" -type f); do
1180 echo "${jar}"
1181 found="true"
1182 done
1183 [[ "${found}" ]]
1184 return $?
1185}
1186
1187# ------------------------------------------------------------------------------
1188# @ebuild-function java-pkg_ensure-no-bundled-jars
1189#
1190# Try to locate bundled jar files in ${WORKDIR} and die if found.
888# This should be used after S has been populated with symlinks to jars 1191# This function should be called after WORKDIR has been populated with symlink
889# TODO document 1192# to system jar files or bundled jars removed.
1193# ------------------------------------------------------------------------------
890java-pkg_ensure-no-bundled-jars() { 1194java-pkg_ensure-no-bundled-jars() {
891 debug-print-function ${FUNCNAME} $* 1195 debug-print-function ${FUNCNAME} $*
892 pushd ${WORKDIR} >/dev/null 2>/dev/null
893 1196
894 local bundled_jars=$(find . -name "*.jar" -type f) 1197 local bundled_jars=$(java-pkg_find-normal-jars)
895 if [[ -n ${bundled_jars} ]]; then 1198 if [[ -n ${bundled_jars} ]]; then
896 echo "Bundled jars found:" 1199 echo "Bundled jars found:"
897 local jar 1200 local jar
898 for jar in ${bundled_jars}; do 1201 for jar in ${bundled_jars}; do
899 echo $(pwd)${jar/./} 1202 echo $(pwd)${jar/./}
900 done 1203 done
901 die "Bundled jars found!" 1204 die "Bundled jars found!"
902
903 fi 1205 fi
904 popd >/dev/null 2>/dev/null
905} 1206}
906 1207
907# ------------------------------------------------------------------------------ 1208# ------------------------------------------------------------------------------
908# @internal-function java-pkg_ensure-vm-version-sufficient 1209# @internal-function java-pkg_ensure-vm-version-sufficient
909# 1210#
921 fi 1222 fi
922} 1223}
923 1224
924# ------------------------------------------------------------------------------ 1225# ------------------------------------------------------------------------------
925# @internal-function java-pkg_is-vm-version-sufficient 1226# @internal-function java-pkg_is-vm-version-sufficient
926# 1227#
927# @return zero - VM is sufficient 1228# @return zero - VM is sufficient
928# @return non-zero - VM is not sufficient 1229# @return non-zero - VM is not sufficient
929# ------------------------------------------------------------------------------ 1230# ------------------------------------------------------------------------------
930java-pkg_is-vm-version-sufficient() { 1231java-pkg_is-vm-version-sufficient() {
931 debug-print-function ${FUNCNAME} $* 1232 debug-print-function ${FUNCNAME} $*
951 die "Active Java VM too old" 1252 die "Active Java VM too old"
952 fi 1253 fi
953} 1254}
954 1255
955# ------------------------------------------------------------------------------ 1256# ------------------------------------------------------------------------------
956# @internal-function java-pkg_is-vm-version-eq 1257# @internal-function java-pkg_is-vm-version-eq
957# 1258#
958# @param $@ - VM version to compare current VM to 1259# @param $@ - VM version to compare current VM to
959# @return zero - VM versions are equal 1260# @return zero - VM versions are equal
960# @return non-zero - VM version are not equal 1261# @return non-zero - VM version are not equal
961# ------------------------------------------------------------------------------ 1262# ------------------------------------------------------------------------------
962java-pkg_is-vm-version-eq() { 1263java-pkg_is-vm-version-eq() {
992# 1293#
993# @param $@ - VM version to compare current to 1294# @param $@ - VM version to compare current to
994# ------------------------------------------------------------------------------ 1295# ------------------------------------------------------------------------------
995java-pkg_ensure-vm-version-ge() { 1296java-pkg_ensure-vm-version-ge() {
996 debug-print-function ${FUNCNAME} $* 1297 debug-print-function ${FUNCNAME} $*
997 1298
998 if ! java-pkg_is-vm-version-ge "$@" ; then 1299 if ! java-pkg_is-vm-version-ge "$@" ; then
999 debug-print "vm is not suffient" 1300 debug-print "vm is not suffient"
1000 eerror "This package requires a Java VM version >= $@" 1301 eerror "This package requires a Java VM version >= $@"
1001 einfo "Please use java-config -S to set the correct one" 1302 einfo "Please use java-config -S to set the correct one"
1002 die "Active Java VM too old" 1303 die "Active Java VM too old"
1003 fi 1304 fi
1004} 1305}
1005 1306
1006# ------------------------------------------------------------------------------ 1307# ------------------------------------------------------------------------------
1007# @internal-function java-pkg_is-vm-version-ge 1308# @internal-function java-pkg_is-vm-version-ge
1008# 1309#
1009# @param $@ - VM version to compare current VM to 1310# @param $@ - VM version to compare current VM to
1010# @return zero - current VM version is greater than checked version 1311# @return zero - current VM version is greater than checked version
1011# @return non-zero - current VM version is not greater than checked version 1312# @return non-zero - current VM version is not greater than checked version
1012# ------------------------------------------------------------------------------ 1313# ------------------------------------------------------------------------------
1013java-pkg_is-vm-version-ge() { 1314java-pkg_is-vm-version-ge() {
1027 return 1 1328 return 1
1028 fi 1329 fi
1029 fi 1330 fi
1030} 1331}
1031 1332
1333java-pkg_set-current-vm() {
1334 export GENTOO_VM=${1}
1335}
1336
1337java-pkg_get-current-vm() {
1338 echo ${GENTOO_VM}
1339}
1340
1341java-pkg_current-vm-matches() {
1342 hasq $(java-pkg_get-current-vm) ${@}
1343 return $?
1344}
1345
1032# ------------------------------------------------------------------------------ 1346# ------------------------------------------------------------------------------
1033# @ebuild-function java-pkg_get-source 1347# @ebuild-function java-pkg_get-source
1034# 1348#
1035# Determines what source version should be used, for passing to -source. 1349# Determines what source version should be used, for passing to -source.
1036# Unless you want to break things you probably shouldn't set _WANT_SOURCE 1350# Unless you want to break things you probably shouldn't set _WANT_SOURCE
1037# 1351#
1038# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE 1352# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1039# ------------------------------------------------------------------------------ 1353# ------------------------------------------------------------------------------
1044# ------------------------------------------------------------------------------ 1358# ------------------------------------------------------------------------------
1045# @ebuild-function java-pkg_get-target 1359# @ebuild-function java-pkg_get-target
1046# 1360#
1047# Determines what target version should be used, for passing to -target. 1361# Determines what target version should be used, for passing to -target.
1048# If you don't care about lower versions, you can set _WANT_TARGET to the 1362# If you don't care about lower versions, you can set _WANT_TARGET to the
1049# version of your JDK. 1363# version of your JDK.
1050# Remember doing this will mostly like cause things to break.
1051# Doesn't allow it to be lower then the one in depend.
1052# Doesn't allow it to be higher then the active vm.
1053# 1364#
1054# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1365# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1055# ------------------------------------------------------------------------------ 1366# ------------------------------------------------------------------------------
1056java-pkg_get-target() { 1367java-pkg_get-target() {
1057 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")
1058 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then
1059 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)"
1060 if version_is_at_least "${min}" "${JAVA_PKG_WANT_TARGET}" && version_is_at_least "${JAVA_PKG_WANT_TARGET}" "${max}"; then
1061 echo ${JAVA_PKG_WANT_TARGET}
1062 else
1063 echo ${min}
1064 fi
1065 else
1066 echo ${min}
1067 fi
1068
1069 #echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND}")} 1368 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1070} 1369}
1071 1370
1072java-pkg_get-javac() { 1371java-pkg_get-javac() {
1073 debug-print-function ${FUNCNAME} $* 1372 debug-print-function ${FUNCNAME} $*
1074 1373
1075 java-pkg_init-compiler_ 1374
1076 local compiler="${GENTOO_COMPILER}" 1375 local compiler="${GENTOO_COMPILER}"
1077 1376
1078 local compiler_executable 1377 local compiler_executable
1079 if [[ "${compiler}" = "javac" ]]; then 1378 if [[ "${compiler}" = "javac" ]]; then
1080 # nothing fancy needs to be done for javac 1379 # nothing fancy needs to be done for javac
1088 unset JAVAC 1387 unset JAVAC
1089 # try to get value of JAVAC 1388 # try to get value of JAVAC
1090 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1389 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1091 export JAVAC=${old_javac} 1390 export JAVAC=${old_javac}
1092 1391
1093 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1392 if [[ -z ${compiler_executable} ]]; then
1094 1393 echo "JAVAC is empty or undefined in ${compiler_env}"
1394 return 1
1395 fi
1396
1095 # check that it's executable 1397 # check that it's executable
1096 if [[ ! -x ${compiler_executable} ]]; then 1398 if [[ ! -x ${compiler_executable} ]]; then
1097 eerror "Could not find ${compiler_executable}!"
1098 die "${compiler_executable} doesn't exist, or isn't executable" 1399 echo "${compiler_executable} doesn't exist, or isn't executable"
1400 return 1
1099 fi 1401 fi
1100 else 1402 else
1101 eerror "Could not find environment file for ${compiler}" 1403 echo "Could not find environment file for ${compiler}"
1102 die "Could not find ${compiler_env}" 1404 return 1
1103 fi 1405 fi
1104 fi 1406 fi
1105 echo ${compiler_executable} 1407 echo ${compiler_executable}
1106} 1408}
1107 1409
1108# ------------------------------------------------------------------------------ 1410# ------------------------------------------------------------------------------
1109# @ebuild-function java-pkg_javac-args 1411# @ebuild-function java-pkg_javac-args
1110# 1412#
1111# If an ebuild uses javac directly, instead of using ejavac, it should call this 1413# If an ebuild uses javac directly, instead of using ejavac, it should call this
1112# to know what -source/-target to use. 1414# to know what -source/-target to use.
1113# 1415#
1114# @return string - arguments to pass to javac, complete with -target and -source 1416# @return string - arguments to pass to javac, complete with -target and -source
1117 debug-print-function ${FUNCNAME} $* 1419 debug-print-function ${FUNCNAME} $*
1118 1420
1119 local want_source="$(java-pkg_get-source)" 1421 local want_source="$(java-pkg_get-source)"
1120 local want_target="$(java-pkg_get-target)" 1422 local want_target="$(java-pkg_get-target)"
1121 1423
1122 local source_str="-source ${want_source}" 1424 local source_str="-source ${want_source}"
1123 local target_str="-target ${want_target}" 1425 local target_str="-target ${want_target}"
1124 1426
1125 debug-print "want source: ${want_source}" 1427 debug-print "want source: ${want_source}"
1126 debug-print "want target: ${want_target}" 1428 debug-print "want target: ${want_target}"
1127 1429
1128 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1430 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1129 debug-print "could not find valid -source/-target values" 1431 debug-print "could not find valid -source/-target values for javac"
1130 die "Could not find valid -source/-target values" 1432 echo "Could not find valid -source/-target values for javac"
1433 return 1
1131 else 1434 else
1132 if java-pkg_is-vm-version-ge "1.4"; then 1435 if java-pkg_is-vm-version-ge "1.4"; then
1133 echo "${source_str} ${target_str}" 1436 echo "${source_str} ${target_str}"
1134 else 1437 else
1135 echo "${target_str}" 1438 echo "${target_str}"
1139 1442
1140# TODO document 1443# TODO document
1141java-pkg_get-jni-cflags() { 1444java-pkg_get-jni-cflags() {
1142 local flags="-I${JAVA_HOME}/include" 1445 local flags="-I${JAVA_HOME}/include"
1143 1446
1144 # TODO figure out how to cope with other things than linux... 1447 local platform="linux"
1448 use elibc_FreeBSD && platform="freebsd"
1449
1450 # TODO do a check that the directories are valid
1145 flags="${flags} -I${JAVA_HOME}/include/linux" 1451 flags="${flags} -I${JAVA_HOME}/include/${platform}"
1146 1452
1147 echo ${flags} 1453 echo ${flags}
1454}
1455
1456java-pkg_ensure-gcj() {
1457 if ! built_with_use sys-devel/gcc gcj ; then
1458 ewarn
1459 ewarn "You must build gcc with the gcj support to build with gcj"
1460 ewarn
1461 ebeep 5
1462 die "No GCJ support found!"
1463 fi
1464}
1465
1466java-pkg_ensure-test() {
1467 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \
1468 && hasq test ${IUSE} && ! use test;
1469 then
1470 eerror "You specified FEATURES=test, but USE=test is needed"
1471 eerror "to pull in the additional dependencies for testing"
1472 die "Need USE=test enabled"
1473 fi
1474}
1475
1476# ------------------------------------------------------------------------------
1477# @ebuild-function java-pkg_register-ant-task
1478#
1479# Register this package as ant task, so that ant will load it when no specific
1480# ANT_TASKS are specified. Note that even without this registering, all packages
1481# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1482# packages, but can be also used by other ebuilds that used to symlink their
1483# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1484# compatibility.
1485#
1486# @param --version x.y Register only for ant version x.y (otherwise for any ant
1487# version). Used by the ant-* packages to prevent loading of mismatched
1488# ant-core ant tasks after core was updated, before the tasks are updated,
1489# without a need for blockers.
1490# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1491# ------------------------------------------------------------------------------
1492java-pkg_register-ant-task() {
1493 local TASKS_DIR="tasks"
1494
1495 # check for --version x.y parameters
1496 while [[ -n "${1}" && -n "${2}" ]]; do
1497 local var="${1#--}"
1498 local val="${2}"
1499 if [[ "${var}" == "version" ]]; then
1500 TASKS_DIR="tasks-${val}"
1501 else
1502 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1503 fi
1504 shift 2
1505 done
1506
1507 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1508
1509 dodir /usr/share/ant/${TASKS_DIR}
1510 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1511}
1512
1513# ------------------------------------------------------------------------------
1514# @internal-function java-pkg_ant-tasks-from-deps
1515#
1516# Function to determine ANT_TASKS from DEPEND variable for backwards
1517# compatibility with ebuilds that don't set ANT_TASKS before calling eant() or
1518# WANT_ANT_TASKS before inheriting java-pkg-2. If the DEPEND string contains
1519# "dev-java/ant" or "dev-java/ant-tasks", then it returns "all", otherwise
1520# "none". It's not smart enough to cope with USE flag depends but that shouldn't
1521# be a problem, the worst it can do is activace all tasks when not needed.
1522# Note that this is called only with JAVA_PKG_STRICT=1, to find ebuilds with
1523# insufficient dependencies, otherwise all available tasks are used for
1524# backwards compatilbility.
1525#
1526# @return "all" or "none"
1527# ------------------------------------------------------------------------------
1528java-pkg_ant-tasks-from-deps() {
1529 local found_ant found_ant_tasks
1530
1531 for dep in ${DEPEND}
1532 do
1533 local ant="$(awk '/(dev-java\/ant)/ { if (match($1, "(dev-java/ant)((-[0-9])+|$)", m)) print m[1] }' <<< ${dep})"
1534 [[ "${ant}" == "dev-java/ant" ]] && found_ant=true
1535 [[ "${dep}" == *"ant-tasks"* ]] && found_ant_tasks=true
1536 done
1537
1538 if [[ -n "${found_ant}" || -n "${found_ant_tasks}" ]]; then
1539 java-pkg_announce-qa-violation "The ebuild DEPENDS on deprecated ant or ant-tasks"
1540 echo "all"
1541 else
1542 # ebuild doesn't set ANT_TASKS and doesn't depend on ant-tasks or ant
1543 # so we deactivate all tasks that may be installed
1544 echo "none"
1545 fi
1546}
1547
1548# ------------------------------------------------------------------------------
1549# @internal-function java-pkg_ant-tasks-depend
1550#
1551# Translates the WANT_ANT_TASKS variable into valid dependencies.
1552# ------------------------------------------------------------------------------
1553java-pkg_ant-tasks-depend() {
1554 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1555
1556 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1557 local DEP=""
1558 for i in ${WANT_ANT_TASKS}
1559 do
1560 if [[ ${i} != ant-* ]]; then
1561 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1562 return 1
1563 fi
1564 DEP="${DEP}dev-java/${i} "
1565 done
1566 echo ${DEP}
1567 return 0
1568 else
1569 return 0
1570 fi
1148} 1571}
1149 1572
1150# ------------------------------------------------------------------------------ 1573# ------------------------------------------------------------------------------
1151# @section-end helper 1574# @section-end helper
1152# ------------------------------------------------------------------------------ 1575# ------------------------------------------------------------------------------
1161 1584
1162# ------------------------------------------------------------------------------ 1585# ------------------------------------------------------------------------------
1163# @ebuild-function eant 1586# @ebuild-function eant
1164# 1587#
1165# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1588# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1166# compiler. 1589# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1167# 1590# variables:
1591# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1592# gentoo.classpath property. Be sure to call
1593# java-ant_rewrite-classpath in src_unpack.
1594# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1168# ------------------------------------------------------------------------------ 1595# ------------------------------------------------------------------------------
1169eant() { 1596eant() {
1170 debug-print-function ${FUNCNAME} $* 1597 debug-print-function ${FUNCNAME} $*
1171 1598
1172 local antflags 1599 # FIXME get this working
1600# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then
1601# java-pkg_announce-qa-violation \
1602# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1603# fi
1604
1605 if ! hasq java-ant-2 ${INHERITED} && is-java-strict; then
1606 local msg="You should inherit java-ant-2 when using eant"
1607 java-pkg_announce-qa-violation ${msg}
1608 die ${msg}
1609 fi
1610
1611 local antflags="-Dnoget=true -Dmaven.mode.offline=true"
1612
1173 java-pkg_init-compiler_ 1613 java-pkg_init-compiler_
1174 local compiler="${GENTOO_COMPILER}" 1614 local compiler="${GENTOO_COMPILER}"
1175 1615
1176 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1616 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1177 1617
1179 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1619 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1180 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1620 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1181 fi 1621 fi
1182 1622
1183 if [[ ${compiler} != "javac" ]]; then 1623 if [[ ${compiler} != "javac" ]]; then
1184 antflags="-Dbuild.compiler=${build_compiler}" 1624 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1185 # Figure out any extra stuff to put on the classpath for compilers aside 1625 # Figure out any extra stuff to put on the classpath for compilers aside
1186 # from javac 1626 # from javac
1187 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to 1627 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1188 # java-config -p 1628 # java-config -p
1189 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1629 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})"
1190 if [[ -n ${build_compiler_deps} ]]; then 1630 if [[ -n ${build_compiler_deps} ]]; then
1191 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})" 1631 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1192 fi 1632 fi
1193 fi 1633 fi
1194 1634
1195 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1635 if is-java-strict; then
1196 antflags="${antflags} -debug" 1636 einfo "Disabling system classpath for ant"
1637 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1638 fi
1639
1640 for arg in "${@}"; do
1641 if [[ ${arg} = -lib ]]; then
1642 if is-java-strict; then
1643 eerror "You should not use the -lib argument to eant because it will fail"
1644 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1645 eerror "or ant properties to make dependencies available."
1646 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1647 eerror "split ant (>=dev-java/ant-core-1.7)."
1648 die "eant -lib is deprecated/forbidden"
1649 else
1650 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1651 echo "more info."
1652 fi
1197 fi 1653 fi
1198 1654 done
1655
1656 if has_version ">=dev-java/ant-core-1.7.0"; then
1657 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1658 ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}"
1659
1660 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1661 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1662
1663 if is-java-strict; then
1664 # if ant-tasks were not set by ebuild or forced, try to determine them from depends
1665 if [[ -z "${ANT_TASKS}" ]]; then
1666 ANT_TASKS="$(java-pkg_ant-tasks-from-deps)"
1667 fi
1668 else
1669 # if ant-tasks is not set by ebuild or forced, activate all of them
1670 ANT_TASKS="${ANT_TASKS:-all}"
1671 fi
1672
1673 # at this point, ANT_TASKS should be "all", "none" or explicit list
1674 if [[ "${ANT_TASKS}" == "all" ]]; then
1675 einfo "Using all available ANT_TASKS"
1676 elif [[ "${ANT_TASKS}" == "none" ]]; then
1677 einfo "Disabling all optional ANT_TASKS"
1678 else
1679 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1680 fi
1681
1682 export ANT_TASKS
1683 fi
1684
1685 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1686 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1687
1688 local gcp="${EANT_GENTOO_CLASSPATH}"
1689
1690 if [[ ${EBUILD_PHASE} = "test" ]]; then
1691 antflags="${antflags} -DJunit.present=true"
1692 [[ ${gcp} && ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1693 fi
1694
1695 local cp
1696
1697 for atom in ${gcp}; do
1698 cp="${cp}:$(java-pkg_getjars ${atom})"
1699 done
1700
1701 if [[ ${cp} ]]; then
1702 # It seems ant does not like single quotes around ${cp}
1703 antflags="${antflags} -Dgentoo.classpath=\"${cp#:}\""
1704 fi
1705
1199 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1706 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1707 debug-print "Calling ant: ${antflags} ${@}"
1200 ant ${antflags} "${@}" || die "eant failed" 1708 ant ${antflags} "${@}" || die "eant failed"
1201 1709
1202} 1710}
1203 1711
1204# ------------------------------------------------------------------------------ 1712# ------------------------------------------------------------------------------
1205# @ebuild-function ejavac 1713# @ebuild-function ejavac
1206# 1714#
1207# Javac wrapper function. Will use the appropriate compiler, based on 1715# Javac wrapper function. Will use the appropriate compiler, based on
1208# /etc/java-config/compilers.conf 1716# /etc/java-config/compilers.conf
1209# 1717#
1210# @param $@ - Arguments to be passed to the compiler 1718# @param $@ - Arguments to be passed to the compiler
1211# ------------------------------------------------------------------------------ 1719# ------------------------------------------------------------------------------
1212ejavac() { 1720ejavac() {
1213 debug-print-function ${FUNCNAME} $* 1721 debug-print-function ${FUNCNAME} $*
1214 1722
1723 java-pkg_init-compiler_
1724
1725 local compiler_executable
1215 local compiler_executable=$(java-pkg_get-javac) 1726 compiler_executable=$(java-pkg_get-javac)
1727 if [[ ${?} != 0 ]]; then
1728 eerror "There was a problem determining compiler: ${compiler_executable}"
1729 die "get-javac failed"
1730 fi
1216 1731
1732 local javac_args
1733 javac_args="$(java-pkg_javac-args)"
1734 if [[ ${?} != 0 ]]; then
1735 eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
1736 die "java-pkg_javac-args failed"
1737 fi
1738
1217 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 1739 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1218 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 1740 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1219} 1741}
1220 1742
1221# ------------------------------------------------------------------------------ 1743# ------------------------------------------------------------------------------
1222# @ebuild-function java-pkg_filter-compiler 1744# @ebuild-function java-pkg_filter-compiler
1223# 1745#
1224# Used to prevent the use of some compilers. Should be used in src_compile. 1746# Used to prevent the use of some compilers. Should be used in src_compile.
1225# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER 1747# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
1226# 1748#
1227# @param $@ - compilers to filter 1749# @param $@ - compilers to filter
1228# ------------------------------------------------------------------------------ 1750# ------------------------------------------------------------------------------
1229java-pkg_filter-compiler() { 1751java-pkg_filter-compiler() {
1230 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@" 1752 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@"
1231} 1753}
1232 1754
1233# ------------------------------------------------------------------------------ 1755# ------------------------------------------------------------------------------
1756# @ebuild-function java-pkg_force-compiler
1757#
1758# Used to force the use of particular compilers. Should be used in src_compile.
1759# A common use of this would be to force ecj-3.1 to be used on amd64, to avoid
1760# OutOfMemoryErrors that may come up.
1761#
1762# @param $@ - compilers to force
1763# ------------------------------------------------------------------------------
1764java-pkg_force-compiler() {
1765 JAVA_PKG_FORCE_COMPILER="$@"
1766}
1767
1768# ------------------------------------------------------------------------------
1234# @ebuild-function use_doc 1769# @ebuild-function use_doc
1235# 1770#
1236# Helper function for getting ant to build javadocs. If the user has USE=doc, 1771# Helper function for getting ant to build javadocs. If the user has USE=doc,
1237# then 'javadoc' or the argument are returned. Otherwise, there is no return. 1772# then 'javadoc' or the argument are returned. Otherwise, there is no return.
1238# 1773#
1239# The output of this should be passed to ant. 1774# The output of this should be passed to ant.
1240# 1775#
1241# Example: build javadocs by calling 'javadoc' target 1776# Example: build javadocs by calling 'javadoc' target
1242# eant $(use_doc) 1777# eant $(use_doc)
1243# Example: build javadocs by calling 'apidoc' target 1778# Example: build javadocs by calling 'apidoc' target
1248# ------------------------------------------------------------------------------ 1783# ------------------------------------------------------------------------------
1249use_doc() { 1784use_doc() {
1250 use doc && echo ${@:-javadoc} 1785 use doc && echo ${@:-javadoc}
1251} 1786}
1252 1787
1788
1253# ------------------------------------------------------------------------------ 1789# ------------------------------------------------------------------------------
1254# @section-end build 1790# @section-end build
1255# ------------------------------------------------------------------------------ 1791# ------------------------------------------------------------------------------
1256 1792
1257# ------------------------------------------------------------------------------ 1793# ------------------------------------------------------------------------------
1258# @section-begin internal 1794# @section-begin internal
1259# @section-summary Internal functions 1795# @section-summary Internal functions
1260# 1796#
1261# Do __NOT__ use any of these from an ebuild! These are only to be used from 1797# Do __NOT__ use any of these from an ebuild! These are only to be used from
1262# within the java eclasses. 1798# within the java eclasses.
1263# ------------------------------------------------------------------------------ 1799# ------------------------------------------------------------------------------
1264 1800
1265# ----------------------------------------------------------------------------- 1801# -----------------------------------------------------------------------------
1266# @function-internal java-pkg_init 1802# @function-internal java-pkg_init
1267# 1803#
1268# The purpose of this function, as the name might imply, is to initialize the 1804# The purpose of this function, as the name might imply, is to initialize the
1269# Java environment. It ensures that that there aren't any environment variables 1805# Java environment. It ensures that that there aren't any environment variables
1270# that'll muss things up. It initializes some variables, which are used 1806# that'll muss things up. It initializes some variables, which are used
1271# internally. And most importantly, it'll switch the VM if necessary. 1807# internally. And most importantly, it'll switch the VM if necessary.
1272# 1808#
1275# 1811#
1276# ----------------------------------------------------------------------------- 1812# -----------------------------------------------------------------------------
1277java-pkg_init() { 1813java-pkg_init() {
1278 unset JAVAC 1814 unset JAVAC
1279 unset JAVA_HOME 1815 unset JAVA_HOME
1816
1817 # People do all kinds of weird things.
1818 # http://forums.gentoo.org/viewtopic-p-3943166.html
1819 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
1820 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
1821 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
1822 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
1823 ewarn "sun-jdk vms and and as such break configure scripts that"
1824 ewarn "use it (for example app-office/openoffice) so we filter it out."
1825 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
1826 ewarn "make.conf for example) to silence this warning or"
1827 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
1828 fi
1829
1830 if [[ -z ${accept} ]]; then
1831 unset _JAVA_OPTIONS
1832 # phase hooks make this run many times without this
1833 I_WANT_GLOBAL_JAVA_OPTIONS="true"
1834 fi
1835
1280 java-pkg_init_paths_ 1836 java-pkg_init_paths_
1281 java-pkg_switch-vm 1837 java-pkg_switch-vm
1282 PATH=${JAVA_HOME}/bin:${PATH} 1838 PATH=${JAVA_HOME}/bin:${PATH}
1283 1839
1284 # TODO we will probably want to set JAVAC and JAVACFLAGS 1840 # TODO we will probably want to set JAVAC and JAVACFLAGS
1285 1841
1286 # Do some QA checks 1842 # Do some QA checks
1287 java-pkg_check-jikes 1843 java-pkg_check-jikes
1288 1844
1289 # When users have crazy classpaths some packages can fail to compile. 1845 # When users have crazy classpaths some packages can fail to compile.
1290 # and everything should work with empty CLASSPATH. 1846 # and everything should work with empty CLASSPATH.
1291 # This also helps prevent unexpected dependencies on random things 1847 # This also helps prevent unexpected dependencies on random things
1292 # from the CLASSPATH. 1848 # from the CLASSPATH.
1293 unset CLASSPATH 1849 unset CLASSPATH
1850
1851 # Unset external ANT_ stuff
1852 unset ANT_TASKS
1853 unset ANT_OPTS
1294} 1854}
1295 1855
1296# ------------------------------------------------------------------------------ 1856# ------------------------------------------------------------------------------
1297# @function-internal java-pkg-init-compiler_ 1857# @function-internal java-pkg-init-compiler_
1298# 1858#
1299# This function attempts to figure out what compiler should be used. It does 1859# This function attempts to figure out what compiler should be used. It does
1300# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the 1860# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
1301# COMPILERS variable defined there. 1861# COMPILERS variable defined there.
1302# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER 1862# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
1303# 1863#
1304# It will go through the list of compilers, and verify that it supports the 1864# It will go through the list of compilers, and verify that it supports the
1305# target and source that are needed. If it is not suitable, then the next 1865# target and source that are needed. If it is not suitable, then the next
1306# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking 1866# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
1307# isn't done. 1867# isn't done.
1308# 1868#
1330 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1890 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1331 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})" 1891 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
1332 else 1892 else
1333 compilers=${JAVA_PKG_FORCE_COMPILER} 1893 compilers=${JAVA_PKG_FORCE_COMPILER}
1334 fi 1894 fi
1335 1895
1336 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}" 1896 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
1337 1897
1338 # Figure out if we should announce what compiler we're using 1898 # Figure out if we should announce what compiler we're using
1339 local compiler 1899 local compiler
1340 for compiler in ${compilers}; do 1900 for compiler in ${compilers}; do
1343 if [[ ${compiler} = "javac" ]]; then 1903 if [[ ${compiler} = "javac" ]]; then
1344 debug-print "Found javac... breaking" 1904 debug-print "Found javac... breaking"
1345 export GENTOO_COMPILER="javac" 1905 export GENTOO_COMPILER="javac"
1346 break 1906 break
1347 fi 1907 fi
1348 1908
1349 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then 1909 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
1350 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1910 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1351 einfo "Filtering ${compiler}" 1911 einfo "Filtering ${compiler}"
1352 continue 1912 continue
1353 fi 1913 fi
1354 fi 1914 fi
1355 1915
1356 # for non-javac, we need to make sure it supports the right target and 1916 # for non-javac, we need to make sure it supports the right target and
1357 # source 1917 # source
1358 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1918 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1359 if [[ -f ${compiler_env} ]]; then 1919 if [[ -f ${compiler_env} ]]; then
1360 local desired_target="$(java-pkg_get-target)" 1920 local desired_target="$(java-pkg_get-target)"
1442# Writes the package.env out to disk. 2002# Writes the package.env out to disk.
1443# 2003#
1444# ------------------------------------------------------------------------------ 2004# ------------------------------------------------------------------------------
1445# TODO change to do-write, to match everything else 2005# TODO change to do-write, to match everything else
1446java-pkg_do_write_() { 2006java-pkg_do_write_() {
2007 java-pkg_init_paths_
1447 # Create directory for package.env 2008 # Create directory for package.env
1448 dodir "${JAVA_PKG_SHAREPATH}" 2009 dodir "${JAVA_PKG_SHAREPATH}"
1449 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 2010 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then
1450 # Create package.env 2011 # Create package.env
1451 ( 2012 (
1456 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 2017 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1457 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 2018 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1458 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 2019 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\""
1459 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 2020 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1460 ) > "${JAVA_PKG_ENV}" 2021 ) > "${JAVA_PKG_ENV}"
1461 2022
1462 # register target/source 2023 # register target/source
1463 local target="$(java-pkg_get-target)" 2024 local target="$(java-pkg_get-target)"
1464 local source="$(java-pkg_get-source)" 2025 local source="$(java-pkg_get-source)"
1465 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}" 2026 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
1466 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}" 2027 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
1479 # Strip unnecessary leading and trailing colons 2040 # Strip unnecessary leading and trailing colons
1480 # TODO try to cleanup if possible 2041 # TODO try to cleanup if possible
1481 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 2042 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
1482 fi 2043 fi
1483} 2044}
1484
1485 2045
1486# ------------------------------------------------------------------------------ 2046# ------------------------------------------------------------------------------
1487# @internal-function java-pkg_record-jar_ 2047# @internal-function java-pkg_record-jar_
1488# 2048#
1489# Record a dependency to the package.env 2049# Record a dependency to the package.env
1533 fi 2093 fi
1534} 2094}
1535 2095
1536# ------------------------------------------------------------------------------ 2096# ------------------------------------------------------------------------------
1537# @internal-function java-pkg_expand_dir_ 2097# @internal-function java-pkg_expand_dir_
1538# 2098#
1539# Gets the full path of the file/directory's parent. 2099# Gets the full path of the file/directory's parent.
1540# @param $1 - file/directory to find parent directory for 2100# @param $1 - file/directory to find parent directory for
1541# @return - path to $1's parent directory 2101# @return - path to $1's parent directory
1542# ------------------------------------------------------------------------------ 2102# ------------------------------------------------------------------------------
1543java-pkg_expand_dir_() { 2103java-pkg_expand_dir_() {
1570# ------------------------------------------------------------------------------ 2130# ------------------------------------------------------------------------------
1571java-pkg_setup-vm() { 2131java-pkg_setup-vm() {
1572 debug-print-function ${FUNCNAME} $* 2132 debug-print-function ${FUNCNAME} $*
1573 2133
1574 local vendor="$(java-pkg_get-vm-vendor)" 2134 local vendor="$(java-pkg_get-vm-vendor)"
1575 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge 1 5; then 2135 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1576 addpredict "/dev/random" 2136 addpredict "/dev/random"
1577 elif [[ "${vendor}" == "ibm" ]]; then 2137 elif [[ "${vendor}" == "ibm" ]]; then
1578 addpredict "/proc/self/maps" 2138 addpredict "/proc/self/maps"
1579 addpredict "/proc/cpuinfo" 2139 addpredict "/proc/cpuinfo"
1580 export LANG="C" LC_ALL="C" 2140 export LANG="C" LC_ALL="C"
1629# @return - The version of the current VM 2189# @return - The version of the current VM
1630# ------------------------------------------------------------------------------ 2190# ------------------------------------------------------------------------------
1631java-pkg_get-vm-version() { 2191java-pkg_get-vm-version() {
1632 debug-print-function ${FUNCNAME} $* 2192 debug-print-function ${FUNCNAME} $*
1633 2193
1634 java-pkg_get-current-vm | sed -e "s/.*-\([0-9.]\+\).*/\1/" 2194 java-config -g PROVIDES_VERSION
1635} 2195}
1636 2196
1637# ------------------------------------------------------------------------------ 2197# ------------------------------------------------------------------------------
1638# @internal-function java-pkg_switch-vm 2198# @internal-function java-pkg_switch-vm
1639# 2199#
1640# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 2200# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1641# verify that the current VM is sufficient. 2201# verify that the current VM is sufficient.
1642# Setup the environment for the VM being used. 2202# Setup the environment for the VM being used.
1643# ------------------------------------------------------------------------------ 2203# ------------------------------------------------------------------------------
1644java-pkg_switch-vm() { 2204java-pkg_switch-vm() {
2205 debug-print-function ${FUNCNAME} $*
2206
1645 if java-pkg_needs-vm; then 2207 if java-pkg_needs-vm; then
1646 # Use the VM specified by JAVA_PKG_FORCE_VM 2208 # Use the VM specified by JAVA_PKG_FORCE_VM
1647 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then 2209 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1648 # If you're forcing the VM, I hope you know what your doing... 2210 # If you're forcing the VM, I hope you know what your doing...
2211 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1649 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 2212 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1650 # if we're allowed to switch the vm... 2213 # if we're allowed to switch the vm...
1651 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 2214 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1652 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}" 2215 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1653 if [[ -n ${JAVA_PKG_VNEED} ]]; then 2216 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1654 export GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2217 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1655 else 2218 else
1656 export GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2219 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
2220 fi
2221 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
2222 eerror "Unable to determine VM for building from dependencies:"
2223 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
2224 echo "VNEED: ${JAVA_PKG_VNEED}"
2225 die "Failed to determine VM for building."
2226 else
2227 export GENTOO_VM
1657 fi 2228 fi
1658 # otherwise just make sure the current VM is sufficient 2229 # otherwise just make sure the current VM is sufficient
1659 else 2230 else
1660 java-pkg_ensure-vm-version-sufficient 2231 java-pkg_ensure-vm-version-sufficient
1661 fi 2232 fi
1662 debug-print "Using: $(java-config -f)" 2233 debug-print "Using: $(java-config -f)"
1663 2234
1664 java-pkg_setup-vm 2235 java-pkg_setup-vm
1665 2236
1666 export JAVA=$(java-config -java) 2237 export JAVA=$(java-config --java)
1667 export JAVAC=$(java-config -javac) 2238 export JAVAC=$(java-config --javac)
1668 export JAVACFLAGS="$(java-pkg_javac-args)" 2239 JAVACFLAGS="$(java-pkg_javac-args)"
2240 if [[ ${?} != 0 ]]; then
2241 eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
2242 die "java-pkg_javac-args failed"
2243 fi
1669 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 2244 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
2245 export JAVACFLAGS
1670 2246
1671 export JAVA_HOME="$(java-config -g JAVA_HOME)" 2247 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1672 export JDK_HOME=${JAVA_HOME} 2248 export JDK_HOME=${JAVA_HOME}
1673 2249
1674 #TODO If you know a better solution let us know. 2250 #TODO If you know a better solution let us know.
1675 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 2251 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1676 2252
1677 local tann="${T}/announced-vm" 2253 local tann="${T}/announced-vm"
1678 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 2254 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1679 # Add a check for setup/preinst phase... to avoid duplicate outputs 2255 # Add a check for setup/preinst phase... to avoid duplicate outputs
1680 # for when FEATURES=buildpkg 2256 # for when FEATURES=buildpkg
1681 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]]; 2257 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1706 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2 2282 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2
1707 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2 2283 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2
1708 echo "and of course, the output of emerge --info" >&2 2284 echo "and of course, the output of emerge --info" >&2
1709} 2285}
1710 2286
2287
2288# TODO document
2289# List jars in the source directory, ${S}
2290java-pkg_jar-list() {
2291 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
2292 einfo "Linked Jars"
2293 find "${S}" -type l -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2294 einfo "Jars"
2295 find "${S}" -type f -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2296 einfo "Classes"
2297 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2298 fi
2299}
2300
2301# ------------------------------------------------------------------------------
2302# @internal-function java-pkg_verify-classes
2303#
2304# Verify that the classes were compiled for the right source / target. Dies if
2305# not.
2306# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2307# ------------------------------------------------------------------------------
2308java-pkg_verify-classes() {
2309 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
2310 local target=$(java-pkg_get-target)
2311 local result
2312 local log="${T}/class-version-verify.log"
2313 if [[ -n "${1}" ]]; then
2314 class-version-verify.py -v -t ${target} "${1}" > "${log}"
2315 result=$?
2316 else
2317 ebegin "Verifying java class versions (target: ${target})"
2318 class-version-verify.py -v -t ${target} -r "${D}" > "${log}"
2319 result=$?
2320 eend ${result}
2321 fi
2322 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2323 if [[ ${result} != 0 ]]; then
2324 eerror "Incorrect bytecode version found"
2325 [[ -n "${1}" ]] && eerror "in file: ${1}"
2326 eerror "See ${log} for more details."
2327 die "Incorrect bytecode found"
2328 fi
2329}
2330
1711# ------------------------------------------------------------------------------ 2331# ------------------------------------------------------------------------------
1712# @section-end internal 2332# @section-end internal
1713# ------------------------------------------------------------------------------ 2333# ------------------------------------------------------------------------------
1714 2334
1715java-pkg_check-phase() { 2335java-pkg_check-phase() {
1716 local phase=${1} 2336 local phase=${1}
1717 local funcname=${2} 2337 local funcname=${2}
1718 # TODO add check for java-stricter
1719 if [[ ${EBUILD_PHASE} != ${phase} ]]; then 2338 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then
1720 java-pkg_announce-qa-violation \ 2339 java-pkg_announce-qa-violation \
1721 "${funcname} used outside of src_${phase}" 2340 "${funcname} used outside of src_${phase}"
1722 fi 2341 fi
1723} 2342}
1724 2343
1735 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2354 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1736 fi 2355 fi
1737} 2356}
1738 2357
1739java-pkg_announce-qa-violation() { 2358java-pkg_announce-qa-violation() {
1740 if hasq java-strict ${FEATURES}; then 2359 if is-java-strict; then
1741 echo "Java QA Notice: $@" >&2 2360 echo "Java QA Notice: $@" >&2
1742 increment-qa-violations 2361 increment-qa-violations
1743 fi 2362 fi
1744} 2363}
1745 2364
1746increment-qa-violations() { 2365increment-qa-violations() {
1747 let "JAVA_PKG_QA_VIOLATIONS+=1" 2366 let "JAVA_PKG_QA_VIOLATIONS+=1"
1748 export JAVA_PKG_QA_VIOLATIONS 2367 export JAVA_PKG_QA_VIOLATIONS
1749} 2368}
1750 2369
2370is-java-strict() {
2371 [[ -n ${JAVA_PKG_STRICT} ]]
2372 return $?
2373}
2374
1751# ------------------------------------------------------------------------------ 2375# ------------------------------------------------------------------------------
1752# @eclass-end 2376# @eclass-end
1753# ------------------------------------------------------------------------------ 2377# ------------------------------------------------------------------------------

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

  ViewVC Help
Powered by ViewVC 1.1.20