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

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.78

  ViewVC Help
Powered by ViewVC 1.1.20