/[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.83
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.83 2007/05/04 17:20:08 caster 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 ( # dont want to pollute calling env
212 insinto "${dest}"
213 doins -r ${1}/*
214 ) || die "Installing examples failed"
215 else
216 ( # dont want to pollute calling env
217 insinto "${dest}"
218 doins -r "$@"
219 ) || die "Installing examples failed"
220 fi
221}
145 222
146# ----------------------------------------------------------------------------- 223# -----------------------------------------------------------------------------
147# @ebuild-function java-pkg_dojar 224# @ebuild-function java-pkg_dojar
148# 225#
149# Installs any number of jars. 226# Installs any number of jars.
150# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default. 227# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default.
151# You can use java-pkg_jarinto to change this path. 228# You can use java-pkg_jarinto to change this path.
152# You should never install a jar with a package version in the filename. 229# You should never install a jar with a package version in the filename.
153# Instead, use java-pkg_newjar defined below. 230# Instead, use java-pkg_newjar defined below.
154# 231#
155# @example 232# @example
156# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar 233# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar
157# 234#
168 # Create JARDEST if it doesn't exist 245 # Create JARDEST if it doesn't exist
169 dodir ${JAVA_PKG_JARDEST} 246 dodir ${JAVA_PKG_JARDEST}
170 247
171 local jar 248 local jar
172 # for each jar 249 # for each jar
173 for jar in "$@"; do 250 for jar in "${@}"; do
174 local jar_basename=$(basename "${jar}") 251 local jar_basename=$(basename "${jar}")
175 252
176 java-pkg_check-versioned-jar ${jar_basename} 253 java-pkg_check-versioned-jar ${jar_basename}
177 254
178 # check if it exists 255 # check if it exists
179 if [[ -e "${jar}" ]] ; then 256 if [[ -e "${jar}" ]] ; then
257 # Don't overwrite if jar has already been installed with the same
258 # name
259 local dest="${D}${JAVA_PKG_JARDEST}/${jar_basename}"
260 if [[ -e "${dest}" ]]; then
261 ewarn "Overwriting ${dest}"
262 fi
263
180 # install it into JARDEST if it's a non-symlink 264 # install it into JARDEST if it's a non-symlink
181 if [[ ! -L "${jar}" ]] ; then 265 if [[ ! -L "${jar}" ]] ; then
266 #but first check class version when in strict mode.
267 is-java-strict && java-pkg_verify-classes "${jar}"
268
182 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 269 INSDESTTREE="${JAVA_PKG_JARDEST}" \
183 doins "${jar}" || die "failed to install ${jar}" 270 doins "${jar}" || die "failed to install ${jar}"
184 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 271 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
185 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}" 272 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}"
186 # make a symlink to the original jar if it's symlink 273 # make a symlink to the original jar if it's symlink
197 284
198 java-pkg_do_write_ 285 java-pkg_do_write_
199} 286}
200 287
201 288
289# ------------------------------------------------------------------------------
290# @internal-function depend-java-query
291#
292# Wrapper for the depend-java-query binary to enable passing USE in env.
293# Using env variables keeps this eclass working with java-config versions that
294# do not handle use flags.
295# ------------------------------------------------------------------------------
296
297depend-java-query() {
298 # Used to have a which call here but it caused endless loops for some people
299 # that had some weird bashrc voodoo for which.
300 USE="${USE}" /usr/bin/depend-java-query "${@}"
301}
202 302
203# ------------------------------------------------------------------------------ 303# ------------------------------------------------------------------------------
204# @ebuild-function java-pkg_regjar 304# @ebuild-function java-pkg_regjar
205# 305#
206# Records an already installed jar in the package.env 306# 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 307# This would mostly be used if the package has make or a custom script to
208# install things. 308# install things.
209# 309#
210# Example: 310# Example:
211# java-pkg-regjar ${D}/opt/foo/lib/foo.jar 311# java-pkg_regjar ${D}/opt/foo/lib/foo.jar
312#
313# WARNING:
314# if you want to use shell expansion, you have to use ${D}/... as the for in
315# this function will not be able to expand the path, here's an example:
316#
317# java-pkg_regjar /opt/my-java/lib/*.jar
318#
319# will not work, because:
320# * the `for jar in "$@"` can't expand the path to jar file names, as they
321# don't exist yet
322# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar'
323# doesn't exist
324#
325# you have to use it as:
326#
327# java-pkg_regjar ${D}/opt/my-java/lib/*.jar
212# 328#
213# @param $@ - jars to record 329# @param $@ - jars to record
214# ------------------------------------------------------------------------------ 330# ------------------------------------------------------------------------------
215# TODO fix me! 331# TODO should we be making sure the jar is present on ${D} or wherever?
216java-pkg_regjar() { 332java-pkg_regjar() {
217 debug-print-function ${FUNCNAME} $* 333 debug-print-function ${FUNCNAME} $*
218 334
219 java-pkg_check-phase install 335 java-pkg_check-phase install
220 336
221 [[ ${#} -lt 1 ]] && die "at least one argument needed" 337 [[ ${#} -lt 1 ]] && die "at least one argument needed"
222 338
223 java-pkg_init_paths_ 339 java-pkg_init_paths_
224 340
225 local jar jar_dir jar_file 341 local jar jar_dir jar_file
226 for jar in "$@"; do 342 for jar in "${@}"; do
227 # TODO use java-pkg_check-versioned-jar 343 # 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 344 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
345 [[ -d "${jar}" || -d "${D}${jar}" ]] \
346 && die "Called ${FUNCNAME} on a directory $*"
347
348 #check that class version correct when in strict mode
349 is-java-strict && java-pkg_verify-classes "${jar}"
350
351 # nelchael: we should strip ${D} in this case too, here's why:
352 # imagine such call:
353 # java-pkg_regjar ${D}/opt/java/*.jar
354 # such call will fall into this case (-e ${jar}) and will
355 # record paths with ${D} in package.env
231 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 356 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
232 else 357 else
358 if [[ ${jar} = *\** ]]; then
359 eerror "The argument ${jar} to ${FUNCNAME}"
360 eerror "has * in it. If you want it to glob in"
361 eerror '${D} add ${D} to the argument.'
362 fi
233 die "${jar} does not exist" 363 die "${jar} does not exist"
234 fi 364 fi
235 done 365 done
236 366
237 java-pkg_do_write_ 367 java-pkg_do_write_
238} 368}
239
240 369
241# ------------------------------------------------------------------------------ 370# ------------------------------------------------------------------------------
242# @ebuild-function java-pkg_newjar 371# @ebuild-function java-pkg_newjar
243# 372#
244# Installs a jar with a new name 373# Installs a jar with a new name
255 local original_jar="${1}" 384 local original_jar="${1}"
256 local new_jar="${2:-${PN}.jar}" 385 local new_jar="${2:-${PN}.jar}"
257 local new_jar_dest="${T}/${new_jar}" 386 local new_jar_dest="${T}/${new_jar}"
258 387
259 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 388 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
260 [[ ! -f ${original_jar} ]] && die "${new_jar} does not exist!" 389 [[ ! -f ${original_jar} ]] \
390 && die "${original_jar} does not exist or is not a file!"
261 391
262 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 392 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
263 cp "${original_jar}" "${new_jar_dest}" \ 393 cp "${original_jar}" "${new_jar_dest}" \
264 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 394 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
265 java-pkg_dojar "${new_jar_dest}" 395 java-pkg_dojar "${new_jar_dest}"
266} 396}
267 397
268
269# ------------------------------------------------------------------------------ 398# ------------------------------------------------------------------------------
270# @ebuild-function java-pkg_addcp 399# @ebuild-function java-pkg_addcp
271# 400#
272# Add something to the package's classpath. For jars, you should use dojar, 401# 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. 402# newjar, or regjar. This is typically used to add directories to the classpath.
278java-pkg_addcp() { 407java-pkg_addcp() {
279 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}" 408 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
280 java-pkg_do_write_ 409 java-pkg_do_write_
281} 410}
282 411
283
284# ------------------------------------------------------------------------------ 412# ------------------------------------------------------------------------------
285# @ebuild-function java-pkg_doso 413# @ebuild-function java-pkg_doso
286# 414#
287# Installs any number of JNI libraries 415# Installs any number of JNI libraries
288# They will be installed into /usr/lib by default, but java-pkg_sointo 416# They will be installed into /usr/lib by default, but java-pkg_sointo
289# can be used change this path 417# can be used change this path
290# 418#
291# Example: 419# Example:
316 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 444 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
317 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 445 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
318 # otherwise make a symlink to the symlink's origin 446 # otherwise make a symlink to the symlink's origin
319 else 447 else
320 # TODO use dosym 448 # TODO use dosym
449 ln -s "$(readlink "${lib}")" \
321 ln -s "$(readlink "${lib}")" "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")" 450 "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")"
322 debug-print "${lib} is a symlink, linking accordanly" 451 debug-print "${lib} is a symlink, linking accordanly"
323 fi 452 fi
324 # otherwise die 453 # otherwise die
325 else 454 else
326 die "${lib} does not exist" 455 die "${lib} does not exist"
346 java-pkg_check-phase install 475 java-pkg_check-phase install
347 476
348 [[ ${#} -lt 1 ]] && "at least one argument needed" 477 [[ ${#} -lt 1 ]] && "at least one argument needed"
349 478
350 java-pkg_init_paths_ 479 java-pkg_init_paths_
351 480
352 local lib target_dir 481 local lib target_dir
353 for lib in "$@" ; do 482 for lib in "$@" ; do
354 # Check the absolute path of the lib 483 # Check the absolute path of the lib
355 if [[ -e "${lib}" ]] ; then 484 if [[ -e "${lib}" ]] ; then
356 target_dir="$(java-pkg_expand_dir_ ${lib})" 485 target_dir="$(java-pkg_expand_dir_ ${lib})"
404# ------------------------------------------------------------------------------ 533# ------------------------------------------------------------------------------
405java-pkg_dohtml() { 534java-pkg_dohtml() {
406 debug-print-function ${FUNCNAME} $* 535 debug-print-function ${FUNCNAME} $*
407 536
408 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 537 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
409 # TODO-nichoj find out what exactly -f package-list does 538
539 # from /usr/lib/portage/bin/dohtml -h
540 # -f Set list of allowed extensionless file names.
410 dohtml -f package-list "$@" 541 dohtml -f package-list "$@"
542
411 # this probably shouldn't be here but it provides 543 # this probably shouldn't be here but it provides
412 # a reasonable way to catch # docs for all of the 544 # a reasonable way to catch # docs for all of the
413 # old ebuilds. 545 # old ebuilds.
414 java-pkg_recordjavadoc 546 java-pkg_recordjavadoc
415} 547}
416 548
417# TODO document 549# ------------------------------------------------------------------------------
550# @ebuild-function java-pkg_dojavadoc
551#
552# Installs javadoc documentation. This should be controlled by the doc use flag.
553#
554# @param $1: - The javadoc root directory.
555#
556# @example:
557# java-pkg_dojavadoc docs/api
558#
559# ------------------------------------------------------------------------------
418java-pkg_dojavadoc() { 560java-pkg_dojavadoc() {
561 debug-print-function ${FUNCNAME} $*
419 local dir="$1" 562 local dir="$1"
563
564 # QA checks
420 565
421 java-pkg_check-phase install 566 java-pkg_check-phase install
422 567
423 [[ -z "${dir}" ]] && die "Must specify a directory!" 568 [[ -z "${dir}" ]] && die "Must specify a directory!"
424 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!" 569 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!"
570 if [[ ! -e "${dir}/index.html" ]]; then
571 local msg="No index.html in javadoc directory"
572 ewarn "${msg}"
573 is-java-strict && die "${msg}"
574 fi
575
576 # Renaming to match our directory layout
425 577
426 local dir_to_install="${dir}" 578 local dir_to_install="${dir}"
427 if [[ "$(basename "${dir}")" != "api" ]]; then 579 if [[ "$(basename "${dir}")" != "api" ]]; then
428 dir_to_install="${T}/api" 580 dir_to_install="${T}/api"
429 # TODO use doins 581 # TODO use doins
430 cp -r "${dir}" "${dir_to_install}" || die "cp failed" 582 cp -r "${dir}" "${dir_to_install}" || die "cp failed"
431 fi 583 fi
432 584
585 # Actual installation
586
433 java-pkg_dohtml -r ${dir_to_install} 587 java-pkg_dohtml -r ${dir_to_install}
434} 588}
435 589
436# ------------------------------------------------------------------------------ 590# ------------------------------------------------------------------------------
437# @ebuild-function java-pkg_dosrc 591# @ebuild-function java-pkg_dosrc
438# 592#
439# Installs a zip containing the source for a package, so it can used in 593# Installs a zip containing the source for a package, so it can used in
440# from IDEs like eclipse and netbeans. 594# from IDEs like eclipse and netbeans.
441# 595#
442# Ebuild needs to DEPEND on app-arch/zip to use this. 596# Ebuild needs to DEPEND on app-arch/zip to use this.
443# 597#
444# It also should be controlled by USE=source. 598# It also should be controlled by USE=source.
445# 599#
446# @example: 600# @example:
447# java-pkg_dosrc src/* 601# java-pkg_dosrc src/*
448# 602#
449# ------------------------------------------------------------------------------ 603# ------------------------------------------------------------------------------
450# TODO change so it the arguments it takes are the base directories containing 604# TODO change so it the arguments it takes are the base directories containing
451# source -nichoj 605# source -nichoj
452# TODO should we be able to handle multiple calls to dosrc? -nichoj 606# TODO should we be able to handle multiple calls to dosrc? -nichoj
453# TODO maybe we can take an existing zip/jar? -nichoj 607# TODO maybe we can take an existing zip/jar? -nichoj
454# FIXME apparently this fails if you give it an empty directories 608# FIXME apparently this fails if you give it an empty directories
455java-pkg_dosrc() { 609java-pkg_dosrc() {
456 debug-print-function ${FUNCNAME} $* 610 debug-print-function ${FUNCNAME} $*
457 611
458 [ ${#} -lt 1 ] && die "At least one argument needed" 612 [ ${#} -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 613
463 java-pkg_check-phase install 614 java-pkg_check-phase install
464 615
465 [[ ${#} -lt 1 ]] && die "At least one argument needed" 616 [[ ${#} -lt 1 ]] && die "At least one argument needed"
617
618 if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
619 local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
620 if is-java-strict; then
621 eerror "${msg}"
622 die "${msg}"
623 else
624 echo "${msg}"
625 echo "Please report this to http://bugs.gentoo.org."
626 fi
627 fi
466 628
467 java-pkg_init_paths_ 629 java-pkg_init_paths_
468 630
469 local zip_name="${PN}-src.zip" 631 local zip_name="${PN}-src.zip"
470 local zip_path="${T}/${zip_name}" 632 local zip_path="${T}/${zip_name}"
471 local dir 633 local dir
472 for dir in ${@}; do 634 for dir in "${@}"; do
473 local dir_parent=$(dirname "${dir}") 635 local dir_parent=$(dirname "${dir}")
474 local dir_name=$(basename "${dir}") 636 local dir_name=$(basename "${dir}")
475 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 637 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
476 zip -q -r ${zip_path} ${dir_name} -i '*.java' 638 zip -q -r ${zip_path} ${dir_name} -i '*.java'
477 local result=$? 639 local result=$?
494# @ebuild-function java-pkg_dolauncher 656# @ebuild-function java-pkg_dolauncher
495# 657#
496# Make a wrapper script to lauch/start this package 658# Make a wrapper script to lauch/start this package
497# If necessary, the wrapper will switch to the appropriate VM. 659# If necessary, the wrapper will switch to the appropriate VM.
498# 660#
661# Can be called without parameters if the package installs only one jar
662# that has the Main-class attribute set. The wrapper will be named ${PN}.
663#
499# @param $1 - filename of launcher to create 664# @param $1 - filename of launcher to create
500# @param $2 - options, as follows: 665# @param $2 - options, as follows:
501# --main the.main.class.too.start 666# --main the.main.class.too.start
502# --jar /the/jar/too/launch.jar 667# --jar /the/jar/too/launch.jar or just <name>.jar
503# --java_args 'Extra arguments to pass too jave' 668# --java_args 'Extra arguments to pass to java'
504# --pkg_args 'extra arguments too pass too the package' 669# --pkg_args 'Extra arguments to pass to the package'
505# --pwd 670# --pwd Directory the launcher changes to before executing java
506# -into 671# -into Directory to install the launcher to, instead of /usr/bin
507# -pre 672# -pre Prepend contents of this file to the launcher
508# ------------------------------------------------------------------------------ 673# ------------------------------------------------------------------------------
509java-pkg_dolauncher() { 674java-pkg_dolauncher() {
510 debug-print-function ${FUNCNAME} $* 675 debug-print-function ${FUNCNAME} $*
511 676
512 java-pkg_check-phase install 677 java-pkg_check-phase install
513
514 [[ ${#} -lt 1 ]] && die "Need at least one argument"
515
516 java-pkg_init_paths_ 678 java-pkg_init_paths_
517 679
680 if [[ ${#} = 0 ]]; then
681 local name="${PN}"
682 else
518 local name="${1}" 683 local name="${1}"
684 shift
685 fi
686
519 # TODO rename to launcher 687 # TODO rename to launcher
520 local target="${T}/${name}" 688 local target="${T}/${name}"
689 local var_tmp="${T}/launcher_variables_tmp"
521 local target_dir pre 690 local target_dir pre
522 shift
523 691
524 echo "#!/bin/bash" > "${target}" 692 # Process the other the rest of the arguments
525 while [[ -n "${1}" && -n "${2}" ]]; do 693 while [[ -n "${1}" && -n "${2}" ]]; do
526 local var=${1} value=${2} 694 local var="${1}" value="${2}"
527 if [[ "${var:0:2}" == "--" ]]; then 695 if [[ "${var:0:2}" == "--" ]]; then
696 local var=${var:2}
528 echo "gjl_${var:2}=\"${value}\"" >> "${target}" 697 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
698 local gjl_${var}="${value}"
529 elif [[ "${var}" == "-into" ]]; then 699 elif [[ "${var}" == "-into" ]]; then
530 target_dir="${value}" 700 target_dir="${value}"
531 elif [[ "${var}" == "-pre" ]]; then 701 elif [[ "${var}" == "-pre" ]]; then
532 pre="${value}" 702 pre="${value}"
533 fi 703 fi
534 shift 2 704 shift 2
535 done 705 done
706
707 # Test if no --jar and --main arguments were given and
708 # in that case check if the package only installs one jar
709 # and use that jar.
710 if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
711 local cp="${JAVA_PKG_CLASSPATH}"
712 if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
713 echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
714 else
715 local msg="Not enough information to create a launcher given."
716 msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
717 die "${msg}"
718 fi
719 fi
720
721 # Write the actual script
722 echo "#!/bin/bash" > "${target}"
723 if [[ -n "${pre}" ]]; then
724 if [[ -f "${pre}" ]]; then
725 cat "${pre}" >> "${target}"
726 else
727 die "-pre specified file '${pre}' does not exist"
728 fi
729 fi
536 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 730 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
537 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 731 cat "${var_tmp}" >> "${target}"
732 rm -f "${var_tmp}"
538 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 733 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
539 734
540 if [[ -n "${into}" ]]; then 735 if [[ -n "${target_dir}" ]]; then
541 DESTTREE="${target_dir}" dobin "${target}" 736 DESTTREE="${target_dir}" dobin "${target}"
542 local ret=$? 737 local ret=$?
543 return ${ret} 738 return ${ret}
544 else 739 else
545 dobin "${target}" 740 dobin "${target}"
573 echo "dowar: warning, skipping directory ${war}" 768 echo "dowar: warning, skipping directory ${war}"
574 continue 769 continue
575 else 770 else
576 warpath="${war}" 771 warpath="${war}"
577 fi 772 fi
578 773
579 # Install those files like you mean it 774 # Install those files like you mean it
580 INSOPTIONS="-m 0644" \ 775 INSOPTIONS="-m 0644" \
581 INSDESTTREE=${JAVA_PKG_WARDEST} \ 776 INSDESTTREE=${JAVA_PKG_WARDEST} \
582 doins ${warpath} 777 doins ${warpath}
583 done 778 done
618# @ebuild-function java-pkg_jar-from 813# @ebuild-function java-pkg_jar-from
619# 814#
620# Makes a symlink to a jar from a certain package 815# Makes a symlink to a jar from a certain package
621# A lot of java packages include dependencies in a lib/ directory 816# A lot of java packages include dependencies in a lib/ directory
622# You can use this function to replace these bundled dependencies. 817# You can use this function to replace these bundled dependencies.
818# The dependency is recorded into package.env DEPEND line, unless "--build-only"
819# is passed as the very first argument, for jars that have to be present only
820# at build time and are not needed on runtime (junit testing etc).
623# 821#
624# Example: get all jars from xerces slot 2 822# Example: get all jars from xerces slot 2
625# java-pkg_jar-from xerces-2 823# java-pkg_jar-from xerces-2
626# Example: get a specific jar from xerces slot 2 824# Example: get a specific jar from xerces slot 2
627# java-pkg_jar-from xerces-2 xml-apis.jar 825# java-pkg_jar-from xerces-2 xml-apis.jar
628# Example get a specific jar from xerces slot 2, and name it diffrently 826# 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 827# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
828# Example: get junit.jar which is needed only for building
829# java-pkg_jar-from --build-only junit junit.jar
630# 830#
631# @param $1 - Package to get jars from. 831# @param $opt
832# --build-only - makes the jar(s) not added into package.env DEPEND line.
833# (assumed automatically when called inside src_test)
834# --with-dependencies - get jars also from requested package's dependencies
835# transitively.
836# --into $dir - symlink jar(s) into $dir (must exist) instead of .
837# @param $1 - Package to get jars from, or comma-separated list of packages in
838# case other parameters are not used.
632# @param $2 - jar from package. If not specified, all jars will be used. 839# @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 840# @param $3 - When a single jar is specified, destination filename of the
634# symlink. Defaults to the name of the jar. 841# symlink. Defaults to the name of the jar.
635# ------------------------------------------------------------------------------ 842# ------------------------------------------------------------------------------
636# TODO could probably be cleaned up a little 843# TODO could probably be cleaned up a little
637java-pkg_jar-from() { 844java-pkg_jar-from() {
638 debug-print-function ${FUNCNAME} $* 845 debug-print-function ${FUNCNAME} $*
639 846
847 local build_only=""
848 local destdir="."
849 local deep=""
850
851 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
852
853 while [[ "${1}" == --* ]]; do
854 if [[ "${1}" = "--build-only" ]]; then
855 build_only="build"
856 elif [[ "${1}" = "--with-dependencies" ]]; then
857 deep="--with-dependencies"
858 elif [[ "${1}" = "--into" ]]; then
859 destdir="${2}"
860 shift
861 else
862 die "java-pkg_jar-from called with unknown parameter: ${1}"
863 fi
864 shift
865 done
866
640 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 867 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
641 868
642 [[ -z ${target_pkg} ]] && die "Must specify a package" 869 [[ -z ${target_pkg} ]] && die "Must specify a package"
643 870
644 # default destjar to the target jar 871 # default destjar to the target jar
645 [[ -z "${destjar}" ]] && destjar="${target_jar}" 872 [[ -z "${destjar}" ]] && destjar="${target_jar}"
646 873
874 local error_msg="There was a problem getting the classpath for ${target_pkg}."
875 local classpath
647 local classpath="$(java-config --classpath=${target_pkg})" 876 classpath="$(java-config ${deep} --classpath=${target_pkg})"
648 [[ $? != 0 ]] && die "There was a problem getting the classpath for ${target_pkg}" 877 [[ $? != 0 ]] && die ${error_msg}
878
879 # When we have commas this functions is called to bring jars from multiple
880 # packages. This affects recording of dependencencies performed later
881 # which expects one package only, so we do it here.
882 if [[ ${target_pkg} = *,* ]]; then
883 for pkg in ${target_pkg//,/ }; do
884 java-pkg_ensure-dep "${build_only}" "${pkg}"
885 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
886 done
887 # setting this disables further record-jar_ calls later
888 build_only="build"
889 else
890 java-pkg_ensure-dep "${build_only}" "${target_pkg}"
891 fi
892
893 pushd ${destdir} > /dev/null \
894 || die "failed to change directory to ${destdir}"
649 895
650 local jar 896 local jar
651 for jar in ${classpath//:/ }; do 897 for jar in ${classpath//:/ }; do
652 local jar_name=$(basename "${jar}") 898 local jar_name=$(basename "${jar}")
653 if [[ ! -f "${jar}" ]] ; then 899 if [[ ! -f "${jar}" ]] ; then
657 # If no specific target jar was indicated, link it 903 # If no specific target jar was indicated, link it
658 if [[ -z "${target_jar}" ]] ; then 904 if [[ -z "${target_jar}" ]] ; then
659 [[ -f "${target_jar}" ]] && rm "${target_jar}" 905 [[ -f "${target_jar}" ]] && rm "${target_jar}"
660 ln -snf "${jar}" \ 906 ln -snf "${jar}" \
661 || die "Failed to make symlink from ${jar} to ${jar_name}" 907 || die "Failed to make symlink from ${jar} to ${jar_name}"
662 java-pkg_record-jar_ "${target_pkg}" "${jar}" 908 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
663 # otherwise, if the current jar is the target jar, link it 909 # otherwise, if the current jar is the target jar, link it
664 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 910 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
665 [[ -f "${destjar}" ]] && rm "${destjar}" 911 [[ -f "${destjar}" ]] && rm "${destjar}"
666 ln -snf "${jar}" "${destjar}" \ 912 ln -snf "${jar}" "${destjar}" \
667 || die "Failed to make symlink from ${jar} to ${destjar}" 913 || die "Failed to make symlink from ${jar} to ${destjar}"
668 java-pkg_record-jar_ "${target_pkg}" "${jar}" 914 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
915 popd > /dev/null
669 return 0 916 return 0
670 fi 917 fi
671 done 918 done
919 popd > /dev/null
672 # if no target was specified, we're ok 920 # if no target was specified, we're ok
673 if [[ -z "${target_jar}" ]] ; then 921 if [[ -z "${target_jar}" ]] ; then
674 return 0 922 return 0
675 # otherwise, die bitterly 923 # otherwise, die bitterly
676 else 924 else
690# ------------------------------------------------------------------------------ 938# ------------------------------------------------------------------------------
691# @ebuild-function java-pkg_getjars 939# @ebuild-function java-pkg_getjars
692# 940#
693# Get the classpath provided by any number of packages 941# Get the classpath provided by any number of packages
694# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'. 942# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
943# The providing packages are recorded as dependencies into package.env DEPEND
944# line, unless "--build-only" is passed as the very first argument, for jars
945# that have to be present only at build time and are not needed on runtime
946# (junit testing etc).
695# 947#
696# Example: Get the classpath for xerces-2, 948# Example: Get the classpath for xerces-2 and xalan,
697# java-pkg_getjars xerces-2 xalan 949# java-pkg_getjars xerces-2,xalan
698# Example Return: 950# Example Return:
699# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 951# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
700# 952#
953# @param $opt
954# --build-only - makes the jar(s) not added into package.env DEPEND line.
955# (assumed automatically when called inside src_test)
956# --with-dependencies - get jars also from requested package's dependencies
957# transitively.
701# @param $@ - list of packages to get jars from 958# @param $1 - list of packages to get jars from
959# (passed to java-config --classpath)
702# ------------------------------------------------------------------------------ 960# ------------------------------------------------------------------------------
703java-pkg_getjars() { 961java-pkg_getjars() {
704 debug-print-function ${FUNCNAME} $* 962 debug-print-function ${FUNCNAME} $*
705 963
706 [[ ${#} -lt 1 ]] && die "At least one argument needed" 964 local build_only=""
965 local deep=""
707 966
708 # NOTE could probably just pass $@ to java-config --classpath. and return it 967 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
709 local classpath pkg 968
710 for pkg in ${@//,/ }; do 969 while [[ "${1}" == --* ]]; do
711 #for pkg in $(echo "$@" | tr ',' ' '); do 970 if [[ "${1}" = "--build-only" ]]; then
712 jars="$(java-config --classpath=${pkg})" 971 build_only="build"
713 debug-print "${pkg}:${jars}" 972 elif [[ "${1}" = "--with-dependencies" ]]; then
714 # TODO should we ensure jars exist? 973 deep="--with-dependencies"
715 if [[ -z "${classpath}" ]]; then
716 classpath="${jars}"
717 else 974 else
718 classpath="${classpath}:${jars}" 975 die "java-pkg_jar-from called with unknown parameter: ${1}"
719 fi 976 fi
720 java-pkg_record-jar_ "${pkg}" 977 shift
721 done 978 done
979
980 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
981
982
983 local classpath pkgs="${1}"
984 jars="$(java-config ${deep} --classpath=${pkgs})"
985 [[ $? != 0 || -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed"
986 debug-print "${pkgs}:${jars}"
987
988 for pkg in ${pkgs//,/ }; do
989 java-pkg_ensure-dep "${build_only}" "${pkg}"
990 done
991
992 if [[ -z "${classpath}" ]]; then
993 classpath="${jars}"
994 else
995 classpath="${classpath}:${jars}"
996 fi
997
998 # Only record jars that aren't build-only
999 if [[ -z "${build_only}" ]]; then
1000 for pkg in ${pkgs//,/ }; do
1001 java-pkg_record-jar_ "${pkg}"
1002 done
1003 fi
1004
722 echo "${classpath}" 1005 echo "${classpath}"
723} 1006}
724 1007
725# ------------------------------------------------------------------------------ 1008# ------------------------------------------------------------------------------
726# @ebuild-function java-pkg_getjar 1009# @ebuild-function java-pkg_getjar
727# 1010#
728# Get the filename of a single jar from a package 1011# Get the filename of a single jar from a package
1012# The providing package is recorded as runtime dependency into package.env
1013# DEPEND line, unless "--build-only" is passed as the very first argument, for
1014# jars that have to be present only at build time and are not needed on runtime
1015# (junit testing etc).
729# 1016#
730# @example 1017# @example
731# java-pkg_getjar xerces-2 xml-apis.jar 1018# java-pkg_getjar xerces-2 xml-apis.jar
732# @example-return 1019# @example-return
733# /usr/share/xerces-2/lib/xml-apis.jar 1020# /usr/share/xerces-2/lib/xml-apis.jar
734# 1021#
1022# @param $opt
1023# --build-only - makes the jar not added into package.env DEPEND line.
735# @param $1 - package to use 1024# @param $1 - package to use
736# @param $2 - jar to get 1025# @param $2 - jar to get
737# ------------------------------------------------------------------------------ 1026# ------------------------------------------------------------------------------
738java-pkg_getjar() { 1027java-pkg_getjar() {
739 debug-print-function ${FUNCNAME} $* 1028 debug-print-function ${FUNCNAME} $*
1029
1030 local build_only=""
1031
1032 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1033
1034 while [[ "${1}" == --* ]]; do
1035 if [[ "${1}" = "--build-only" ]]; then
1036 build_only="build"
1037 else
1038 die "java-pkg_jar-from called with unknown parameter: ${1}"
1039 fi
1040 shift
1041 done
1042
1043 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
740 1044
741 local pkg="${1}" target_jar="${2}" jar 1045 local pkg="${1}" target_jar="${2}" jar
742 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 1046 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
743 [[ -z ${target_jar} ]] && die "Must specify jar to get" 1047 [[ -z ${target_jar} ]] && die "Must specify jar to get"
744 1048
745 # TODO check that package is actually installed 1049 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
1050 local classpath
746 local classpath=$(java-config --classpath=${pkg}) 1051 classpath=$(java-config --classpath=${pkg})
747 [[ $? != 0 ]] && die "There could not find classpath for ${pkg}. Are you sure its installed?" 1052 [[ $? != 0 ]] && die ${error_msg}
1053
1054 java-pkg_ensure-dep "${build_only}" "${pkg}"
1055
748 for jar in ${classpath//:/ }; do 1056 for jar in ${classpath//:/ }; do
749 if [[ ! -f "${jar}" ]] ; then 1057 if [[ ! -f "${jar}" ]] ; then
750 die "Installation problems with jars in ${pkg} - is it installed?" 1058 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
751 fi 1059 fi
752 1060
753 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then 1061 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
754 java-pkg_record-jar_ "${pkg}" "${jar}" 1062 # Only record jars that aren't build-only
1063 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" "${jar}"
755 echo "${jar}" 1064 echo "${jar}"
756 return 0 1065 return 0
757 fi 1066 fi
758 done 1067 done
759 1068
760 die "Could not find ${target_jar} in ${pkg}" 1069 die "Could not find ${target_jar} in ${pkg}"
761 return 1 1070 return 1
1071}
1072
1073# ------------------------------------------------------------------------------
1074# @ebuild-function java-pkg_register-dependency
1075#
1076# Registers runtime dependency on a package, list of packages, or a single jar
1077# from a package, into package.env DEPEND line. Can only be called in
1078# src_install phase.
1079# Intended for binary packages where you don't need to symlink the jars or get
1080# their classpath during build. As such, the dependencies only need to be
1081# specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1082# Get the classpath provided by any number of packages.
1083#
1084# @param $1 - comma-separated list of packages, or a single package
1085# @param $2 - if param $1 is a single package, optionally specify the jar
1086# to depend on
1087#
1088# Example: Record the dependency on whole xerces-2 and xalan,
1089# java-pkg_register-dependency xerces-2,xalan
1090# Example: Record the dependency on ant.jar from ant-core
1091# java-pkg_register-dependency ant-core ant.jar
1092#
1093# Note: Passing both list of packages as the first parameter AND specifying the
1094# jar as the second is not allowed and will cause the function to die. We assume
1095# that there's more chance one passes such combination as a mistake, than that
1096# there are more packages providing identically named jar without class
1097# collisions.
1098# ------------------------------------------------------------------------------
1099java-pkg_register-dependency() {
1100 debug-print-function ${FUNCNAME} $*
1101
1102 java-pkg_check-phase install
1103
1104 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1105
1106 local pkgs="${1}"
1107 local jar="${2}"
1108
1109 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1110
1111 if [[ -z "${jar}" ]]; then
1112 for pkg in ${pkgs//,/ }; do
1113 java-pkg_ensure-dep runtime "${pkg}"
1114 java-pkg_record-jar_ "${pkg}"
1115 done
1116 else
1117 [[ ${pkgs} == *,* ]] && \
1118 die "${FUNCNAME} called with both package list and jar name"
1119 java-pkg_ensure-dep runtime "${pkgs}"
1120 java-pkg_record-jar_ "${pkgs}" "${jar}"
1121 fi
1122
1123 java-pkg_do_write_
762} 1124}
763 1125
764# This function reads stdin, and based on that input, figures out how to 1126# This function reads stdin, and based on that input, figures out how to
765# populate jars from the filesystem. 1127# populate jars from the filesystem.
766# Need to figure out a good way of making use of this, ie be able to use a 1128# Need to figure out a good way of making use of this, ie be able to use a
778# line="${line// /}" 1140# line="${line// /}"
779# 1141#
780# # format: path=jarinfo 1142# # format: path=jarinfo
781# local path=${line%%=*} 1143# local path=${line%%=*}
782# local jarinfo=${line##*=} 1144# local jarinfo=${line##*=}
783# 1145#
784# # format: jar@package 1146# # format: jar@package
785# local jar=${jarinfo%%@*}.jar 1147# local jar=${jarinfo%%@*}.jar
786# local package=${jarinfo##*@} 1148# local package=${jarinfo##*@}
787# if [[ -n ${replace_only} ]]; then 1149# if [[ -n ${replace_only} ]]; then
788# [[ ! -f $path ]] && die "No jar exists at ${path}" 1150# [[ ! -f $path ]] && die "No jar exists at ${path}"
801# @section-end query 1163# @section-end query
802# ------------------------------------------------------------------------------ 1164# ------------------------------------------------------------------------------
803 1165
804# ------------------------------------------------------------------------------ 1166# ------------------------------------------------------------------------------
805# @section-begin helper 1167# @section-begin helper
806# @section-summary Helper functions 1168# @section-summary Helper functions
807# 1169#
808# Various other functions to use from an ebuild 1170# Various other functions to use from an ebuild
809# ------------------------------------------------------------------------------ 1171# ------------------------------------------------------------------------------
810 1172
811# ------------------------------------------------------------------------------ 1173# ------------------------------------------------------------------------------
817# jdbc-stdext 1179# jdbc-stdext
818# jaf 1180# jaf
819# jdbc-rowset 1181# jdbc-rowset
820# jms 1182# jms
821# 1183#
822# @param $1 - Optionally indicate that the dependencies are controlled by 1184# @param $1 - Optionally indicate that the dependencies are controlled by
823# a use flag by specifying '--use' Requires $2. 1185# a use flag by specifying '--use' Requires $2.
824# @param $2 - USE flag which will enable the dependencies. 1186# @param $2 - USE flag which will enable the dependencies.
825# @param $@ - virtual packages to add depenedencies for 1187# @param $@ - virtual packages to add depenedencies for
826# ------------------------------------------------------------------------------ 1188# ------------------------------------------------------------------------------
827# TODO rewrite to parse a line based declaration file instead -- karltk 1189# TODO rewrite to parse a line based declaration file instead -- karltk
883# 1245#
884# export DEPEND="${DEPEND} ${depstr}" 1246# export DEPEND="${DEPEND} ${depstr}"
885# export RDEPEND="${RDEPEND} ${depstr}" 1247# export RDEPEND="${RDEPEND} ${depstr}"
886#} 1248#}
887 1249
1250# ------------------------------------------------------------------------------
1251# @ebuild-function java-pkg_find-normal-jars
1252#
1253# Find the files with suffix .jar file in the given directory or $WORKDIR
1254#
1255# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1256# ------------------------------------------------------------------------------
1257java-pkg_find-normal-jars() {
1258 local dir=$1
1259 [[ "${dir}" ]] || dir="${WORKDIR}"
1260 local found
1261 for jar in $(find "${dir}" -name "*.jar" -type f); do
1262 echo "${jar}"
1263 found="true"
1264 done
1265 [[ "${found}" ]]
1266 return $?
1267}
1268
1269# ------------------------------------------------------------------------------
1270# @ebuild-function java-pkg_ensure-no-bundled-jars
1271#
1272# 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 1273# This function should be called after WORKDIR has been populated with symlink
889# TODO document 1274# to system jar files or bundled jars removed.
1275# ------------------------------------------------------------------------------
890java-pkg_ensure-no-bundled-jars() { 1276java-pkg_ensure-no-bundled-jars() {
891 debug-print-function ${FUNCNAME} $* 1277 debug-print-function ${FUNCNAME} $*
892 pushd ${WORKDIR} >/dev/null 2>/dev/null
893 1278
894 local bundled_jars=$(find . -name "*.jar" -type f) 1279 local bundled_jars=$(java-pkg_find-normal-jars)
895 if [[ -n ${bundled_jars} ]]; then 1280 if [[ -n ${bundled_jars} ]]; then
896 echo "Bundled jars found:" 1281 echo "Bundled jars found:"
897 local jar 1282 local jar
898 for jar in ${bundled_jars}; do 1283 for jar in ${bundled_jars}; do
899 echo $(pwd)${jar/./} 1284 echo $(pwd)${jar/./}
900 done 1285 done
901 die "Bundled jars found!" 1286 die "Bundled jars found!"
902
903 fi 1287 fi
904 popd >/dev/null 2>/dev/null
905} 1288}
906 1289
907# ------------------------------------------------------------------------------ 1290# ------------------------------------------------------------------------------
908# @internal-function java-pkg_ensure-vm-version-sufficient 1291# @internal-function java-pkg_ensure-vm-version-sufficient
909# 1292#
921 fi 1304 fi
922} 1305}
923 1306
924# ------------------------------------------------------------------------------ 1307# ------------------------------------------------------------------------------
925# @internal-function java-pkg_is-vm-version-sufficient 1308# @internal-function java-pkg_is-vm-version-sufficient
926# 1309#
927# @return zero - VM is sufficient 1310# @return zero - VM is sufficient
928# @return non-zero - VM is not sufficient 1311# @return non-zero - VM is not sufficient
929# ------------------------------------------------------------------------------ 1312# ------------------------------------------------------------------------------
930java-pkg_is-vm-version-sufficient() { 1313java-pkg_is-vm-version-sufficient() {
931 debug-print-function ${FUNCNAME} $* 1314 debug-print-function ${FUNCNAME} $*
951 die "Active Java VM too old" 1334 die "Active Java VM too old"
952 fi 1335 fi
953} 1336}
954 1337
955# ------------------------------------------------------------------------------ 1338# ------------------------------------------------------------------------------
956# @internal-function java-pkg_is-vm-version-eq 1339# @internal-function java-pkg_is-vm-version-eq
957# 1340#
958# @param $@ - VM version to compare current VM to 1341# @param $@ - VM version to compare current VM to
959# @return zero - VM versions are equal 1342# @return zero - VM versions are equal
960# @return non-zero - VM version are not equal 1343# @return non-zero - VM version are not equal
961# ------------------------------------------------------------------------------ 1344# ------------------------------------------------------------------------------
962java-pkg_is-vm-version-eq() { 1345java-pkg_is-vm-version-eq() {
992# 1375#
993# @param $@ - VM version to compare current to 1376# @param $@ - VM version to compare current to
994# ------------------------------------------------------------------------------ 1377# ------------------------------------------------------------------------------
995java-pkg_ensure-vm-version-ge() { 1378java-pkg_ensure-vm-version-ge() {
996 debug-print-function ${FUNCNAME} $* 1379 debug-print-function ${FUNCNAME} $*
997 1380
998 if ! java-pkg_is-vm-version-ge "$@" ; then 1381 if ! java-pkg_is-vm-version-ge "$@" ; then
999 debug-print "vm is not suffient" 1382 debug-print "vm is not suffient"
1000 eerror "This package requires a Java VM version >= $@" 1383 eerror "This package requires a Java VM version >= $@"
1001 einfo "Please use java-config -S to set the correct one" 1384 einfo "Please use java-config -S to set the correct one"
1002 die "Active Java VM too old" 1385 die "Active Java VM too old"
1003 fi 1386 fi
1004} 1387}
1005 1388
1006# ------------------------------------------------------------------------------ 1389# ------------------------------------------------------------------------------
1007# @internal-function java-pkg_is-vm-version-ge 1390# @internal-function java-pkg_is-vm-version-ge
1008# 1391#
1009# @param $@ - VM version to compare current VM to 1392# @param $@ - VM version to compare current VM to
1010# @return zero - current VM version is greater than checked version 1393# @return zero - current VM version is greater than checked version
1011# @return non-zero - current VM version is not greater than checked version 1394# @return non-zero - current VM version is not greater than checked version
1012# ------------------------------------------------------------------------------ 1395# ------------------------------------------------------------------------------
1013java-pkg_is-vm-version-ge() { 1396java-pkg_is-vm-version-ge() {
1027 return 1 1410 return 1
1028 fi 1411 fi
1029 fi 1412 fi
1030} 1413}
1031 1414
1415java-pkg_set-current-vm() {
1416 export GENTOO_VM=${1}
1417}
1418
1419java-pkg_get-current-vm() {
1420 echo ${GENTOO_VM}
1421}
1422
1423java-pkg_current-vm-matches() {
1424 hasq $(java-pkg_get-current-vm) ${@}
1425 return $?
1426}
1427
1032# ------------------------------------------------------------------------------ 1428# ------------------------------------------------------------------------------
1033# @ebuild-function java-pkg_get-source 1429# @ebuild-function java-pkg_get-source
1034# 1430#
1035# Determines what source version should be used, for passing to -source. 1431# 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 1432# Unless you want to break things you probably shouldn't set _WANT_SOURCE
1037# 1433#
1038# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE 1434# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1039# ------------------------------------------------------------------------------ 1435# ------------------------------------------------------------------------------
1044# ------------------------------------------------------------------------------ 1440# ------------------------------------------------------------------------------
1045# @ebuild-function java-pkg_get-target 1441# @ebuild-function java-pkg_get-target
1046# 1442#
1047# Determines what target version should be used, for passing to -target. 1443# 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 1444# If you don't care about lower versions, you can set _WANT_TARGET to the
1049# version of your JDK. 1445# 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# 1446#
1054# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1447# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1055# ------------------------------------------------------------------------------ 1448# ------------------------------------------------------------------------------
1056java-pkg_get-target() { 1449java-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}")} 1450 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1070} 1451}
1071 1452
1072java-pkg_get-javac() { 1453java-pkg_get-javac() {
1073 debug-print-function ${FUNCNAME} $* 1454 debug-print-function ${FUNCNAME} $*
1074 1455
1075 java-pkg_init-compiler_ 1456
1076 local compiler="${GENTOO_COMPILER}" 1457 local compiler="${GENTOO_COMPILER}"
1077 1458
1078 local compiler_executable 1459 local compiler_executable
1079 if [[ "${compiler}" = "javac" ]]; then 1460 if [[ "${compiler}" = "javac" ]]; then
1080 # nothing fancy needs to be done for javac 1461 # nothing fancy needs to be done for javac
1088 unset JAVAC 1469 unset JAVAC
1089 # try to get value of JAVAC 1470 # try to get value of JAVAC
1090 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1471 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1091 export JAVAC=${old_javac} 1472 export JAVAC=${old_javac}
1092 1473
1093 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1474 if [[ -z ${compiler_executable} ]]; then
1094 1475 echo "JAVAC is empty or undefined in ${compiler_env}"
1476 return 1
1477 fi
1478
1095 # check that it's executable 1479 # check that it's executable
1096 if [[ ! -x ${compiler_executable} ]]; then 1480 if [[ ! -x ${compiler_executable} ]]; then
1097 eerror "Could not find ${compiler_executable}!"
1098 die "${compiler_executable} doesn't exist, or isn't executable" 1481 echo "${compiler_executable} doesn't exist, or isn't executable"
1482 return 1
1099 fi 1483 fi
1100 else 1484 else
1101 eerror "Could not find environment file for ${compiler}" 1485 echo "Could not find environment file for ${compiler}"
1102 die "Could not find ${compiler_env}" 1486 return 1
1103 fi 1487 fi
1104 fi 1488 fi
1105 echo ${compiler_executable} 1489 echo ${compiler_executable}
1106} 1490}
1107 1491
1108# ------------------------------------------------------------------------------ 1492# ------------------------------------------------------------------------------
1109# @ebuild-function java-pkg_javac-args 1493# @ebuild-function java-pkg_javac-args
1110# 1494#
1111# If an ebuild uses javac directly, instead of using ejavac, it should call this 1495# If an ebuild uses javac directly, instead of using ejavac, it should call this
1112# to know what -source/-target to use. 1496# to know what -source/-target to use.
1113# 1497#
1114# @return string - arguments to pass to javac, complete with -target and -source 1498# @return string - arguments to pass to javac, complete with -target and -source
1117 debug-print-function ${FUNCNAME} $* 1501 debug-print-function ${FUNCNAME} $*
1118 1502
1119 local want_source="$(java-pkg_get-source)" 1503 local want_source="$(java-pkg_get-source)"
1120 local want_target="$(java-pkg_get-target)" 1504 local want_target="$(java-pkg_get-target)"
1121 1505
1122 local source_str="-source ${want_source}" 1506 local source_str="-source ${want_source}"
1123 local target_str="-target ${want_target}" 1507 local target_str="-target ${want_target}"
1124 1508
1125 debug-print "want source: ${want_source}" 1509 debug-print "want source: ${want_source}"
1126 debug-print "want target: ${want_target}" 1510 debug-print "want target: ${want_target}"
1127 1511
1128 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1512 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1129 debug-print "could not find valid -source/-target values" 1513 debug-print "could not find valid -source/-target values for javac"
1130 die "Could not find valid -source/-target values" 1514 echo "Could not find valid -source/-target values for javac"
1515 return 1
1131 else 1516 else
1132 if java-pkg_is-vm-version-ge "1.4"; then 1517 if java-pkg_is-vm-version-ge "1.4"; then
1133 echo "${source_str} ${target_str}" 1518 echo "${source_str} ${target_str}"
1134 else 1519 else
1135 echo "${target_str}" 1520 echo "${target_str}"
1139 1524
1140# TODO document 1525# TODO document
1141java-pkg_get-jni-cflags() { 1526java-pkg_get-jni-cflags() {
1142 local flags="-I${JAVA_HOME}/include" 1527 local flags="-I${JAVA_HOME}/include"
1143 1528
1144 # TODO figure out how to cope with other things than linux... 1529 local platform="linux"
1530 use elibc_FreeBSD && platform="freebsd"
1531
1532 # TODO do a check that the directories are valid
1145 flags="${flags} -I${JAVA_HOME}/include/linux" 1533 flags="${flags} -I${JAVA_HOME}/include/${platform}"
1146 1534
1147 echo ${flags} 1535 echo ${flags}
1536}
1537
1538java-pkg_ensure-gcj() {
1539 if ! built_with_use sys-devel/gcc gcj ; then
1540 ewarn
1541 ewarn "You must build gcc with the gcj support to build with gcj"
1542 ewarn
1543 ebeep 5
1544 die "No GCJ support found!"
1545 fi
1546}
1547
1548java-pkg_ensure-test() {
1549 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \
1550 && hasq test ${IUSE} && ! use test;
1551 then
1552 eerror "You specified FEATURES=test, but USE=test is needed"
1553 eerror "to pull in the additional dependencies for testing"
1554 die "Need USE=test enabled"
1555 fi
1556}
1557
1558# ------------------------------------------------------------------------------
1559# @ebuild-function java-pkg_register-ant-task
1560#
1561# Register this package as ant task, so that ant will load it when no specific
1562# ANT_TASKS are specified. Note that even without this registering, all packages
1563# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1564# packages, but can be also used by other ebuilds that used to symlink their
1565# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1566# compatibility.
1567#
1568# @param --version x.y Register only for ant version x.y (otherwise for any ant
1569# version). Used by the ant-* packages to prevent loading of mismatched
1570# ant-core ant tasks after core was updated, before the tasks are updated,
1571# without a need for blockers.
1572# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1573# ------------------------------------------------------------------------------
1574java-pkg_register-ant-task() {
1575 local TASKS_DIR="tasks"
1576
1577 # check for --version x.y parameters
1578 while [[ -n "${1}" && -n "${2}" ]]; do
1579 local var="${1#--}"
1580 local val="${2}"
1581 if [[ "${var}" == "version" ]]; then
1582 TASKS_DIR="tasks-${val}"
1583 else
1584 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1585 fi
1586 shift 2
1587 done
1588
1589 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1590
1591 dodir /usr/share/ant/${TASKS_DIR}
1592 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1593}
1594
1595# ------------------------------------------------------------------------------
1596# @internal-function java-pkg_ant-tasks-from-deps
1597#
1598# Function to determine ANT_TASKS from DEPEND variable for backwards
1599# compatibility with ebuilds that don't set ANT_TASKS before calling eant() or
1600# WANT_ANT_TASKS before inheriting java-pkg-2. If the DEPEND string contains
1601# "dev-java/ant" or "dev-java/ant-tasks", then it returns "all", otherwise
1602# "none". It's not smart enough to cope with USE flag depends but that shouldn't
1603# be a problem, the worst it can do is activace all tasks when not needed.
1604# Note that this is called only with JAVA_PKG_STRICT=1, to find ebuilds with
1605# insufficient dependencies, otherwise all available tasks are used for
1606# backwards compatilbility.
1607#
1608# @return "all" or "none"
1609# ------------------------------------------------------------------------------
1610java-pkg_ant-tasks-from-deps() {
1611 local found_ant found_ant_tasks
1612
1613 for dep in ${DEPEND}
1614 do
1615 local ant="$(awk '/(dev-java\/ant)/ { if (match($1, "(dev-java/ant)((-[0-9])+|$)", m)) print m[1] }' <<< ${dep})"
1616 [[ "${ant}" == "dev-java/ant" ]] && found_ant=true
1617 [[ "${dep}" == *"ant-tasks"* ]] && found_ant_tasks=true
1618 done
1619
1620 if [[ -n "${found_ant}" || -n "${found_ant_tasks}" ]]; then
1621 java-pkg_announce-qa-violation --nodie "The ebuild DEPENDS on deprecated ant or ant-tasks"
1622 echo "all"
1623 else
1624 # ebuild doesn't set ANT_TASKS and doesn't depend on ant-tasks or ant
1625 # so we deactivate all tasks that may be installed
1626 echo "none"
1627 fi
1628}
1629
1630# ------------------------------------------------------------------------------
1631# @internal-function java-pkg_ant-tasks-depend
1632#
1633# Translates the WANT_ANT_TASKS variable into valid dependencies.
1634# ------------------------------------------------------------------------------
1635java-pkg_ant-tasks-depend() {
1636 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1637
1638 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1639 local DEP=""
1640 for i in ${WANT_ANT_TASKS}
1641 do
1642 if [[ ${i} != ant-* ]]; then
1643 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1644 return 1
1645 fi
1646 DEP="${DEP}dev-java/${i} "
1647 done
1648 echo ${DEP}
1649 return 0
1650 else
1651 return 0
1652 fi
1148} 1653}
1149 1654
1150# ------------------------------------------------------------------------------ 1655# ------------------------------------------------------------------------------
1151# @section-end helper 1656# @section-end helper
1152# ------------------------------------------------------------------------------ 1657# ------------------------------------------------------------------------------
1161 1666
1162# ------------------------------------------------------------------------------ 1667# ------------------------------------------------------------------------------
1163# @ebuild-function eant 1668# @ebuild-function eant
1164# 1669#
1165# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1670# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1166# compiler. 1671# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1167# 1672# variables:
1673# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1674# gentoo.classpath property. Be sure to call
1675# java-ant_rewrite-classpath in src_unpack.
1676# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1168# ------------------------------------------------------------------------------ 1677# ------------------------------------------------------------------------------
1169eant() { 1678eant() {
1170 debug-print-function ${FUNCNAME} $* 1679 debug-print-function ${FUNCNAME} $*
1171 1680
1172 local antflags 1681 if ! hasq java-ant-2 ${INHERITED}; then
1682 local msg="You should inherit java-ant-2 when using eant"
1683 java-pkg_announce-qa-violation "${msg}"
1684 fi
1685
1686 local antflags="-Dnoget=true -Dmaven.mode.offline=true"
1687
1173 java-pkg_init-compiler_ 1688 java-pkg_init-compiler_
1174 local compiler="${GENTOO_COMPILER}" 1689 local compiler="${GENTOO_COMPILER}"
1175 1690
1176 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1691 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1177 1692
1179 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1694 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1180 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1695 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1181 fi 1696 fi
1182 1697
1183 if [[ ${compiler} != "javac" ]]; then 1698 if [[ ${compiler} != "javac" ]]; then
1184 antflags="-Dbuild.compiler=${build_compiler}" 1699 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1185 # Figure out any extra stuff to put on the classpath for compilers aside 1700 # Figure out any extra stuff to put on the classpath for compilers aside
1186 # from javac 1701 # from javac
1187 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to 1702 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1188 # java-config -p 1703 # java-config -p
1189 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1704 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 1705 if [[ -n ${build_compiler_deps} ]]; then
1191 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})" 1706 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1192 fi 1707 fi
1193 fi 1708 fi
1194 1709
1195 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1710 if is-java-strict; then
1196 antflags="${antflags} -debug" 1711 einfo "Disabling system classpath for ant"
1712 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1713 fi
1714
1715 for arg in "${@}"; do
1716 if [[ ${arg} = -lib ]]; then
1717 if is-java-strict; then
1718 eerror "You should not use the -lib argument to eant because it will fail"
1719 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1720 eerror "or ant properties to make dependencies available."
1721 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1722 eerror "split ant (>=dev-java/ant-core-1.7)."
1723 die "eant -lib is deprecated/forbidden"
1724 else
1725 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1726 echo "more info."
1727 fi
1197 fi 1728 fi
1198 1729 done
1730
1731 if has_version ">=dev-java/ant-core-1.7.0"; then
1732 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1733 ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}"
1734
1735 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1736 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1737
1738 if is-java-strict; then
1739 # if ant-tasks were not set by ebuild or forced, try to determine them from depends
1740 if [[ -z "${ANT_TASKS}" ]]; then
1741 ANT_TASKS="$(java-pkg_ant-tasks-from-deps)"
1742 fi
1743 else
1744 # if ant-tasks is not set by ebuild or forced, activate all of them
1745 ANT_TASKS="${ANT_TASKS:-all}"
1746 fi
1747
1748 # at this point, ANT_TASKS should be "all", "none" or explicit list
1749 if [[ "${ANT_TASKS}" == "all" ]]; then
1750 einfo "Using all available ANT_TASKS"
1751 elif [[ "${ANT_TASKS}" == "none" ]]; then
1752 einfo "Disabling all optional ANT_TASKS"
1753 else
1754 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1755 fi
1756
1757 export ANT_TASKS
1758 fi
1759
1760 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1761 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1762
1763 local gcp="${EANT_GENTOO_CLASSPATH}"
1764 local getjarsarg=""
1765
1766 if [[ ${EBUILD_PHASE} = "test" ]]; then
1767 antflags="${antflags} -DJunit.present=true"
1768 [[ ${gcp} && ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1769 getjarsarg="--with-dependencies"
1770 fi
1771
1772 local cp
1773
1774 for atom in ${gcp}; do
1775 cp="${cp}:$(java-pkg_getjars ${getjarsarg} ${atom})"
1776 done
1777
1778 if [[ ${cp} ]]; then
1779 # It seems ant does not like single quotes around ${cp}
1780 antflags="${antflags} -Dgentoo.classpath=\"${cp#:}\""
1781 fi
1782
1199 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1783 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1784 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
1200 ant ${antflags} "${@}" || die "eant failed" 1785 ant ${antflags} "${@}" || die "eant failed"
1201
1202} 1786}
1203 1787
1204# ------------------------------------------------------------------------------ 1788# ------------------------------------------------------------------------------
1205# @ebuild-function ejavac 1789# @ebuild-function ejavac
1206# 1790#
1207# Javac wrapper function. Will use the appropriate compiler, based on 1791# Javac wrapper function. Will use the appropriate compiler, based on
1208# /etc/java-config/compilers.conf 1792# /etc/java-config/compilers.conf
1209# 1793#
1210# @param $@ - Arguments to be passed to the compiler 1794# @param $@ - Arguments to be passed to the compiler
1211# ------------------------------------------------------------------------------ 1795# ------------------------------------------------------------------------------
1212ejavac() { 1796ejavac() {
1213 debug-print-function ${FUNCNAME} $* 1797 debug-print-function ${FUNCNAME} $*
1214 1798
1799 java-pkg_init-compiler_
1800
1801 local compiler_executable
1215 local compiler_executable=$(java-pkg_get-javac) 1802 compiler_executable=$(java-pkg_get-javac)
1803 if [[ ${?} != 0 ]]; then
1804 eerror "There was a problem determining compiler: ${compiler_executable}"
1805 die "get-javac failed"
1806 fi
1216 1807
1808 local javac_args
1809 javac_args="$(java-pkg_javac-args)"
1810 if [[ ${?} != 0 ]]; then
1811 eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
1812 die "java-pkg_javac-args failed"
1813 fi
1814
1217 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 1815 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1218 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 1816 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1219} 1817}
1220 1818
1221# ------------------------------------------------------------------------------ 1819# ------------------------------------------------------------------------------
1222# @ebuild-function java-pkg_filter-compiler 1820# @ebuild-function java-pkg_filter-compiler
1223# 1821#
1224# Used to prevent the use of some compilers. Should be used in src_compile. 1822# Used to prevent the use of some compilers. Should be used in src_compile.
1225# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER 1823# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
1226# 1824#
1227# @param $@ - compilers to filter 1825# @param $@ - compilers to filter
1228# ------------------------------------------------------------------------------ 1826# ------------------------------------------------------------------------------
1229java-pkg_filter-compiler() { 1827java-pkg_filter-compiler() {
1230 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@" 1828 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@"
1231} 1829}
1232 1830
1233# ------------------------------------------------------------------------------ 1831# ------------------------------------------------------------------------------
1832# @ebuild-function java-pkg_force-compiler
1833#
1834# Used to force the use of particular compilers. Should be used in src_compile.
1835# A common use of this would be to force ecj-3.1 to be used on amd64, to avoid
1836# OutOfMemoryErrors that may come up.
1837#
1838# @param $@ - compilers to force
1839# ------------------------------------------------------------------------------
1840java-pkg_force-compiler() {
1841 JAVA_PKG_FORCE_COMPILER="$@"
1842}
1843
1844# ------------------------------------------------------------------------------
1234# @ebuild-function use_doc 1845# @ebuild-function use_doc
1235# 1846#
1236# Helper function for getting ant to build javadocs. If the user has USE=doc, 1847# 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. 1848# then 'javadoc' or the argument are returned. Otherwise, there is no return.
1238# 1849#
1239# The output of this should be passed to ant. 1850# The output of this should be passed to ant.
1240# 1851#
1241# Example: build javadocs by calling 'javadoc' target 1852# Example: build javadocs by calling 'javadoc' target
1242# eant $(use_doc) 1853# eant $(use_doc)
1243# Example: build javadocs by calling 'apidoc' target 1854# Example: build javadocs by calling 'apidoc' target
1248# ------------------------------------------------------------------------------ 1859# ------------------------------------------------------------------------------
1249use_doc() { 1860use_doc() {
1250 use doc && echo ${@:-javadoc} 1861 use doc && echo ${@:-javadoc}
1251} 1862}
1252 1863
1864
1253# ------------------------------------------------------------------------------ 1865# ------------------------------------------------------------------------------
1254# @section-end build 1866# @section-end build
1255# ------------------------------------------------------------------------------ 1867# ------------------------------------------------------------------------------
1256 1868
1257# ------------------------------------------------------------------------------ 1869# ------------------------------------------------------------------------------
1258# @section-begin internal 1870# @section-begin internal
1259# @section-summary Internal functions 1871# @section-summary Internal functions
1260# 1872#
1261# Do __NOT__ use any of these from an ebuild! These are only to be used from 1873# Do __NOT__ use any of these from an ebuild! These are only to be used from
1262# within the java eclasses. 1874# within the java eclasses.
1263# ------------------------------------------------------------------------------ 1875# ------------------------------------------------------------------------------
1264 1876
1265# ----------------------------------------------------------------------------- 1877# -----------------------------------------------------------------------------
1266# @function-internal java-pkg_init 1878# @function-internal java-pkg_init
1267# 1879#
1268# The purpose of this function, as the name might imply, is to initialize the 1880# 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 1881# 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 1882# that'll muss things up. It initializes some variables, which are used
1271# internally. And most importantly, it'll switch the VM if necessary. 1883# internally. And most importantly, it'll switch the VM if necessary.
1272# 1884#
1275# 1887#
1276# ----------------------------------------------------------------------------- 1888# -----------------------------------------------------------------------------
1277java-pkg_init() { 1889java-pkg_init() {
1278 unset JAVAC 1890 unset JAVAC
1279 unset JAVA_HOME 1891 unset JAVA_HOME
1892
1893 # People do all kinds of weird things.
1894 # http://forums.gentoo.org/viewtopic-p-3943166.html
1895 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
1896 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
1897 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
1898 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
1899 ewarn "sun-jdk vms and and as such break configure scripts that"
1900 ewarn "use it (for example app-office/openoffice) so we filter it out."
1901 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
1902 ewarn "make.conf for example) to silence this warning or"
1903 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
1904 fi
1905
1906 if [[ -z ${accept} ]]; then
1907 unset _JAVA_OPTIONS
1908 # phase hooks make this run many times without this
1909 I_WANT_GLOBAL_JAVA_OPTIONS="true"
1910 fi
1911
1280 java-pkg_init_paths_ 1912 java-pkg_init_paths_
1281 java-pkg_switch-vm 1913 java-pkg_switch-vm
1282 PATH=${JAVA_HOME}/bin:${PATH} 1914 PATH=${JAVA_HOME}/bin:${PATH}
1283 1915
1284 # TODO we will probably want to set JAVAC and JAVACFLAGS 1916 # TODO we will probably want to set JAVAC and JAVACFLAGS
1285 1917
1286 # Do some QA checks 1918 # Do some QA checks
1287 java-pkg_check-jikes 1919 java-pkg_check-jikes
1288 1920
1289 # When users have crazy classpaths some packages can fail to compile. 1921 # When users have crazy classpaths some packages can fail to compile.
1290 # and everything should work with empty CLASSPATH. 1922 # and everything should work with empty CLASSPATH.
1291 # This also helps prevent unexpected dependencies on random things 1923 # This also helps prevent unexpected dependencies on random things
1292 # from the CLASSPATH. 1924 # from the CLASSPATH.
1293 unset CLASSPATH 1925 unset CLASSPATH
1926
1927 # Unset external ANT_ stuff
1928 unset ANT_TASKS
1929 unset ANT_OPTS
1294} 1930}
1295 1931
1296# ------------------------------------------------------------------------------ 1932# ------------------------------------------------------------------------------
1297# @function-internal java-pkg-init-compiler_ 1933# @function-internal java-pkg-init-compiler_
1298# 1934#
1299# This function attempts to figure out what compiler should be used. It does 1935# 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 1936# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
1301# COMPILERS variable defined there. 1937# COMPILERS variable defined there.
1302# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER 1938# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
1303# 1939#
1304# It will go through the list of compilers, and verify that it supports the 1940# 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 1941# 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 1942# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
1307# isn't done. 1943# isn't done.
1308# 1944#
1330 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1966 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1331 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})" 1967 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
1332 else 1968 else
1333 compilers=${JAVA_PKG_FORCE_COMPILER} 1969 compilers=${JAVA_PKG_FORCE_COMPILER}
1334 fi 1970 fi
1335 1971
1336 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}" 1972 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
1337 1973
1338 # Figure out if we should announce what compiler we're using 1974 # Figure out if we should announce what compiler we're using
1339 local compiler 1975 local compiler
1340 for compiler in ${compilers}; do 1976 for compiler in ${compilers}; do
1343 if [[ ${compiler} = "javac" ]]; then 1979 if [[ ${compiler} = "javac" ]]; then
1344 debug-print "Found javac... breaking" 1980 debug-print "Found javac... breaking"
1345 export GENTOO_COMPILER="javac" 1981 export GENTOO_COMPILER="javac"
1346 break 1982 break
1347 fi 1983 fi
1348 1984
1349 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then 1985 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
1350 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1986 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1351 einfo "Filtering ${compiler}" 1987 einfo "Filtering ${compiler}"
1352 continue 1988 continue
1353 fi 1989 fi
1354 fi 1990 fi
1355 1991
1356 # for non-javac, we need to make sure it supports the right target and 1992 # for non-javac, we need to make sure it supports the right target and
1357 # source 1993 # source
1358 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1994 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1359 if [[ -f ${compiler_env} ]]; then 1995 if [[ -f ${compiler_env} ]]; then
1360 local desired_target="$(java-pkg_get-target)" 1996 local desired_target="$(java-pkg_get-target)"
1442# Writes the package.env out to disk. 2078# Writes the package.env out to disk.
1443# 2079#
1444# ------------------------------------------------------------------------------ 2080# ------------------------------------------------------------------------------
1445# TODO change to do-write, to match everything else 2081# TODO change to do-write, to match everything else
1446java-pkg_do_write_() { 2082java-pkg_do_write_() {
2083 java-pkg_init_paths_
1447 # Create directory for package.env 2084 # Create directory for package.env
1448 dodir "${JAVA_PKG_SHAREPATH}" 2085 dodir "${JAVA_PKG_SHAREPATH}"
1449 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 2086 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then
1450 # Create package.env 2087 # Create package.env
1451 ( 2088 (
1456 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 2093 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1457 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 2094 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1458 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 2095 [[ -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 ! 2096 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1460 ) > "${JAVA_PKG_ENV}" 2097 ) > "${JAVA_PKG_ENV}"
1461 2098
1462 # register target/source 2099 # register target/source
1463 local target="$(java-pkg_get-target)" 2100 local target="$(java-pkg_get-target)"
1464 local source="$(java-pkg_get-source)" 2101 local source="$(java-pkg_get-source)"
1465 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}" 2102 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
1466 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}" 2103 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
1479 # Strip unnecessary leading and trailing colons 2116 # Strip unnecessary leading and trailing colons
1480 # TODO try to cleanup if possible 2117 # TODO try to cleanup if possible
1481 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 2118 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
1482 fi 2119 fi
1483} 2120}
1484
1485 2121
1486# ------------------------------------------------------------------------------ 2122# ------------------------------------------------------------------------------
1487# @internal-function java-pkg_record-jar_ 2123# @internal-function java-pkg_record-jar_
1488# 2124#
1489# Record a dependency to the package.env 2125# Record a dependency to the package.env
1533 fi 2169 fi
1534} 2170}
1535 2171
1536# ------------------------------------------------------------------------------ 2172# ------------------------------------------------------------------------------
1537# @internal-function java-pkg_expand_dir_ 2173# @internal-function java-pkg_expand_dir_
1538# 2174#
1539# Gets the full path of the file/directory's parent. 2175# Gets the full path of the file/directory's parent.
1540# @param $1 - file/directory to find parent directory for 2176# @param $1 - file/directory to find parent directory for
1541# @return - path to $1's parent directory 2177# @return - path to $1's parent directory
1542# ------------------------------------------------------------------------------ 2178# ------------------------------------------------------------------------------
1543java-pkg_expand_dir_() { 2179java-pkg_expand_dir_() {
1569# 2205#
1570# ------------------------------------------------------------------------------ 2206# ------------------------------------------------------------------------------
1571java-pkg_setup-vm() { 2207java-pkg_setup-vm() {
1572 debug-print-function ${FUNCNAME} $* 2208 debug-print-function ${FUNCNAME} $*
1573 2209
2210 export LANG="C" LC_ALL="C"
2211
1574 local vendor="$(java-pkg_get-vm-vendor)" 2212 local vendor="$(java-pkg_get-vm-vendor)"
1575 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge 1 5; then 2213 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1576 addpredict "/dev/random" 2214 addpredict "/dev/random"
1577 elif [[ "${vendor}" == "ibm" ]]; then 2215 elif [[ "${vendor}" == "ibm" ]]; then
1578 addpredict "/proc/self/maps" 2216 addpredict "/proc/self/maps"
1579 addpredict "/proc/cpuinfo" 2217 addpredict "/proc/cpuinfo"
1580 export LANG="C" LC_ALL="C"
1581 elif [[ "${vendor}" == "jrockit" ]]; then 2218 elif [[ "${vendor}" == "jrockit" ]]; then
1582 addpredict "/proc/cpuinfo" 2219 addpredict "/proc/cpuinfo"
1583 fi 2220 fi
1584} 2221}
1585 2222
1629# @return - The version of the current VM 2266# @return - The version of the current VM
1630# ------------------------------------------------------------------------------ 2267# ------------------------------------------------------------------------------
1631java-pkg_get-vm-version() { 2268java-pkg_get-vm-version() {
1632 debug-print-function ${FUNCNAME} $* 2269 debug-print-function ${FUNCNAME} $*
1633 2270
1634 java-pkg_get-current-vm | sed -e "s/.*-\([0-9.]\+\).*/\1/" 2271 java-config -g PROVIDES_VERSION
1635} 2272}
1636 2273
1637# ------------------------------------------------------------------------------ 2274# ------------------------------------------------------------------------------
1638# @internal-function java-pkg_switch-vm 2275# @internal-function java-pkg_switch-vm
1639# 2276#
1640# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 2277# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1641# verify that the current VM is sufficient. 2278# verify that the current VM is sufficient.
1642# Setup the environment for the VM being used. 2279# Setup the environment for the VM being used.
1643# ------------------------------------------------------------------------------ 2280# ------------------------------------------------------------------------------
1644java-pkg_switch-vm() { 2281java-pkg_switch-vm() {
2282 debug-print-function ${FUNCNAME} $*
2283
1645 if java-pkg_needs-vm; then 2284 if java-pkg_needs-vm; then
1646 # Use the VM specified by JAVA_PKG_FORCE_VM 2285 # Use the VM specified by JAVA_PKG_FORCE_VM
1647 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then 2286 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1648 # If you're forcing the VM, I hope you know what your doing... 2287 # If you're forcing the VM, I hope you know what your doing...
2288 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1649 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 2289 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1650 # if we're allowed to switch the vm... 2290 # if we're allowed to switch the vm...
1651 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 2291 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}" 2292 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1653 if [[ -n ${JAVA_PKG_VNEED} ]]; then 2293 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}}")" 2294 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1655 else 2295 else
1656 export GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2296 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
2297 fi
2298 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
2299 eerror "Unable to determine VM for building from dependencies:"
2300 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
2301 echo "VNEED: ${JAVA_PKG_VNEED}"
2302 die "Failed to determine VM for building."
2303 else
2304 export GENTOO_VM
1657 fi 2305 fi
1658 # otherwise just make sure the current VM is sufficient 2306 # otherwise just make sure the current VM is sufficient
1659 else 2307 else
1660 java-pkg_ensure-vm-version-sufficient 2308 java-pkg_ensure-vm-version-sufficient
1661 fi 2309 fi
1662 debug-print "Using: $(java-config -f)" 2310 debug-print "Using: $(java-config -f)"
1663 2311
1664 java-pkg_setup-vm 2312 java-pkg_setup-vm
1665 2313
1666 export JAVA=$(java-config -java) 2314 export JAVA=$(java-config --java)
1667 export JAVAC=$(java-config -javac) 2315 export JAVAC=$(java-config --javac)
1668 export JAVACFLAGS="$(java-pkg_javac-args)" 2316 JAVACFLAGS="$(java-pkg_javac-args)"
2317 if [[ ${?} != 0 ]]; then
2318 eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
2319 die "java-pkg_javac-args failed"
2320 fi
1669 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 2321 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
2322 export JAVACFLAGS
1670 2323
1671 export JAVA_HOME="$(java-config -g JAVA_HOME)" 2324 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1672 export JDK_HOME=${JAVA_HOME} 2325 export JDK_HOME=${JAVA_HOME}
1673 2326
1674 #TODO If you know a better solution let us know. 2327 #TODO If you know a better solution let us know.
1675 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 2328 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1676 2329
1677 local tann="${T}/announced-vm" 2330 local tann="${T}/announced-vm"
1678 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 2331 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1679 # Add a check for setup/preinst phase... to avoid duplicate outputs 2332 # Add a check for setup/preinst phase... to avoid duplicate outputs
1680 # for when FEATURES=buildpkg 2333 # for when FEATURES=buildpkg
1681 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]]; 2334 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1706 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2 2359 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2
1707 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2 2360 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2
1708 echo "and of course, the output of emerge --info" >&2 2361 echo "and of course, the output of emerge --info" >&2
1709} 2362}
1710 2363
2364
2365# TODO document
2366# List jars in the source directory, ${S}
2367java-pkg_jar-list() {
2368 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
2369 einfo "Linked Jars"
2370 find "${S}" -type l -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2371 einfo "Jars"
2372 find "${S}" -type f -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2373 einfo "Classes"
2374 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2375 fi
2376}
2377
2378# ------------------------------------------------------------------------------
2379# @internal-function java-pkg_verify-classes
2380#
2381# Verify that the classes were compiled for the right source / target. Dies if
2382# not.
2383# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2384# ------------------------------------------------------------------------------
2385java-pkg_verify-classes() {
2386 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
2387 local target=$(java-pkg_get-target)
2388 local result
2389 local log="${T}/class-version-verify.log"
2390 if [[ -n "${1}" ]]; then
2391 class-version-verify.py -v -t ${target} "${1}" > "${log}"
2392 result=$?
2393 else
2394 ebegin "Verifying java class versions (target: ${target})"
2395 class-version-verify.py -v -t ${target} -r "${D}" > "${log}"
2396 result=$?
2397 eend ${result}
2398 fi
2399 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2400 if [[ ${result} != 0 ]]; then
2401 eerror "Incorrect bytecode version found"
2402 [[ -n "${1}" ]] && eerror "in file: ${1}"
2403 eerror "See ${log} for more details."
2404 die "Incorrect bytecode found"
2405 fi
2406}
2407
2408# ----------------------------------------------------------------------------
2409# @internal-function java-pkg_ensure-dep
2410# Check that a package being used in jarfrom, getjars and getjar is contained
2411# within DEPEND or RDEPEND.
2412# @param $1 - empty - check both vars; "runtime" or "build" - check only
2413# RDEPEND, resp. DEPEND
2414# @param $2 - Package name and slot.
2415java-pkg_ensure-dep() {
2416 debug-print-function ${FUNCNAME} $*
2417
2418 local limit_to="${1}"
2419 local target_pkg="${2}"
2420 local dev_error=""
2421
2422 local stripped_pkg=$(echo "${target_pkg}" | sed \
2423 's/-[0-9]*\(\.[0-9]\)*$//')
2424
2425 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2426 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2427 dev_error="${dev_error} declared in DEPEND."
2428 if is-java-strict; then
2429 die "${dev_error}"
2430 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2431 eerror "${dev_error}"
2432 elog "Because you have this package installed the package will"
2433 elog "build without problems, but please report this to"
2434 elog "http://bugs.gentoo.org"
2435 fi
2436 fi
2437
2438 if [[ ${limit_to} != build && ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2439 dev_error="The ebuild is attempting to use ${target_pkg},"
2440 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND."
2441 if is-java-strict; then
2442 die "${dev_error}"
2443 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2444 eerror "${dev_error}"
2445 elog "The package will build without problems, but may fail to run"
2446 elog "if you don't have ${target_pkg} installed, so please report"
2447 elog "this to http://bugs.gentoo.org"
2448 fi
2449 fi
2450}
2451
1711# ------------------------------------------------------------------------------ 2452# ------------------------------------------------------------------------------
1712# @section-end internal 2453# @section-end internal
1713# ------------------------------------------------------------------------------ 2454# ------------------------------------------------------------------------------
1714 2455
1715java-pkg_check-phase() { 2456java-pkg_check-phase() {
1716 local phase=${1} 2457 local phase=${1}
1717 local funcname=${2} 2458 local funcname=${FUNCNAME[1]}
1718 # TODO add check for java-stricter
1719 if [[ ${EBUILD_PHASE} != ${phase} ]]; then 2459 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
1720 java-pkg_announce-qa-violation \
1721 "${funcname} used outside of src_${phase}" 2460 local msg="${funcname} used outside of src_${phase}"
2461 java-pkg_announce-qa-violation "${msg}"
1722 fi 2462 fi
1723} 2463}
1724 2464
1725java-pkg_check-versioned-jar() { 2465java-pkg_check-versioned-jar() {
1726 local jar=${1} 2466 local jar=${1}
1735 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2475 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1736 fi 2476 fi
1737} 2477}
1738 2478
1739java-pkg_announce-qa-violation() { 2479java-pkg_announce-qa-violation() {
1740 if hasq java-strict ${FEATURES}; then 2480 local nodie
2481 if [[ ${1} == "--nodie" ]]; then
2482 nodie="true"
2483 shift
2484 fi
1741 echo "Java QA Notice: $@" >&2 2485 echo "Java QA Notice: $@" >&2
1742 increment-qa-violations 2486 increment-qa-violations
1743 fi 2487 [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
1744} 2488}
1745 2489
1746increment-qa-violations() { 2490increment-qa-violations() {
1747 let "JAVA_PKG_QA_VIOLATIONS+=1" 2491 let "JAVA_PKG_QA_VIOLATIONS+=1"
1748 export JAVA_PKG_QA_VIOLATIONS 2492 export JAVA_PKG_QA_VIOLATIONS
1749} 2493}
1750 2494
2495is-java-strict() {
2496 [[ -n ${JAVA_PKG_STRICT} ]]
2497 return $?
2498}
2499
1751# ------------------------------------------------------------------------------ 2500# ------------------------------------------------------------------------------
1752# @eclass-end 2501# @eclass-end
1753# ------------------------------------------------------------------------------ 2502# ------------------------------------------------------------------------------

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

  ViewVC Help
Powered by ViewVC 1.1.20