/[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.2 Revision 1.100
4# Copyright (c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org> 4# Copyright (c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
5# Copyright (c) 2004-2005, Gentoo Foundation 5# Copyright (c) 2004-2005, Gentoo Foundation
6# 6#
7# Licensed under the GNU General Public License, v2 7# Licensed under the GNU General Public License, v2
8# 8#
9 9# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.100 2007/11/28 02:03:48 betelgeuse Exp $
10 10
11# ----------------------------------------------------------------------------- 11# -----------------------------------------------------------------------------
12# @eclass-begin 12# @eclass-begin
13# @eclass-shortdesc Java Utility eclass 13# @eclass-shortdesc Java Utility eclass
14# @eclass-maintainer java@gentoo.org 14# @eclass-maintainer java@gentoo.org
15# 15#
16# This eclass provides functionality which is used by 16# This eclass provides functionality which is used by
17# java-pkg.eclass and java-pkg-opt.eclass as well as from ebuilds. 17# java-pkg.eclass and java-pkg-opt.eclass as well as from ebuilds.
18# 18#
19# @warning 19# @warning
20# You probably don't want to inherit this directly from an ebuild. Instead, 20# You probably don't want to inherit this directly from an ebuild. Instead,
21# you should inherit java-ant for Ant-based Java packages, java-pkg for other 21# you should inherit java-ant for Ant-based Java packages, java-pkg for other
22# Java packages, or java-pkg-opt for packages that have optional Java support. 22# Java packages, or java-pkg-opt for packages that have optional Java support.
23# 23#
24# ----------------------------------------------------------------------------- 24# -----------------------------------------------------------------------------
25 25
26inherit eutils versionator multilib 26inherit eutils versionator multilib
27
28IUSE="elibc_FreeBSD"
27 29
28# ----------------------------------------------------------------------------- 30# -----------------------------------------------------------------------------
29# @section-begin variables 31# @section-begin variables
30# @section-title Variables 32# @section-title Variables
31# 33#
34 36
35# Make sure we use java-config-2 37# Make sure we use java-config-2
36export WANT_JAVA_CONFIG="2" 38export WANT_JAVA_CONFIG="2"
37 39
38# ----------------------------------------------------------------------------- 40# -----------------------------------------------------------------------------
41# @variable-external WANT_ANT_TASKS
42# @variable-default ""
43#
44# An $IFS separated list of ant tasks.
45# Ebuild can specify this variable before inheriting java-ant-2 eclass to
46# determine ANT_TASKS it needs. They will be automatically translated to
47# DEPEND variable and ANT_TASKS variable. JAVA_PKG_FORCE_ANT_TASKS can override
48# ANT_TASKS set by WANT_ANT_TASKS, but not the DEPEND due to caching.
49# Ebuilds that need to depend conditionally on certain tasks and specify them
50# differently for different eant calls can't use this simplified approach.
51# You also cannot specify version or anything else than ant-*.
52#
53# @example WANT_ANT_TASKS="ant-junit ant-trax"
54#
55# @seealso JAVA_PKG_FORCE_ANT_TASKS
56# -----------------------------------------------------------------------------
57#WANT_ANT_TASKS
58
59# -----------------------------------------------------------------------------
60# @variable-internal JAVA_PKG_PORTAGE_DEP
61#
62# The version of portage we need to function properly. Previously it was
63# portage with phase hooks support but now we use a version with proper env
64# saving.
65# -----------------------------------------------------------------------------
66JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1.2.7"
67
68# -----------------------------------------------------------------------------
39# @variable-internal JAVA_PKG_E_DEPEND 69# @variable-internal JAVA_PKG_E_DEPEND
40# 70#
41# This is a convience variable to be used from the other java eclasses. This is 71# This is a convience variable to be used from the other java eclasses. This is
42# the version of java-config we want to use. We also need a recent version 72# the version of java-config we want to use. Usually the latest stable version
43# portage, that includes phase hooks. 73# so that ebuilds can use new features without depending on specific versions.
44# ----------------------------------------------------------------------------- 74# -----------------------------------------------------------------------------
45JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 >=sys-apps/portage-2.1_pre1" 75JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.33-r1 ${JAVA_PKG_PORTAGE_DEP}"
76hasq source ${JAVA_PKG_IUSE} && JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} source? ( app-arch/zip )"
46 77
47# ----------------------------------------------------------------------------- 78# -----------------------------------------------------------------------------
48# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 79# @variable-external JAVA_PKG_ALLOW_VM_CHANGE
49# @variable-default yes 80# @variable-default yes
50# 81#
97# ----------------------------------------------------------------------------- 128# -----------------------------------------------------------------------------
98 129
99# ----------------------------------------------------------------------------- 130# -----------------------------------------------------------------------------
100# @variable-internal JAVA_PKG_COMPILER_DIR 131# @variable-internal JAVA_PKG_COMPILER_DIR
101# @default /usr/share/java-config-2/compiler 132# @default /usr/share/java-config-2/compiler
102# 133#
103# Directory where compiler settings are saved, without trailing slash. 134# Directory where compiler settings are saved, without trailing slash.
104# Probably shouldn't touch this variable. 135# Probably shouldn't touch this variable.
105# ----------------------------------------------------------------------------- 136# -----------------------------------------------------------------------------
106JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"} 137JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"}
107 138
117 148
118# ----------------------------------------------------------------------------- 149# -----------------------------------------------------------------------------
119# @variable-external JAVA_PKG_FORCE_COMPILER 150# @variable-external JAVA_PKG_FORCE_COMPILER
120# 151#
121# Explicitly set a list of compilers to use. This is normally read from 152# Explicitly set a list of compilers to use. This is normally read from
122# JAVA_PKG_COMPILERS_CONF. 153# JAVA_PKG_COMPILERS_CONF.
123# 154#
124# @note This should only be used internally or for testing. 155# @note This should only be used internally or for testing.
125# @example Use jikes and javac, in that order 156# @example Use jikes and javac, in that order
126# JAVA_PKG_FORCE_COMPILER="jikes javac" 157# JAVA_PKG_FORCE_COMPILER="jikes javac"
127# ----------------------------------------------------------------------------- 158# -----------------------------------------------------------------------------
128 159
160# -----------------------------------------------------------------------------
161# @variable-external JAVA_PKG_FORCE_ANT_TASKS
162#
163# An $IFS separated list of ant tasks. Can be set in environment before calling
164# emerge/ebuild to override variables set in ebuild, mainly for testing before
165# putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in
166# eant() call, not the dependencies specified in WANT_ANT_TASKS.
167#
168# @example JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \
169# ebuild foo.ebuild compile
170#
171# @seealso WANT_ANT_TASKS
172# -----------------------------------------------------------------------------
173
129# TODO document me 174# TODO document me
130JAVA_PKG_QA_VIOLATIONS=0 175JAVA_PKG_QA_VIOLATIONS=0
131 176
132# ----------------------------------------------------------------------------- 177# -----------------------------------------------------------------------------
133# @section-end variables 178# @section-end variables
140# 185#
141# These are used to install Java-related things, such as jars, Javadocs, JNI 186# These are used to install Java-related things, such as jars, Javadocs, JNI
142# libraries, etc. 187# libraries, etc.
143# ----------------------------------------------------------------------------- 188# -----------------------------------------------------------------------------
144 189
190# -----------------------------------------------------------------------------
191# @ebuild-function java-pkg_doexamples
192#
193# Installs given arguments to /usr/share/doc/${PF}/examples
194# If you give it only one parameter and it is a directory it will install
195# everything in that directory to the examples directory.
196#
197# @example
198# java-pkg_doexamples demo
199# java-pkg_doexamples demo/* examples/*
200#
201# @param --subdir - If the examples need a certain directory structure
202# @param $* - list of files to install
203# ------------------------------------------------------------------------------
204java-pkg_doexamples() {
205 debug-print-function ${FUNCNAME} $*
206
207 [[ ${#} -lt 1 ]] && die "At least one argument needed"
208
209 java-pkg_check-phase install
210
211 local dest=/usr/share/doc/${PF}/examples
212 if [[ ${1} == --subdir ]]; then
213 local dest=${dest}/${2}
214 dodir ${dest}
215 shift 2
216 fi
217
218 if [[ ${#} = 1 && -d ${1} ]]; then
219 ( # dont want to pollute calling env
220 insinto "${dest}"
221 doins -r ${1}/*
222 ) || die "Installing examples failed"
223 else
224 ( # dont want to pollute calling env
225 insinto "${dest}"
226 doins -r "$@"
227 ) || die "Installing examples failed"
228 fi
229}
145 230
146# ----------------------------------------------------------------------------- 231# -----------------------------------------------------------------------------
147# @ebuild-function java-pkg_dojar 232# @ebuild-function java-pkg_dojar
148# 233#
149# Installs any number of jars. 234# Installs any number of jars.
150# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default. 235# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default.
151# You can use java-pkg_jarinto to change this path. 236# You can use java-pkg_jarinto to change this path.
152# You should never install a jar with a package version in the filename. 237# You should never install a jar with a package version in the filename.
153# Instead, use java-pkg_newjar defined below. 238# Instead, use java-pkg_newjar defined below.
154# 239#
155# @example 240# @example
156# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar 241# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar
157# 242#
168 # Create JARDEST if it doesn't exist 253 # Create JARDEST if it doesn't exist
169 dodir ${JAVA_PKG_JARDEST} 254 dodir ${JAVA_PKG_JARDEST}
170 255
171 local jar 256 local jar
172 # for each jar 257 # for each jar
173 for jar in "$@"; do 258 for jar in "${@}"; do
174 local jar_basename=$(basename "${jar}") 259 local jar_basename=$(basename "${jar}")
175 260
176 java-pkg_check-versioned-jar ${jar_basename} 261 java-pkg_check-versioned-jar ${jar_basename}
177 262
178 # check if it exists 263 # check if it exists
179 if [[ -e "${jar}" ]] ; then 264 if [[ -e "${jar}" ]] ; then
265 # Don't overwrite if jar has already been installed with the same
266 # name
267 local dest="${D}${JAVA_PKG_JARDEST}/${jar_basename}"
268 if [[ -e "${dest}" ]]; then
269 ewarn "Overwriting ${dest}"
270 fi
271
180 # install it into JARDEST if it's a non-symlink 272 # install it into JARDEST if it's a non-symlink
181 if [[ ! -L "${jar}" ]] ; then 273 if [[ ! -L "${jar}" ]] ; then
274 #but first check class version when in strict mode.
275 is-java-strict && java-pkg_verify-classes "${jar}"
276
182 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 277 INSDESTTREE="${JAVA_PKG_JARDEST}" \
183 doins "${jar}" || die "failed to install ${jar}" 278 doins "${jar}" || die "failed to install ${jar}"
184 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 279 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
185 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}" 280 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}"
186 # make a symlink to the original jar if it's symlink 281 # make a symlink to the original jar if it's symlink
197 292
198 java-pkg_do_write_ 293 java-pkg_do_write_
199} 294}
200 295
201 296
297# ------------------------------------------------------------------------------
298# @internal-function depend-java-query
299#
300# Wrapper for the depend-java-query binary to enable passing USE in env.
301# Using env variables keeps this eclass working with java-config versions that
302# do not handle use flags.
303# ------------------------------------------------------------------------------
304
305depend-java-query() {
306 # Used to have a which call here but it caused endless loops for some people
307 # that had some weird bashrc voodoo for which.
308 USE="${USE}" /usr/bin/depend-java-query "${@}"
309}
202 310
203# ------------------------------------------------------------------------------ 311# ------------------------------------------------------------------------------
204# @ebuild-function java-pkg_regjar 312# @ebuild-function java-pkg_regjar
205# 313#
206# Records an already installed jar in the package.env 314# Records an already installed jar in the package.env
207# This would mostly be used if the package has make or a custom script to 315# This would mostly be used if the package has make or a custom script to
208# install things. 316# install things.
209# 317#
210# Example: 318# Example:
211# java-pkg-regjar ${D}/opt/foo/lib/foo.jar 319# java-pkg_regjar ${D}/opt/foo/lib/foo.jar
320#
321# WARNING:
322# if you want to use shell expansion, you have to use ${D}/... as the for in
323# this function will not be able to expand the path, here's an example:
324#
325# java-pkg_regjar /opt/my-java/lib/*.jar
326#
327# will not work, because:
328# * the `for jar in "$@"` can't expand the path to jar file names, as they
329# don't exist yet
330# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar'
331# doesn't exist
332#
333# you have to use it as:
334#
335# java-pkg_regjar ${D}/opt/my-java/lib/*.jar
212# 336#
213# @param $@ - jars to record 337# @param $@ - jars to record
214# ------------------------------------------------------------------------------ 338# ------------------------------------------------------------------------------
215# TODO fix me! 339# TODO should we be making sure the jar is present on ${D} or wherever?
216java-pkg_regjar() { 340java-pkg_regjar() {
217 debug-print-function ${FUNCNAME} $* 341 debug-print-function ${FUNCNAME} $*
218 342
219 java-pkg_check-phase install 343 java-pkg_check-phase install
220 344
221 [[ ${#} -lt 1 ]] && die "at least one argument needed" 345 [[ ${#} -lt 1 ]] && die "at least one argument needed"
222 346
223 java-pkg_init_paths_ 347 java-pkg_init_paths_
224 348
225 local jar jar_dir jar_file 349 local jar jar_dir jar_file
226 for jar in "$@"; do 350 for jar in "${@}"; do
227 # TODO use java-pkg_check-versioned-jar 351 # TODO use java-pkg_check-versioned-jar
228 if [[ -e "${jar}" ]]; then
229 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar}"
230 elif [[ -e "${D}${jar}" ]]; then 352 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
353 [[ -d "${jar}" || -d "${D}${jar}" ]] \
354 && die "Called ${FUNCNAME} on a directory $*"
355
356 #check that class version correct when in strict mode
357 is-java-strict && java-pkg_verify-classes "${jar}"
358
359 # nelchael: we should strip ${D} in this case too, here's why:
360 # imagine such call:
361 # java-pkg_regjar ${D}/opt/java/*.jar
362 # such call will fall into this case (-e ${jar}) and will
363 # record paths with ${D} in package.env
231 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 364 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
232 else 365 else
366 if [[ ${jar} = *\** ]]; then
367 eerror "The argument ${jar} to ${FUNCNAME}"
368 eerror "has * in it. If you want it to glob in"
369 eerror '${D} add ${D} to the argument.'
370 fi
233 die "${jar} does not exist" 371 die "${jar} does not exist"
234 fi 372 fi
235 done 373 done
236 374
237 java-pkg_do_write_ 375 java-pkg_do_write_
238} 376}
239
240 377
241# ------------------------------------------------------------------------------ 378# ------------------------------------------------------------------------------
242# @ebuild-function java-pkg_newjar 379# @ebuild-function java-pkg_newjar
243# 380#
244# Installs a jar with a new name 381# Installs a jar with a new name
255 local original_jar="${1}" 392 local original_jar="${1}"
256 local new_jar="${2:-${PN}.jar}" 393 local new_jar="${2:-${PN}.jar}"
257 local new_jar_dest="${T}/${new_jar}" 394 local new_jar_dest="${T}/${new_jar}"
258 395
259 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 396 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
260 [[ ! -f ${original_jar} ]] && die "${new_jar} does not exist!" 397 [[ ! -f ${original_jar} ]] \
398 && die "${original_jar} does not exist or is not a file!"
261 399
262 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 400 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
263 cp "${original_jar}" "${new_jar_dest}" \ 401 cp "${original_jar}" "${new_jar_dest}" \
264 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 402 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
265 java-pkg_dojar "${new_jar_dest}" 403 java-pkg_dojar "${new_jar_dest}"
266} 404}
267 405
268
269# ------------------------------------------------------------------------------ 406# ------------------------------------------------------------------------------
270# @ebuild-function java-pkg_addcp 407# @ebuild-function java-pkg_addcp
271# 408#
272# Add something to the package's classpath. For jars, you should use dojar, 409# Add something to the package's classpath. For jars, you should use dojar,
273# newjar, or regjar. This is typically used to add directories to the classpath. 410# newjar, or regjar. This is typically used to add directories to the classpath.
278java-pkg_addcp() { 415java-pkg_addcp() {
279 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}" 416 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
280 java-pkg_do_write_ 417 java-pkg_do_write_
281} 418}
282 419
283
284# ------------------------------------------------------------------------------ 420# ------------------------------------------------------------------------------
285# @ebuild-function java-pkg_doso 421# @ebuild-function java-pkg_doso
286# 422#
287# Installs any number of JNI libraries 423# Installs any number of JNI libraries
288# They will be installed into /usr/lib by default, but java-pkg_sointo 424# They will be installed into /usr/lib by default, but java-pkg_sointo
289# can be used change this path 425# can be used change this path
290# 426#
291# Example: 427# Example:
316 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 452 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
317 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 453 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
318 # otherwise make a symlink to the symlink's origin 454 # otherwise make a symlink to the symlink's origin
319 else 455 else
320 # TODO use dosym 456 # TODO use dosym
457 ln -s "$(readlink "${lib}")" \
321 ln -s "$(readlink "${lib}")" "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")" 458 "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")"
322 debug-print "${lib} is a symlink, linking accordanly" 459 debug-print "${lib} is a symlink, linking accordanly"
323 fi 460 fi
324 # otherwise die 461 # otherwise die
325 else 462 else
326 die "${lib} does not exist" 463 die "${lib} does not exist"
346 java-pkg_check-phase install 483 java-pkg_check-phase install
347 484
348 [[ ${#} -lt 1 ]] && "at least one argument needed" 485 [[ ${#} -lt 1 ]] && "at least one argument needed"
349 486
350 java-pkg_init_paths_ 487 java-pkg_init_paths_
351 488
352 local lib target_dir 489 local lib target_dir
353 for lib in "$@" ; do 490 for lib in "$@" ; do
354 # Check the absolute path of the lib 491 # Check the absolute path of the lib
355 if [[ -e "${lib}" ]] ; then 492 if [[ -e "${lib}" ]] ; then
356 target_dir="$(java-pkg_expand_dir_ ${lib})" 493 target_dir="$(java-pkg_expand_dir_ ${lib})"
404# ------------------------------------------------------------------------------ 541# ------------------------------------------------------------------------------
405java-pkg_dohtml() { 542java-pkg_dohtml() {
406 debug-print-function ${FUNCNAME} $* 543 debug-print-function ${FUNCNAME} $*
407 544
408 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 545 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
409 # TODO-nichoj find out what exactly -f package-list does 546
547 # from /usr/lib/portage/bin/dohtml -h
548 # -f Set list of allowed extensionless file names.
410 dohtml -f package-list "$@" 549 dohtml -f package-list "$@"
550
411 # this probably shouldn't be here but it provides 551 # this probably shouldn't be here but it provides
412 # a reasonable way to catch # docs for all of the 552 # a reasonable way to catch # docs for all of the
413 # old ebuilds. 553 # old ebuilds.
414 java-pkg_recordjavadoc 554 java-pkg_recordjavadoc
415} 555}
416 556
417# TODO document 557# ------------------------------------------------------------------------------
558# @ebuild-function java-pkg_dojavadoc
559#
560# Installs javadoc documentation. This should be controlled by the doc use flag.
561#
562# @param $1: optional --symlink creates to symlink like this for html
563# documentation bundles.
564# @param $2: - The javadoc root directory.
565#
566# @example:
567# java-pkg_dojavadoc docs/api
568# java-pkg_dojavadoc --symlink apidocs docs/api
569#
570# ------------------------------------------------------------------------------
418java-pkg_dojavadoc() { 571java-pkg_dojavadoc() {
572 debug-print-function ${FUNCNAME} $*
573
574 # For html documentation bundles that link to Javadoc
575 local symlink
576 if [[ ${1} = --symlink ]]; then
577 symlink=${2}
578 shift 2
579 fi
580
419 local dir="$1" 581 local dir="$1"
582 local dest=/usr/share/doc/${PF}/html
583
584 # QA checks
420 585
421 java-pkg_check-phase install 586 java-pkg_check-phase install
422 587
423 [[ -z "${dir}" ]] && die "Must specify a directory!" 588 [[ -z "${dir}" ]] && die "Must specify a directory!"
424 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!" 589 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!"
590 if [[ ! -e "${dir}/index.html" ]]; then
591 local msg="No index.html in javadoc directory"
592 ewarn "${msg}"
593 is-java-strict && die "${msg}"
594 fi
595
596 if [[ -e ${D}/${dest}/api ]]; then
597 eerror "${dest} already exists. Will not overwrite."
598 die "${dest}"
599 fi
600
601 # Renaming to match our directory layout
425 602
426 local dir_to_install="${dir}" 603 local dir_to_install="${dir}"
427 if [[ "$(basename "${dir}")" != "api" ]]; then 604 if [[ "$(basename "${dir}")" != "api" ]]; then
428 dir_to_install="${T}/api" 605 dir_to_install="${T}/api"
429 # TODO use doins 606 # TODO use doins
430 cp -r "${dir}" "${dir_to_install}" || die "cp failed" 607 cp -r "${dir}" "${dir_to_install}" || die "cp failed"
431 fi 608 fi
432 609
610 # Actual installation
611
433 java-pkg_dohtml -r ${dir_to_install} 612 java-pkg_dohtml -r "${dir_to_install}"
613
614 # Let's make a symlink to the directory we have everything else under
615 dosym ${dest}/api "${JAVA_PKG_SHAREPATH}/api" || die
616
617 if [[ ${symlink} ]]; then
618 dosym ${dest}/{api,${symlink}} || die
619 fi
434} 620}
435 621
436# ------------------------------------------------------------------------------ 622# ------------------------------------------------------------------------------
437# @ebuild-function java-pkg_dosrc 623# @ebuild-function java-pkg_dosrc
438# 624#
439# Installs a zip containing the source for a package, so it can used in 625# Installs a zip containing the source for a package, so it can used in
440# from IDEs like eclipse and netbeans. 626# from IDEs like eclipse and netbeans.
441# 627#
442# Ebuild needs to DEPEND on app-arch/zip to use this. 628# Ebuild needs to DEPEND on app-arch/zip to use this.
443# 629#
444# It also should be controlled by USE=source. 630# It also should be controlled by USE=source.
445# 631#
446# @example: 632# @example:
447# java-pkg_dosrc src/* 633# java-pkg_dosrc src/*
448# 634#
449# ------------------------------------------------------------------------------ 635# ------------------------------------------------------------------------------
450# TODO change so it the arguments it takes are the base directories containing 636# TODO change so it the arguments it takes are the base directories containing
451# source -nichoj 637# source -nichoj
452# TODO should we be able to handle multiple calls to dosrc? -nichoj 638# TODO should we be able to handle multiple calls to dosrc? -nichoj
453# TODO maybe we can take an existing zip/jar? -nichoj 639# TODO maybe we can take an existing zip/jar? -nichoj
454# FIXME apparently this fails if you give it an empty directories 640# FIXME apparently this fails if you give it an empty directories
455java-pkg_dosrc() { 641java-pkg_dosrc() {
456 debug-print-function ${FUNCNAME} $* 642 debug-print-function ${FUNCNAME} $*
457 643
458 [ ${#} -lt 1 ] && die "At least one argument needed" 644 [ ${#} -lt 1 ] && die "At least one argument needed"
459 if ! hasq source ${IUSE}; then
460 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
461 fi
462 645
463 java-pkg_check-phase install 646 java-pkg_check-phase install
464 647
465 [[ ${#} -lt 1 ]] && die "At least one argument needed" 648 [[ ${#} -lt 1 ]] && die "At least one argument needed"
649
650 if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
651 local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
652 if is-java-strict; then
653 eerror "${msg}"
654 die "${msg}"
655 else
656 echo "${msg}"
657 echo "Please report this to http://bugs.gentoo.org."
658 fi
659 fi
466 660
467 java-pkg_init_paths_ 661 java-pkg_init_paths_
468 662
469 local zip_name="${PN}-src.zip" 663 local zip_name="${PN}-src.zip"
470 local zip_path="${T}/${zip_name}" 664 local zip_path="${T}/${zip_name}"
471 local dir 665 local dir
472 for dir in ${@}; do 666 for dir in "${@}"; do
473 local dir_parent=$(dirname "${dir}") 667 local dir_parent=$(dirname "${dir}")
474 local dir_name=$(basename "${dir}") 668 local dir_name=$(basename "${dir}")
475 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 669 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
476 zip -q -r ${zip_path} ${dir_name} -i '*.java' 670 zip -q -r ${zip_path} ${dir_name} -i '*.java'
477 local result=$? 671 local result=$?
494# @ebuild-function java-pkg_dolauncher 688# @ebuild-function java-pkg_dolauncher
495# 689#
496# Make a wrapper script to lauch/start this package 690# Make a wrapper script to lauch/start this package
497# If necessary, the wrapper will switch to the appropriate VM. 691# If necessary, the wrapper will switch to the appropriate VM.
498# 692#
693# Can be called without parameters if the package installs only one jar
694# that has the Main-class attribute set. The wrapper will be named ${PN}.
695#
499# @param $1 - filename of launcher to create 696# @param $1 - filename of launcher to create
500# @param $2 - options, as follows: 697# @param $2 - options, as follows:
501# --main the.main.class.too.start 698# --main the.main.class.too.start
502# --jar /the/jar/too/launch.jar 699# --jar /the/jar/too/launch.jar or just <name>.jar
503# --java_args 'Extra arguments to pass too jave' 700# --java_args 'Extra arguments to pass to java'
504# --pkg_args 'extra arguments too pass too the package' 701# --pkg_args 'Extra arguments to pass to the package'
505# --pwd 702# --pwd Directory the launcher changes to before executing java
506# -into 703# -into Directory to install the launcher to, instead of /usr/bin
507# -pre 704# -pre Prepend contents of this file to the launcher
508# ------------------------------------------------------------------------------ 705# ------------------------------------------------------------------------------
509java-pkg_dolauncher() { 706java-pkg_dolauncher() {
510 debug-print-function ${FUNCNAME} $* 707 debug-print-function ${FUNCNAME} $*
511 708
512 java-pkg_check-phase install 709 java-pkg_check-phase install
513
514 [[ ${#} -lt 1 ]] && die "Need at least one argument"
515
516 java-pkg_init_paths_ 710 java-pkg_init_paths_
517 711
712 if [[ ${#} = 0 ]]; then
713 local name="${PN}"
714 else
518 local name="${1}" 715 local name="${1}"
716 shift
717 fi
718
519 # TODO rename to launcher 719 # TODO rename to launcher
520 local target="${T}/${name}" 720 local target="${T}/${name}"
721 local var_tmp="${T}/launcher_variables_tmp"
521 local target_dir pre 722 local target_dir pre
522 shift
523 723
524 echo "#!/bin/bash" > "${target}" 724 # Process the other the rest of the arguments
525 while [[ -n "${1}" && -n "${2}" ]]; do 725 while [[ -n "${1}" && -n "${2}" ]]; do
526 local var=${1} value=${2} 726 local var="${1}" value="${2}"
527 if [[ "${var:0:2}" == "--" ]]; then 727 if [[ "${var:0:2}" == "--" ]]; then
728 local var=${var:2}
528 echo "gjl_${var:2}=\"${value}\"" >> "${target}" 729 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
730 local gjl_${var}="${value}"
529 elif [[ "${var}" == "-into" ]]; then 731 elif [[ "${var}" == "-into" ]]; then
530 target_dir="${value}" 732 target_dir="${value}"
531 elif [[ "${var}" == "-pre" ]]; then 733 elif [[ "${var}" == "-pre" ]]; then
532 pre="${value}" 734 pre="${value}"
533 fi 735 fi
534 shift 2 736 shift 2
535 done 737 done
738
739 # Test if no --jar and --main arguments were given and
740 # in that case check if the package only installs one jar
741 # and use that jar.
742 if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
743 local cp="${JAVA_PKG_CLASSPATH}"
744 if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
745 echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
746 else
747 local msg="Not enough information to create a launcher given."
748 msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
749 die "${msg}"
750 fi
751 fi
752
753 # Write the actual script
754 echo "#!/bin/bash" > "${target}"
755 if [[ -n "${pre}" ]]; then
756 if [[ -f "${pre}" ]]; then
757 cat "${pre}" >> "${target}"
758 else
759 die "-pre specified file '${pre}' does not exist"
760 fi
761 fi
536 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 762 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
537 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 763 cat "${var_tmp}" >> "${target}"
764 rm -f "${var_tmp}"
538 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 765 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
539 766
540 if [[ -n "${into}" ]]; then 767 if [[ -n "${target_dir}" ]]; then
541 DESTTREE="${target_dir}" dobin "${target}" 768 DESTTREE="${target_dir}" dobin "${target}"
542 local ret=$? 769 local ret=$?
543 return ${ret} 770 return ${ret}
544 else 771 else
545 dobin "${target}" 772 dobin "${target}"
573 echo "dowar: warning, skipping directory ${war}" 800 echo "dowar: warning, skipping directory ${war}"
574 continue 801 continue
575 else 802 else
576 warpath="${war}" 803 warpath="${war}"
577 fi 804 fi
578 805
579 # Install those files like you mean it 806 # Install those files like you mean it
580 INSOPTIONS="-m 0644" \ 807 INSOPTIONS="-m 0644" \
581 INSDESTTREE=${JAVA_PKG_WARDEST} \ 808 INSDESTTREE=${JAVA_PKG_WARDEST} \
582 doins ${warpath} 809 doins ${warpath}
583 done 810 done
618# @ebuild-function java-pkg_jar-from 845# @ebuild-function java-pkg_jar-from
619# 846#
620# Makes a symlink to a jar from a certain package 847# Makes a symlink to a jar from a certain package
621# A lot of java packages include dependencies in a lib/ directory 848# A lot of java packages include dependencies in a lib/ directory
622# You can use this function to replace these bundled dependencies. 849# You can use this function to replace these bundled dependencies.
850# The dependency is recorded into package.env DEPEND line, unless "--build-only"
851# is passed as the very first argument, for jars that have to be present only
852# at build time and are not needed on runtime (junit testing etc).
623# 853#
624# Example: get all jars from xerces slot 2 854# Example: get all jars from xerces slot 2
625# java-pkg_jar-from xerces-2 855# java-pkg_jar-from xerces-2
626# Example: get a specific jar from xerces slot 2 856# Example: get a specific jar from xerces slot 2
627# java-pkg_jar-from xerces-2 xml-apis.jar 857# java-pkg_jar-from xerces-2 xml-apis.jar
628# Example get a specific jar from xerces slot 2, and name it diffrently 858# Example: get a specific jar from xerces slot 2, and name it diffrently
629# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 859# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
860# Example: get junit.jar which is needed only for building
861# java-pkg_jar-from --build-only junit junit.jar
630# 862#
631# @param $1 - Package to get jars from. 863# @param $opt
864# --build-only - makes the jar(s) not added into package.env DEPEND line.
865# (assumed automatically when called inside src_test)
866# --with-dependencies - get jars also from requested package's dependencies
867# transitively.
868# --virtual - Packages passed to this function are to be handled as virtuals
869# and will not have individual jar dependencies recorded.
870# --into $dir - symlink jar(s) into $dir (must exist) instead of .
871# @param $1 - Package to get jars from, or comma-separated list of packages in
872# case other parameters are not used.
632# @param $2 - jar from package. If not specified, all jars will be used. 873# @param $2 - jar from package. If not specified, all jars will be used.
633# @param $3 - When a single jar is specified, destination filename of the 874# @param $3 - When a single jar is specified, destination filename of the
634# symlink. Defaults to the name of the jar. 875# symlink. Defaults to the name of the jar.
635# ------------------------------------------------------------------------------ 876# ------------------------------------------------------------------------------
636# TODO could probably be cleaned up a little 877# TODO could probably be cleaned up a little
637java-pkg_jar-from() { 878java-pkg_jar-from() {
638 debug-print-function ${FUNCNAME} $* 879 debug-print-function ${FUNCNAME} $*
639 880
881 local build_only=""
882 local destdir="."
883 local deep=""
884 local virtual=""
885
886 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
887
888 while [[ "${1}" == --* ]]; do
889 if [[ "${1}" = "--build-only" ]]; then
890 build_only="build"
891 elif [[ "${1}" = "--with-dependencies" ]]; then
892 deep="--with-dependencies"
893 elif [[ "${1}" = "--virtual" ]]; then
894 virtual="true"
895 elif [[ "${1}" = "--into" ]]; then
896 destdir="${2}"
897 shift
898 else
899 die "java-pkg_jar-from called with unknown parameter: ${1}"
900 fi
901 shift
902 done
903
640 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 904 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
641 905
642 [[ -z ${target_pkg} ]] && die "Must specify a package" 906 [[ -z ${target_pkg} ]] && die "Must specify a package"
643 907
644 # default destjar to the target jar 908 # default destjar to the target jar
645 [[ -z "${destjar}" ]] && destjar="${target_jar}" 909 [[ -z "${destjar}" ]] && destjar="${target_jar}"
646 910
911 local error_msg="There was a problem getting the classpath for ${target_pkg}."
912 local classpath
647 local classpath="$(java-config --classpath=${target_pkg})" 913 classpath="$(java-config ${deep} --classpath=${target_pkg})"
648 [[ $? != 0 ]] && die "There was a problem getting the classpath for ${target_pkg}" 914 [[ $? != 0 ]] && die ${error_msg}
915
916 # When we have commas this functions is called to bring jars from multiple
917 # packages. This affects recording of dependencencies performed later
918 # which expects one package only, so we do it here.
919 if [[ ${target_pkg} = *,* ]]; then
920 for pkg in ${target_pkg//,/ }; do
921 java-pkg_ensure-dep "${build_only}" "${pkg}"
922 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
923 done
924 # setting this disables further record-jar_ calls later
925 build_only="build"
926 else
927 java-pkg_ensure-dep "${build_only}" "${target_pkg}"
928 fi
929
930 # Record the entire virtual as a dependency so that
931 # no jars are missed.
932 if [[ -z "${build_only}" && -n "${virtual}" ]]; then
933 java-pkg_record-jar_ "${target_pkg}"
934 # setting this disables further record-jars_ calls later
935 build_only="build"
936 fi
937
938 pushd ${destdir} > /dev/null \
939 || die "failed to change directory to ${destdir}"
649 940
650 local jar 941 local jar
651 for jar in ${classpath//:/ }; do 942 for jar in ${classpath//:/ }; do
652 local jar_name=$(basename "${jar}") 943 local jar_name=$(basename "${jar}")
653 if [[ ! -f "${jar}" ]] ; then 944 if [[ ! -f "${jar}" ]] ; then
657 # If no specific target jar was indicated, link it 948 # If no specific target jar was indicated, link it
658 if [[ -z "${target_jar}" ]] ; then 949 if [[ -z "${target_jar}" ]] ; then
659 [[ -f "${target_jar}" ]] && rm "${target_jar}" 950 [[ -f "${target_jar}" ]] && rm "${target_jar}"
660 ln -snf "${jar}" \ 951 ln -snf "${jar}" \
661 || die "Failed to make symlink from ${jar} to ${jar_name}" 952 || die "Failed to make symlink from ${jar} to ${jar_name}"
662 java-pkg_record-jar_ "${target_pkg}" "${jar}" 953 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
663 # otherwise, if the current jar is the target jar, link it 954 # otherwise, if the current jar is the target jar, link it
664 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 955 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
665 [[ -f "${destjar}" ]] && rm "${destjar}" 956 [[ -f "${destjar}" ]] && rm "${destjar}"
666 ln -snf "${jar}" "${destjar}" \ 957 ln -snf "${jar}" "${destjar}" \
667 || die "Failed to make symlink from ${jar} to ${destjar}" 958 || die "Failed to make symlink from ${jar} to ${destjar}"
668 java-pkg_record-jar_ "${target_pkg}" "${jar}" 959 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
960 popd > /dev/null
669 return 0 961 return 0
670 fi 962 fi
671 done 963 done
964 popd > /dev/null
672 # if no target was specified, we're ok 965 # if no target was specified, we're ok
673 if [[ -z "${target_jar}" ]] ; then 966 if [[ -z "${target_jar}" ]] ; then
674 return 0 967 return 0
675 # otherwise, die bitterly 968 # otherwise, die bitterly
676 else 969 else
690# ------------------------------------------------------------------------------ 983# ------------------------------------------------------------------------------
691# @ebuild-function java-pkg_getjars 984# @ebuild-function java-pkg_getjars
692# 985#
693# Get the classpath provided by any number of packages 986# Get the classpath provided by any number of packages
694# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'. 987# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
988# The providing packages are recorded as dependencies into package.env DEPEND
989# line, unless "--build-only" is passed as the very first argument, for jars
990# that have to be present only at build time and are not needed on runtime
991# (junit testing etc).
695# 992#
696# Example: Get the classpath for xerces-2, 993# Example: Get the classpath for xerces-2 and xalan,
697# java-pkg_getjars xerces-2 xalan 994# java-pkg_getjars xerces-2,xalan
698# Example Return: 995# Example Return:
699# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 996# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
700# 997#
998# @param $opt
999# --build-only - makes the jar(s) not added into package.env DEPEND line.
1000# (assumed automatically when called inside src_test)
1001# --with-dependencies - get jars also from requested package's dependencies
1002# transitively.
701# @param $@ - list of packages to get jars from 1003# @param $1 - list of packages to get jars from
1004# (passed to java-config --classpath)
702# ------------------------------------------------------------------------------ 1005# ------------------------------------------------------------------------------
703java-pkg_getjars() { 1006java-pkg_getjars() {
704 debug-print-function ${FUNCNAME} $* 1007 debug-print-function ${FUNCNAME} $*
705 1008
706 [[ ${#} -lt 1 ]] && die "At least one argument needed" 1009 local build_only=""
1010 local deep=""
707 1011
708 # NOTE could probably just pass $@ to java-config --classpath. and return it 1012 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
709 local classpath pkg 1013
710 for pkg in ${@//,/ }; do 1014 while [[ "${1}" == --* ]]; do
711 #for pkg in $(echo "$@" | tr ',' ' '); do 1015 if [[ "${1}" = "--build-only" ]]; then
712 jars="$(java-config --classpath=${pkg})" 1016 build_only="build"
713 debug-print "${pkg}:${jars}" 1017 elif [[ "${1}" = "--with-dependencies" ]]; then
714 # TODO should we ensure jars exist? 1018 deep="--with-dependencies"
715 if [[ -z "${classpath}" ]]; then
716 classpath="${jars}"
717 else 1019 else
718 classpath="${classpath}:${jars}" 1020 die "java-pkg_jar-from called with unknown parameter: ${1}"
719 fi 1021 fi
720 java-pkg_record-jar_ "${pkg}" 1022 shift
721 done 1023 done
1024
1025 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
1026
1027
1028 local classpath pkgs="${1}"
1029 jars="$(java-config ${deep} --classpath=${pkgs})"
1030 [[ $? != 0 || -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed"
1031 debug-print "${pkgs}:${jars}"
1032
1033 for pkg in ${pkgs//,/ }; do
1034 java-pkg_ensure-dep "${build_only}" "${pkg}"
1035 done
1036
1037 if [[ -z "${classpath}" ]]; then
1038 classpath="${jars}"
1039 else
1040 classpath="${classpath}:${jars}"
1041 fi
1042
1043 # Only record jars that aren't build-only
1044 if [[ -z "${build_only}" ]]; then
1045 for pkg in ${pkgs//,/ }; do
1046 java-pkg_record-jar_ "${pkg}"
1047 done
1048 fi
1049
722 echo "${classpath}" 1050 echo "${classpath}"
723} 1051}
724 1052
725# ------------------------------------------------------------------------------ 1053# ------------------------------------------------------------------------------
726# @ebuild-function java-pkg_getjar 1054# @ebuild-function java-pkg_getjar
727# 1055#
728# Get the filename of a single jar from a package 1056# Get the filename of a single jar from a package
1057# The providing package is recorded as runtime dependency into package.env
1058# DEPEND line, unless "--build-only" is passed as the very first argument, for
1059# jars that have to be present only at build time and are not needed on runtime
1060# (junit testing etc).
729# 1061#
730# @example 1062# @example
731# java-pkg_getjar xerces-2 xml-apis.jar 1063# java-pkg_getjar xerces-2 xml-apis.jar
732# @example-return 1064# @example-return
733# /usr/share/xerces-2/lib/xml-apis.jar 1065# /usr/share/xerces-2/lib/xml-apis.jar
734# 1066#
1067# @param $opt
1068# --build-only - makes the jar not added into package.env DEPEND line.
1069# --virtual - Packages passed to this function are to be handled as virtuals
1070# and will not have individual jar dependencies recorded.
735# @param $1 - package to use 1071# @param $1 - package to use
736# @param $2 - jar to get 1072# @param $2 - jar to get
737# ------------------------------------------------------------------------------ 1073# ------------------------------------------------------------------------------
738java-pkg_getjar() { 1074java-pkg_getjar() {
739 debug-print-function ${FUNCNAME} $* 1075 debug-print-function ${FUNCNAME} $*
1076
1077 local build_only=""
1078 local virtual=""
1079
1080 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1081
1082 while [[ "${1}" == --* ]]; do
1083 if [[ "${1}" = "--build-only" ]]; then
1084 build_only="build"
1085 elif [[ "${1}" == --* ]]; then
1086 virtual="true"
1087 else
1088 die "java-pkg_jar-from called with unknown parameter: ${1}"
1089 fi
1090 shift
1091 done
1092
1093 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
740 1094
741 local pkg="${1}" target_jar="${2}" jar 1095 local pkg="${1}" target_jar="${2}" jar
742 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 1096 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
743 [[ -z ${target_jar} ]] && die "Must specify jar to get" 1097 [[ -z ${target_jar} ]] && die "Must specify jar to get"
744 1098
745 # TODO check that package is actually installed 1099 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
1100 local classpath
746 local classpath=$(java-config --classpath=${pkg}) 1101 classpath=$(java-config --classpath=${pkg})
747 [[ $? != 0 ]] && die "There could not find classpath for ${pkg}. Are you sure its installed?" 1102 [[ $? != 0 ]] && die ${error_msg}
1103
1104 java-pkg_ensure-dep "${build_only}" "${pkg}"
1105
1106 # Record the package(Virtual) as a dependency and then set build_only
1107 # So that individual jars are not recorded.
1108 if [[ -n "${virtual}" ]]; then
1109 java-pkg_record-jar_ "${pkg}"
1110 build_only="true"
1111 fi
1112
748 for jar in ${classpath//:/ }; do 1113 for jar in ${classpath//:/ }; do
749 if [[ ! -f "${jar}" ]] ; then 1114 if [[ ! -f "${jar}" ]] ; then
750 die "Installation problems with jars in ${pkg} - is it installed?" 1115 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
751 fi 1116 fi
752 1117
753 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then 1118 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
754 java-pkg_record-jar_ "${pkg}" "${jar}" 1119 # Only record jars that aren't build-only
1120 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" "${jar}"
755 echo "${jar}" 1121 echo "${jar}"
756 return 0 1122 return 0
757 fi 1123 fi
758 done 1124 done
759 1125
760 die "Could not find ${target_jar} in ${pkg}" 1126 die "Could not find ${target_jar} in ${pkg}"
761 return 1 1127 return 1
1128}
1129
1130# ------------------------------------------------------------------------------
1131# @ebuild-function java-pkg_register-dependency
1132#
1133# Registers runtime dependency on a package, list of packages, or a single jar
1134# from a package, into package.env DEPEND line. Can only be called in
1135# src_install phase.
1136# Intended for binary packages where you don't need to symlink the jars or get
1137# their classpath during build. As such, the dependencies only need to be
1138# specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1139#
1140# @param $1 - comma-separated list of packages, or a single package
1141# @param $2 - if param $1 is a single package, optionally specify the jar
1142# to depend on
1143#
1144# Example: Record the dependency on whole xerces-2 and xalan,
1145# java-pkg_register-dependency xerces-2,xalan
1146# Example: Record the dependency on ant.jar from ant-core
1147# java-pkg_register-dependency ant-core ant.jar
1148#
1149# Note: Passing both list of packages as the first parameter AND specifying the
1150# jar as the second is not allowed and will cause the function to die. We assume
1151# that there's more chance one passes such combination as a mistake, than that
1152# there are more packages providing identically named jar without class
1153# collisions.
1154# ------------------------------------------------------------------------------
1155java-pkg_register-dependency() {
1156 debug-print-function ${FUNCNAME} $*
1157
1158 java-pkg_check-phase install
1159
1160 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1161
1162 local pkgs="${1}"
1163 local jar="${2}"
1164
1165 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1166
1167 if [[ -z "${jar}" ]]; then
1168 for pkg in ${pkgs//,/ }; do
1169 java-pkg_ensure-dep runtime "${pkg}"
1170 java-pkg_record-jar_ "${pkg}"
1171 done
1172 else
1173 [[ ${pkgs} == *,* ]] && \
1174 die "${FUNCNAME} called with both package list and jar name"
1175 java-pkg_ensure-dep runtime "${pkgs}"
1176 java-pkg_record-jar_ "${pkgs}" "${jar}"
1177 fi
1178
1179 java-pkg_do_write_
1180}
1181
1182# ------------------------------------------------------------------------------
1183# @ebuild-function java-pkg_register-optional-dependency
1184#
1185# Registers optional runtime dependency on a package, list of packages, or a
1186# single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be
1187# called in src_install phase.
1188# Intended for packages that can use other packages when those are in classpath.
1189# Will be put on classpath by launcher if they are installed. Typical case is
1190# JDBC implementations for various databases. It's better than having USE flag
1191# for each implementation triggering hard dependency.
1192#
1193# @param $1 - comma-separated list of packages, or a single package
1194# @param $2 - if param $1 is a single package, optionally specify the jar
1195# to depend on
1196#
1197# Example: Record the optional dependency on some jdbc providers
1198# java-pkg_register-optional-dependency jdbc-jaybird,jtds-1.2,jdbc-mysql
1199#
1200# Note: Passing both list of packages as the first parameter AND specifying the
1201# jar as the second is not allowed and will cause the function to die. We assume
1202# that there's more chance one passes such combination as a mistake, than that
1203# there are more packages providing identically named jar without class
1204# collisions.
1205# ------------------------------------------------------------------------------
1206java-pkg_register-optional-dependency() {
1207 debug-print-function ${FUNCNAME} $*
1208
1209 java-pkg_check-phase install
1210
1211 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1212
1213 local pkgs="${1}"
1214 local jar="${2}"
1215
1216 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1217
1218 if [[ -z "${jar}" ]]; then
1219 for pkg in ${pkgs//,/ }; do
1220 java-pkg_record-jar_ --optional "${pkg}"
1221 done
1222 else
1223 [[ ${pkgs} == *,* ]] && \
1224 die "${FUNCNAME} called with both package list and jar name"
1225 java-pkg_record-jar_ --optional "${pkgs}" "${jar}"
1226 fi
1227
1228 java-pkg_do_write_
1229}
1230
1231# ------------------------------------------------------------------------------
1232# @ebuild-function java-pkg_register-environment-variable
1233#
1234# Register an arbitrary environment variable into package.env. The gjl launcher
1235# for this package or any package depending on this will export it into
1236# environement before executing java command.
1237# Must only be called in src_install phase.
1238#
1239# @param $1 - variable name
1240# @param $2 - variable value
1241# ------------------------------------------------------------------------------
1242JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
1243JAVA_PKG_EXTRA_ENV_VARS=""
1244java-pkg_register-environment-variable() {
1245 debug-print-function ${FUNCNAME} $*
1246
1247 java-pkg_check-phase install
1248
1249 [[ ${#} != 2 ]] && die "${FUNCNAME} takes two arguments"
1250
1251 echo "${1}=\"${2}\"" >> ${JAVA_PKG_EXTRA_ENV}
1252 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
1253
1254 java-pkg_do_write_
762} 1255}
763 1256
764# This function reads stdin, and based on that input, figures out how to 1257# This function reads stdin, and based on that input, figures out how to
765# populate jars from the filesystem. 1258# populate jars from the filesystem.
766# Need to figure out a good way of making use of this, ie be able to use a 1259# Need to figure out a good way of making use of this, ie be able to use a
778# line="${line// /}" 1271# line="${line// /}"
779# 1272#
780# # format: path=jarinfo 1273# # format: path=jarinfo
781# local path=${line%%=*} 1274# local path=${line%%=*}
782# local jarinfo=${line##*=} 1275# local jarinfo=${line##*=}
783# 1276#
784# # format: jar@package 1277# # format: jar@package
785# local jar=${jarinfo%%@*}.jar 1278# local jar=${jarinfo%%@*}.jar
786# local package=${jarinfo##*@} 1279# local package=${jarinfo##*@}
787# if [[ -n ${replace_only} ]]; then 1280# if [[ -n ${replace_only} ]]; then
788# [[ ! -f $path ]] && die "No jar exists at ${path}" 1281# [[ ! -f $path ]] && die "No jar exists at ${path}"
801# @section-end query 1294# @section-end query
802# ------------------------------------------------------------------------------ 1295# ------------------------------------------------------------------------------
803 1296
804# ------------------------------------------------------------------------------ 1297# ------------------------------------------------------------------------------
805# @section-begin helper 1298# @section-begin helper
806# @section-summary Helper functions 1299# @section-summary Helper functions
807# 1300#
808# Various other functions to use from an ebuild 1301# Various other functions to use from an ebuild
809# ------------------------------------------------------------------------------ 1302# ------------------------------------------------------------------------------
810 1303
811# ------------------------------------------------------------------------------ 1304# ------------------------------------------------------------------------------
817# jdbc-stdext 1310# jdbc-stdext
818# jaf 1311# jaf
819# jdbc-rowset 1312# jdbc-rowset
820# jms 1313# jms
821# 1314#
822# @param $1 - Optionally indicate that the dependencies are controlled by 1315# @param $1 - Optionally indicate that the dependencies are controlled by
823# a use flag by specifying '--use' Requires $2. 1316# a use flag by specifying '--use' Requires $2.
824# @param $2 - USE flag which will enable the dependencies. 1317# @param $2 - USE flag which will enable the dependencies.
825# @param $@ - virtual packages to add depenedencies for 1318# @param $@ - virtual packages to add depenedencies for
826# ------------------------------------------------------------------------------ 1319# ------------------------------------------------------------------------------
827# TODO rewrite to parse a line based declaration file instead -- karltk 1320# TODO rewrite to parse a line based declaration file instead -- karltk
883# 1376#
884# export DEPEND="${DEPEND} ${depstr}" 1377# export DEPEND="${DEPEND} ${depstr}"
885# export RDEPEND="${RDEPEND} ${depstr}" 1378# export RDEPEND="${RDEPEND} ${depstr}"
886#} 1379#}
887 1380
1381# ------------------------------------------------------------------------------
1382# @ebuild-function java-pkg_find-normal-jars
1383#
1384# Find the files with suffix .jar file in the given directory or $WORKDIR
1385#
1386# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1387# ------------------------------------------------------------------------------
1388java-pkg_find-normal-jars() {
1389 local dir=$1
1390 [[ "${dir}" ]] || dir="${WORKDIR}"
1391 local found
1392 for jar in $(find "${dir}" -name "*.jar" -type f); do
1393 echo "${jar}"
1394 found="true"
1395 done
1396 [[ "${found}" ]]
1397 return $?
1398}
1399
1400# ------------------------------------------------------------------------------
1401# @ebuild-function java-pkg_ensure-no-bundled-jars
1402#
1403# Try to locate bundled jar files in ${WORKDIR} and die if found.
888# This should be used after S has been populated with symlinks to jars 1404# This function should be called after WORKDIR has been populated with symlink
889# TODO document 1405# to system jar files or bundled jars removed.
1406# ------------------------------------------------------------------------------
890java-pkg_ensure-no-bundled-jars() { 1407java-pkg_ensure-no-bundled-jars() {
891 debug-print-function ${FUNCNAME} $* 1408 debug-print-function ${FUNCNAME} $*
892 pushd ${WORKDIR} >/dev/null 2>/dev/null
893 1409
894 local bundled_jars=$(find . -name "*.jar" -type f) 1410 local bundled_jars=$(java-pkg_find-normal-jars)
895 if [[ -n ${bundled_jars} ]]; then 1411 if [[ -n ${bundled_jars} ]]; then
896 echo "Bundled jars found:" 1412 echo "Bundled jars found:"
897 local jar 1413 local jar
898 for jar in ${bundled_jars}; do 1414 for jar in ${bundled_jars}; do
899 echo $(pwd)${jar/./} 1415 echo $(pwd)${jar/./}
900 done 1416 done
901 die "Bundled jars found!" 1417 die "Bundled jars found!"
902
903 fi 1418 fi
904 popd >/dev/null 2>/dev/null
905} 1419}
906 1420
907# ------------------------------------------------------------------------------ 1421# ------------------------------------------------------------------------------
908# @internal-function java-pkg_ensure-vm-version-sufficient 1422# @internal-function java-pkg_ensure-vm-version-sufficient
909# 1423#
921 fi 1435 fi
922} 1436}
923 1437
924# ------------------------------------------------------------------------------ 1438# ------------------------------------------------------------------------------
925# @internal-function java-pkg_is-vm-version-sufficient 1439# @internal-function java-pkg_is-vm-version-sufficient
926# 1440#
927# @return zero - VM is sufficient 1441# @return zero - VM is sufficient
928# @return non-zero - VM is not sufficient 1442# @return non-zero - VM is not sufficient
929# ------------------------------------------------------------------------------ 1443# ------------------------------------------------------------------------------
930java-pkg_is-vm-version-sufficient() { 1444java-pkg_is-vm-version-sufficient() {
931 debug-print-function ${FUNCNAME} $* 1445 debug-print-function ${FUNCNAME} $*
951 die "Active Java VM too old" 1465 die "Active Java VM too old"
952 fi 1466 fi
953} 1467}
954 1468
955# ------------------------------------------------------------------------------ 1469# ------------------------------------------------------------------------------
956# @internal-function java-pkg_is-vm-version-eq 1470# @internal-function java-pkg_is-vm-version-eq
957# 1471#
958# @param $@ - VM version to compare current VM to 1472# @param $@ - VM version to compare current VM to
959# @return zero - VM versions are equal 1473# @return zero - VM versions are equal
960# @return non-zero - VM version are not equal 1474# @return non-zero - VM version are not equal
961# ------------------------------------------------------------------------------ 1475# ------------------------------------------------------------------------------
962java-pkg_is-vm-version-eq() { 1476java-pkg_is-vm-version-eq() {
992# 1506#
993# @param $@ - VM version to compare current to 1507# @param $@ - VM version to compare current to
994# ------------------------------------------------------------------------------ 1508# ------------------------------------------------------------------------------
995java-pkg_ensure-vm-version-ge() { 1509java-pkg_ensure-vm-version-ge() {
996 debug-print-function ${FUNCNAME} $* 1510 debug-print-function ${FUNCNAME} $*
997 1511
998 if ! java-pkg_is-vm-version-ge "$@" ; then 1512 if ! java-pkg_is-vm-version-ge "$@" ; then
999 debug-print "vm is not suffient" 1513 debug-print "vm is not suffient"
1000 eerror "This package requires a Java VM version >= $@" 1514 eerror "This package requires a Java VM version >= $@"
1001 einfo "Please use java-config -S to set the correct one" 1515 einfo "Please use java-config -S to set the correct one"
1002 die "Active Java VM too old" 1516 die "Active Java VM too old"
1003 fi 1517 fi
1004} 1518}
1005 1519
1006# ------------------------------------------------------------------------------ 1520# ------------------------------------------------------------------------------
1007# @internal-function java-pkg_is-vm-version-ge 1521# @internal-function java-pkg_is-vm-version-ge
1008# 1522#
1009# @param $@ - VM version to compare current VM to 1523# @param $@ - VM version to compare current VM to
1010# @return zero - current VM version is greater than checked version 1524# @return zero - current VM version is greater than checked version
1011# @return non-zero - current VM version is not greater than checked version 1525# @return non-zero - current VM version is not greater than checked version
1012# ------------------------------------------------------------------------------ 1526# ------------------------------------------------------------------------------
1013java-pkg_is-vm-version-ge() { 1527java-pkg_is-vm-version-ge() {
1027 return 1 1541 return 1
1028 fi 1542 fi
1029 fi 1543 fi
1030} 1544}
1031 1545
1546java-pkg_set-current-vm() {
1547 export GENTOO_VM=${1}
1548}
1549
1550java-pkg_get-current-vm() {
1551 echo ${GENTOO_VM}
1552}
1553
1554java-pkg_current-vm-matches() {
1555 hasq $(java-pkg_get-current-vm) ${@}
1556 return $?
1557}
1558
1032# ------------------------------------------------------------------------------ 1559# ------------------------------------------------------------------------------
1033# @ebuild-function java-pkg_get-source 1560# @ebuild-function java-pkg_get-source
1034# 1561#
1035# Determines what source version should be used, for passing to -source. 1562# Determines what source version should be used, for passing to -source.
1036# Unless you want to break things you probably shouldn't set _WANT_SOURCE 1563# Unless you want to break things you probably shouldn't set _WANT_SOURCE
1037# 1564#
1038# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE 1565# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1039# ------------------------------------------------------------------------------ 1566# ------------------------------------------------------------------------------
1044# ------------------------------------------------------------------------------ 1571# ------------------------------------------------------------------------------
1045# @ebuild-function java-pkg_get-target 1572# @ebuild-function java-pkg_get-target
1046# 1573#
1047# Determines what target version should be used, for passing to -target. 1574# Determines what target version should be used, for passing to -target.
1048# If you don't care about lower versions, you can set _WANT_TARGET to the 1575# If you don't care about lower versions, you can set _WANT_TARGET to the
1049# version of your JDK. 1576# version of your JDK.
1050# Remember doing this will mostly like cause things to break.
1051# Doesn't allow it to be lower then the one in depend.
1052# Doesn't allow it to be higher then the active vm.
1053# 1577#
1054# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1578# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1055# ------------------------------------------------------------------------------ 1579# ------------------------------------------------------------------------------
1056java-pkg_get-target() { 1580java-pkg_get-target() {
1057 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")
1058 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then
1059 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)"
1060 if version_is_at_least "${min}" "${JAVA_PKG_WANT_TARGET}" && version_is_at_least "${JAVA_PKG_WANT_TARGET}" "${max}"; then
1061 echo ${JAVA_PKG_WANT_TARGET}
1062 else
1063 echo ${min}
1064 fi
1065 else
1066 echo ${min}
1067 fi
1068
1069 #echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND}")} 1581 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1070} 1582}
1071 1583
1072java-pkg_get-javac() { 1584java-pkg_get-javac() {
1073 debug-print-function ${FUNCNAME} $* 1585 debug-print-function ${FUNCNAME} $*
1074 1586
1075 java-pkg_init-compiler_ 1587
1076 local compiler="${GENTOO_COMPILER}" 1588 local compiler="${GENTOO_COMPILER}"
1077 1589
1078 local compiler_executable 1590 local compiler_executable
1079 if [[ "${compiler}" = "javac" ]]; then 1591 if [[ "${compiler}" = "javac" ]]; then
1080 # nothing fancy needs to be done for javac 1592 # nothing fancy needs to be done for javac
1088 unset JAVAC 1600 unset JAVAC
1089 # try to get value of JAVAC 1601 # try to get value of JAVAC
1090 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1602 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1091 export JAVAC=${old_javac} 1603 export JAVAC=${old_javac}
1092 1604
1093 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1605 if [[ -z ${compiler_executable} ]]; then
1094 1606 echo "JAVAC is empty or undefined in ${compiler_env}"
1607 return 1
1608 fi
1609
1095 # check that it's executable 1610 # check that it's executable
1096 if [[ ! -x ${compiler_executable} ]]; then 1611 if [[ ! -x ${compiler_executable} ]]; then
1097 eerror "Could not find ${compiler_executable}!"
1098 die "${compiler_executable} doesn't exist, or isn't executable" 1612 echo "${compiler_executable} doesn't exist, or isn't executable"
1613 return 1
1099 fi 1614 fi
1100 else 1615 else
1101 eerror "Could not find environment file for ${compiler}" 1616 echo "Could not find environment file for ${compiler}"
1102 die "Could not find ${compiler_env}" 1617 return 1
1103 fi 1618 fi
1104 fi 1619 fi
1105 echo ${compiler_executable} 1620 echo ${compiler_executable}
1106} 1621}
1107 1622
1108# ------------------------------------------------------------------------------ 1623# ------------------------------------------------------------------------------
1109# @ebuild-function java-pkg_javac-args 1624# @ebuild-function java-pkg_javac-args
1110# 1625#
1111# If an ebuild uses javac directly, instead of using ejavac, it should call this 1626# If an ebuild uses javac directly, instead of using ejavac, it should call this
1112# to know what -source/-target to use. 1627# to know what -source/-target to use.
1113# 1628#
1114# @return string - arguments to pass to javac, complete with -target and -source 1629# @return string - arguments to pass to javac, complete with -target and -source
1117 debug-print-function ${FUNCNAME} $* 1632 debug-print-function ${FUNCNAME} $*
1118 1633
1119 local want_source="$(java-pkg_get-source)" 1634 local want_source="$(java-pkg_get-source)"
1120 local want_target="$(java-pkg_get-target)" 1635 local want_target="$(java-pkg_get-target)"
1121 1636
1122 local source_str="-source ${want_source}" 1637 local source_str="-source ${want_source}"
1123 local target_str="-target ${want_target}" 1638 local target_str="-target ${want_target}"
1124 1639
1125 debug-print "want source: ${want_source}" 1640 debug-print "want source: ${want_source}"
1126 debug-print "want target: ${want_target}" 1641 debug-print "want target: ${want_target}"
1127 1642
1128 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1643 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1129 debug-print "could not find valid -source/-target values" 1644 debug-print "could not find valid -source/-target values for javac"
1130 die "Could not find valid -source/-target values" 1645 echo "Could not find valid -source/-target values for javac"
1646 return 1
1131 else 1647 else
1132 if java-pkg_is-vm-version-ge "1.4"; then 1648 if java-pkg_is-vm-version-ge "1.4"; then
1133 echo "${source_str} ${target_str}" 1649 echo "${source_str} ${target_str}"
1134 else 1650 else
1135 echo "${target_str}" 1651 echo "${target_str}"
1139 1655
1140# TODO document 1656# TODO document
1141java-pkg_get-jni-cflags() { 1657java-pkg_get-jni-cflags() {
1142 local flags="-I${JAVA_HOME}/include" 1658 local flags="-I${JAVA_HOME}/include"
1143 1659
1144 # TODO figure out how to cope with other things than linux... 1660 local platform="linux"
1661 use elibc_FreeBSD && platform="freebsd"
1662
1663 # TODO do a check that the directories are valid
1145 flags="${flags} -I${JAVA_HOME}/include/linux" 1664 flags="${flags} -I${JAVA_HOME}/include/${platform}"
1146 1665
1147 echo ${flags} 1666 echo ${flags}
1667}
1668
1669java-pkg_ensure-gcj() {
1670 if ! built_with_use sys-devel/gcc gcj ; then
1671 ewarn
1672 ewarn "You must build gcc with the gcj support to build with gcj"
1673 ewarn
1674 ebeep 5
1675 die "No GCJ support found!"
1676 fi
1677}
1678
1679java-pkg_ensure-test() {
1680 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \
1681 && hasq test ${IUSE} && ! use test;
1682 then
1683 eerror "You specified FEATURES=test, but USE=test is needed"
1684 eerror "to pull in the additional dependencies for testing"
1685 die "Need USE=test enabled"
1686 fi
1687}
1688
1689# ------------------------------------------------------------------------------
1690# @ebuild-function java-pkg_register-ant-task
1691#
1692# Register this package as ant task, so that ant will load it when no specific
1693# ANT_TASKS are specified. Note that even without this registering, all packages
1694# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1695# packages, but can be also used by other ebuilds that used to symlink their
1696# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1697# compatibility.
1698#
1699# @param --version x.y Register only for ant version x.y (otherwise for any ant
1700# version). Used by the ant-* packages to prevent loading of mismatched
1701# ant-core ant tasks after core was updated, before the tasks are updated,
1702# without a need for blockers.
1703# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1704# ------------------------------------------------------------------------------
1705java-pkg_register-ant-task() {
1706 local TASKS_DIR="tasks"
1707
1708 # check for --version x.y parameters
1709 while [[ -n "${1}" && -n "${2}" ]]; do
1710 local var="${1#--}"
1711 local val="${2}"
1712 if [[ "${var}" == "version" ]]; then
1713 TASKS_DIR="tasks-${val}"
1714 else
1715 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1716 fi
1717 shift 2
1718 done
1719
1720 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1721
1722 dodir /usr/share/ant/${TASKS_DIR}
1723 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1724}
1725
1726# ------------------------------------------------------------------------------
1727# @internal-function java-pkg_ant-tasks-from-deps
1728#
1729# Function to determine ANT_TASKS from DEPEND variable for backwards
1730# compatibility with ebuilds that don't set ANT_TASKS before calling eant() or
1731# WANT_ANT_TASKS before inheriting java-pkg-2. If the DEPEND string contains
1732# "dev-java/ant" or "dev-java/ant-tasks", then it returns "all", otherwise
1733# "none". It's not smart enough to cope with USE flag depends but that shouldn't
1734# be a problem, the worst it can do is activace all tasks when not needed.
1735# Note that this is called only with JAVA_PKG_STRICT=1, to find ebuilds with
1736# insufficient dependencies, otherwise all available tasks are used for
1737# backwards compatilbility.
1738#
1739# @return "all" or "none"
1740# ------------------------------------------------------------------------------
1741java-pkg_ant-tasks-from-deps() {
1742 local found_ant found_ant_tasks
1743
1744 for dep in ${DEPEND}
1745 do
1746 local ant="$(awk '/(dev-java\/ant)/ { if (match($1, "(dev-java/ant)((-[0-9])+|$)", m)) print m[1] }' <<< ${dep})"
1747 [[ "${ant}" == "dev-java/ant" ]] && found_ant=true
1748 [[ "${dep}" == *"ant-tasks"* ]] && found_ant_tasks=true
1749 done
1750
1751 if [[ -n "${found_ant}" || -n "${found_ant_tasks}" ]]; then
1752 java-pkg_announce-qa-violation --nodie "The ebuild DEPENDS on deprecated ant or ant-tasks"
1753 echo "all"
1754 else
1755 # ebuild doesn't set ANT_TASKS and doesn't depend on ant-tasks or ant
1756 # so we deactivate all tasks that may be installed
1757 echo "none"
1758 fi
1759}
1760
1761# ------------------------------------------------------------------------------
1762# @internal-function java-pkg_ant-tasks-depend
1763#
1764# Translates the WANT_ANT_TASKS variable into valid dependencies.
1765# ------------------------------------------------------------------------------
1766java-pkg_ant-tasks-depend() {
1767 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1768
1769 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1770 local DEP=""
1771 for i in ${WANT_ANT_TASKS}
1772 do
1773 if [[ ${i} != ant-* ]]; then
1774 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1775 return 1
1776 fi
1777 DEP="${DEP}dev-java/${i} "
1778 done
1779 echo ${DEP}
1780 return 0
1781 else
1782 return 0
1783 fi
1784}
1785
1786# ------------------------------------------------------------------------------
1787# @ebuild-function ejunit
1788#
1789# Junit wrapper function. Makes it easier to run the tests and checks for
1790# dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner.
1791#
1792# Examples:
1793# ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1794# ejunit org.blinkenlights.jid3.test.AllTests
1795#
1796# @param $1 - -cp or -classpath
1797# @param $2 - classpath; junit and recorded dependencies get appended
1798# @param $@ - the rest of the parameters are passed to java
1799# ------------------------------------------------------------------------------
1800ejunit() {
1801 debug-print-function ${FUNCNAME} $*
1802
1803 local pkgs
1804 for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
1805 pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
1806 done
1807
1808 local cp=$(java-pkg_getjars --with-dependencies junit${pkgs})
1809 if [[ ${1} = -cp || ${1} = -classpath ]]; then
1810 cp="${2}:${cp}"
1811 shift 2
1812 else
1813 cp=".:${cp}"
1814 fi
1815
1816 local runner=junit.textui.TestRunner
1817 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}"
1818 java -cp "${cp}" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
1148} 1819}
1149 1820
1150# ------------------------------------------------------------------------------ 1821# ------------------------------------------------------------------------------
1151# @section-end helper 1822# @section-end helper
1152# ------------------------------------------------------------------------------ 1823# ------------------------------------------------------------------------------
1161 1832
1162# ------------------------------------------------------------------------------ 1833# ------------------------------------------------------------------------------
1163# @ebuild-function eant 1834# @ebuild-function eant
1164# 1835#
1165# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1836# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1166# compiler. 1837# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1167# 1838# variables:
1839# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1840# gentoo.classpath property. Be sure to call
1841# java-ant_rewrite-classpath in src_unpack.
1842# JAVA_PKG_NO_BUNDLED_SEARCH - Don't search for bundled jars or class files
1843# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1168# ------------------------------------------------------------------------------ 1844# ------------------------------------------------------------------------------
1169eant() { 1845eant() {
1170 debug-print-function ${FUNCNAME} $* 1846 debug-print-function ${FUNCNAME} $*
1171 1847
1172 local antflags 1848 if [[ ${EBUILD_PHASE} = compile ]]; then
1849 # Used to be done in hooks in java-ant-2.eclass but moved here so that we can
1850 # finally get rid of the hooks without breaking stuff
1851
1852 [[ "${JAVA_ANT_IGNORE_SYSTEM_CLASSES}" && "${JAVA_PKG_BSFIX}" ]] \
1853 && java-ant_ignore-system-classes "${S}/build.xml"
1854
1855 if hasq java-ant-2 ${INHERITED}; then
1856 java-ant_bsfix
1857 fi
1858
1859 # eant can be called multiple times
1860 JAVA_PKG_BSFIX="off"
1861
1862 if [[ -z ${JAVA_PKG_NO_BUNDLED_SEARCH} ]] && is-java-strict; then
1863 echo "Searching for bundled jars:"
1864 java-pkg_find-normal-jars || echo "None found."
1865 echo "Searching for bundled classes (no output if none found):"
1866 find "${WORKDIR}" -name "*.class"
1867 echo "Search done."
1868 JAVA_PKG_NO_BUNDLED_SEARCH=true # eant can be called many times
1869 fi
1870 fi
1871
1872 if ! hasq java-ant-2 ${INHERITED}; then
1873 local msg="You should inherit java-ant-2 when using eant"
1874 java-pkg_announce-qa-violation "${msg}"
1875 fi
1876
1877 local antflags="-Dnoget=true -Dmaven.mode.offline=true -Dbuild.sysclasspath=ignore"
1878
1173 java-pkg_init-compiler_ 1879 java-pkg_init-compiler_
1174 local compiler="${GENTOO_COMPILER}" 1880 local compiler="${GENTOO_COMPILER}"
1175 1881
1176 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1882 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1177
1178 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})" 1883 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})"
1179 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1884 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1180 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1885 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1181 fi 1886 fi
1182 1887
1183 if [[ ${compiler} != "javac" ]]; then 1888 if [[ ${compiler} != "javac" ]]; then
1184 antflags="-Dbuild.compiler=${build_compiler}" 1889 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1185 # Figure out any extra stuff to put on the classpath for compilers aside 1890 # Figure out any extra stuff to put on the classpath for compilers aside
1186 # from javac 1891 # from javac
1187 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to 1892 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1188 # java-config -p 1893 # java-config -p
1189 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1894 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})"
1190 if [[ -n ${build_compiler_deps} ]]; then 1895 if [[ -n ${build_compiler_deps} ]]; then
1191 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})" 1896 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1192 fi 1897 fi
1193 fi 1898 fi
1194 1899
1195 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1900 for arg in "${@}"; do
1196 antflags="${antflags} -debug" 1901 if [[ ${arg} = -lib ]]; then
1902 if is-java-strict; then
1903 eerror "You should not use the -lib argument to eant because it will fail"
1904 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1905 eerror "or ant properties to make dependencies available."
1906 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1907 eerror "split ant (>=dev-java/ant-core-1.7)."
1908 die "eant -lib is deprecated/forbidden"
1909 else
1910 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1911 echo "more info."
1912 fi
1197 fi 1913 fi
1198 1914 done
1915
1916 # we use this in src_* so we run ant from /
1917 if ROOT=/ has_version ">=dev-java/ant-core-1.7.0"; then
1918 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1919 ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}"
1920
1921 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1922 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1923
1924 if is-java-strict; then
1925 # if ant-tasks were not set by ebuild or forced, try to determine them from depends
1926 if [[ -z "${ANT_TASKS}" ]]; then
1927 ANT_TASKS="$(java-pkg_ant-tasks-from-deps)"
1928 fi
1929 else
1930 # if ant-tasks is not set by ebuild or forced, activate all of them
1931 ANT_TASKS="${ANT_TASKS:-all}"
1932 fi
1933
1934 # at this point, ANT_TASKS should be "all", "none" or explicit list
1935 if [[ "${ANT_TASKS}" == "all" ]]; then
1936 einfo "Using all available ANT_TASKS"
1937 elif [[ "${ANT_TASKS}" == "none" ]]; then
1938 einfo "Disabling all optional ANT_TASKS"
1939 else
1940 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1941 fi
1942
1943 export ANT_TASKS
1944 fi
1945
1946 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1947 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1948
1949 local gcp="${EANT_GENTOO_CLASSPATH}"
1950 local getjarsarg=""
1951
1952 if [[ ${EBUILD_PHASE} = "test" ]]; then
1953 antflags="${antflags} -DJunit.present=true"
1954 [[ ${gcp} && ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1955 getjarsarg="--with-dependencies"
1956 fi
1957
1958 local cp
1959
1960 for atom in ${gcp}; do
1961 cp="${cp}:$(java-pkg_getjars ${getjarsarg} ${atom})"
1962 done
1963
1964 if [[ ${cp} ]]; then
1965 # It seems ant does not like single quotes around ${cp}
1966 antflags="${antflags} -Dgentoo.classpath=\"${cp#:}\""
1967 fi
1968
1199 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1969 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1970 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
1200 ant ${antflags} "${@}" || die "eant failed" 1971 ant ${antflags} "${@}" || die "eant failed"
1201
1202} 1972}
1203 1973
1204# ------------------------------------------------------------------------------ 1974# ------------------------------------------------------------------------------
1205# @ebuild-function ejavac 1975# @ebuild-function ejavac
1206# 1976#
1207# Javac wrapper function. Will use the appropriate compiler, based on 1977# Javac wrapper function. Will use the appropriate compiler, based on
1208# /etc/java-config/compilers.conf 1978# /etc/java-config/compilers.conf
1209# 1979#
1210# @param $@ - Arguments to be passed to the compiler 1980# @param $@ - Arguments to be passed to the compiler
1211# ------------------------------------------------------------------------------ 1981# ------------------------------------------------------------------------------
1212ejavac() { 1982ejavac() {
1213 debug-print-function ${FUNCNAME} $* 1983 debug-print-function ${FUNCNAME} $*
1214 1984
1985 java-pkg_init-compiler_
1986
1987 local compiler_executable
1215 local compiler_executable=$(java-pkg_get-javac) 1988 compiler_executable=$(java-pkg_get-javac)
1989 if [[ ${?} != 0 ]]; then
1990 eerror "There was a problem determining compiler: ${compiler_executable}"
1991 die "get-javac failed"
1992 fi
1216 1993
1994 local javac_args
1995 javac_args="$(java-pkg_javac-args)"
1996 if [[ ${?} != 0 ]]; then
1997 eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
1998 die "java-pkg_javac-args failed"
1999 fi
2000
1217 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 2001 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1218 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 2002 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1219} 2003}
1220 2004
1221# ------------------------------------------------------------------------------ 2005# ------------------------------------------------------------------------------
1222# @ebuild-function java-pkg_filter-compiler 2006# @ebuild-function java-pkg_filter-compiler
1223# 2007#
1224# Used to prevent the use of some compilers. Should be used in src_compile. 2008# Used to prevent the use of some compilers. Should be used in src_compile.
1225# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER 2009# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
1226# 2010#
1227# @param $@ - compilers to filter 2011# @param $@ - compilers to filter
1228# ------------------------------------------------------------------------------ 2012# ------------------------------------------------------------------------------
1229java-pkg_filter-compiler() { 2013java-pkg_filter-compiler() {
1230 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@" 2014 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@"
1231} 2015}
1232 2016
1233# ------------------------------------------------------------------------------ 2017# ------------------------------------------------------------------------------
2018# @ebuild-function java-pkg_force-compiler
2019#
2020# Used to force the use of particular compilers. Should be used in src_compile.
2021# A common use of this would be to force ecj-3.1 to be used on amd64, to avoid
2022# OutOfMemoryErrors that may come up.
2023#
2024# @param $@ - compilers to force
2025# ------------------------------------------------------------------------------
2026java-pkg_force-compiler() {
2027 JAVA_PKG_FORCE_COMPILER="$@"
2028}
2029
2030# ------------------------------------------------------------------------------
1234# @ebuild-function use_doc 2031# @ebuild-function use_doc
1235# 2032#
1236# Helper function for getting ant to build javadocs. If the user has USE=doc, 2033# Helper function for getting ant to build javadocs. If the user has USE=doc,
1237# then 'javadoc' or the argument are returned. Otherwise, there is no return. 2034# then 'javadoc' or the argument are returned. Otherwise, there is no return.
1238# 2035#
1239# The output of this should be passed to ant. 2036# The output of this should be passed to ant.
1240# 2037#
1241# Example: build javadocs by calling 'javadoc' target 2038# Example: build javadocs by calling 'javadoc' target
1242# eant $(use_doc) 2039# eant $(use_doc)
1243# Example: build javadocs by calling 'apidoc' target 2040# Example: build javadocs by calling 'apidoc' target
1248# ------------------------------------------------------------------------------ 2045# ------------------------------------------------------------------------------
1249use_doc() { 2046use_doc() {
1250 use doc && echo ${@:-javadoc} 2047 use doc && echo ${@:-javadoc}
1251} 2048}
1252 2049
2050
1253# ------------------------------------------------------------------------------ 2051# ------------------------------------------------------------------------------
1254# @section-end build 2052# @section-end build
1255# ------------------------------------------------------------------------------ 2053# ------------------------------------------------------------------------------
1256 2054
1257# ------------------------------------------------------------------------------ 2055# ------------------------------------------------------------------------------
1258# @section-begin internal 2056# @section-begin internal
1259# @section-summary Internal functions 2057# @section-summary Internal functions
1260# 2058#
1261# Do __NOT__ use any of these from an ebuild! These are only to be used from 2059# Do __NOT__ use any of these from an ebuild! These are only to be used from
1262# within the java eclasses. 2060# within the java eclasses.
1263# ------------------------------------------------------------------------------ 2061# ------------------------------------------------------------------------------
1264 2062
1265# ----------------------------------------------------------------------------- 2063# -----------------------------------------------------------------------------
1266# @function-internal java-pkg_init 2064# @function-internal java-pkg_init
1267# 2065#
1268# The purpose of this function, as the name might imply, is to initialize the 2066# The purpose of this function, as the name might imply, is to initialize the
1269# Java environment. It ensures that that there aren't any environment variables 2067# Java environment. It ensures that that there aren't any environment variables
1270# that'll muss things up. It initializes some variables, which are used 2068# that'll muss things up. It initializes some variables, which are used
1271# internally. And most importantly, it'll switch the VM if necessary. 2069# internally. And most importantly, it'll switch the VM if necessary.
1272# 2070#
1273# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will 2071# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will
1274# call it during each of the phases of the merge process. 2072# call it during each of the phases of the merge process.
1275# 2073#
1276# ----------------------------------------------------------------------------- 2074# -----------------------------------------------------------------------------
1277java-pkg_init() { 2075java-pkg_init() {
2076 debug-print-function ${FUNCNAME} $*
1278 unset JAVAC 2077 unset JAVAC
1279 unset JAVA_HOME 2078 unset JAVA_HOME
2079
2080 # People do all kinds of weird things.
2081 # http://forums.gentoo.org/viewtopic-p-3943166.html
2082 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
2083 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
2084 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
2085 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
2086 ewarn "sun-jdk vms and and as such break configure scripts that"
2087 ewarn "use it (for example app-office/openoffice) so we filter it out."
2088 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
2089 ewarn "make.conf for example) to silence this warning or"
2090 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
2091 fi
2092
2093 if [[ -z ${accept} ]]; then
2094 # export _JAVA_OPTIONS= doesn't work because it will show up in java
2095 # -version output
2096 unset _JAVA_OPTIONS
2097 # phase hooks make this run many times without this
2098 I_WANT_GLOBAL_JAVA_OPTIONS="true"
2099 fi
2100
2101 if java-pkg_func-exists ant_src_unpack; then
2102 java-pkg_announce-qa-violation "Using old ant_src_unpack. Should be src_unpack"
2103 fi
2104
1280 java-pkg_init_paths_ 2105 java-pkg_init_paths_
1281 java-pkg_switch-vm 2106 java-pkg_switch-vm
1282 PATH=${JAVA_HOME}/bin:${PATH} 2107 PATH=${JAVA_HOME}/bin:${PATH}
1283 2108
1284 # TODO we will probably want to set JAVAC and JAVACFLAGS 2109 # TODO we will probably want to set JAVAC and JAVACFLAGS
1285 2110
1286 # Do some QA checks 2111 # Do some QA checks
1287 java-pkg_check-jikes 2112 java-pkg_check-jikes
1288 2113
2114 # Can't use unset here because Portage does not save the unset
2115 # see https://bugs.gentoo.org/show_bug.cgi?id=189417#c11
2116
1289 # When users have crazy classpaths some packages can fail to compile. 2117 # When users have crazy classpaths some packages can fail to compile.
1290 # and everything should work with empty CLASSPATH. 2118 # and everything should work with empty CLASSPATH.
1291 # This also helps prevent unexpected dependencies on random things 2119 # This also helps prevent unexpected dependencies on random things
1292 # from the CLASSPATH. 2120 # from the CLASSPATH.
1293 unset CLASSPATH 2121 export CLASSPATH=
2122
2123 # Unset external ANT_ stuff
2124 export ANT_TASKS=
2125 export ANT_OPTS=
1294} 2126}
1295 2127
1296# ------------------------------------------------------------------------------ 2128# ------------------------------------------------------------------------------
1297# @function-internal java-pkg-init-compiler_ 2129# @function-internal java-pkg-init-compiler_
1298# 2130#
1299# This function attempts to figure out what compiler should be used. It does 2131# This function attempts to figure out what compiler should be used. It does
1300# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the 2132# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
1301# COMPILERS variable defined there. 2133# COMPILERS variable defined there.
1302# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER 2134# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
1303# 2135#
1304# It will go through the list of compilers, and verify that it supports the 2136# It will go through the list of compilers, and verify that it supports the
1305# target and source that are needed. If it is not suitable, then the next 2137# target and source that are needed. If it is not suitable, then the next
1306# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking 2138# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
1307# isn't done. 2139# isn't done.
1308# 2140#
1324 if [[ -n ${GENTOO_COMPILER} ]]; then 2156 if [[ -n ${GENTOO_COMPILER} ]]; then
1325 debug-print "GENTOO_COMPILER already set" 2157 debug-print "GENTOO_COMPILER already set"
1326 return 2158 return
1327 fi 2159 fi
1328 2160
2161 local compilers;
2162 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1329 local compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})" 2163 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
2164 else
2165 compilers=${JAVA_PKG_FORCE_COMPILER}
2166 fi
2167
1330 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}" 2168 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
1331 2169
1332 # Figure out if we should announce what compiler we're using 2170 # Figure out if we should announce what compiler we're using
1333 local compiler 2171 local compiler
1334 for compiler in ${compilers}; do 2172 for compiler in ${compilers}; do
1337 if [[ ${compiler} = "javac" ]]; then 2175 if [[ ${compiler} = "javac" ]]; then
1338 debug-print "Found javac... breaking" 2176 debug-print "Found javac... breaking"
1339 export GENTOO_COMPILER="javac" 2177 export GENTOO_COMPILER="javac"
1340 break 2178 break
1341 fi 2179 fi
1342 2180
1343 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then 2181 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
1344 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 2182 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1345 einfo "Filtering ${compiler}" 2183 einfo "Filtering ${compiler}"
1346 continue 2184 continue
1347 fi 2185 fi
1348 fi 2186 fi
1349 2187
1350 # for non-javac, we need to make sure it supports the right target and 2188 # for non-javac, we need to make sure it supports the right target and
1351 # source 2189 # source
1352 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 2190 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1353 if [[ -f ${compiler_env} ]]; then 2191 if [[ -f ${compiler_env} ]]; then
1354 local desired_target="$(java-pkg_get-target)" 2192 local desired_target="$(java-pkg_get-target)"
1414 fi 2252 fi
1415 2253
1416 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}" 2254 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}"
1417 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/" 2255 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/"
1418 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env" 2256 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env"
2257 JAVA_PKG_VIRTUALS_PATH="${DESTTREE}/share/java-config-2/virtuals"
2258 JAVA_PKG_VIRTUAL_PROVIDER="${D}/${JAVA_PKG_VIRTUALS_PATH}/${JAVA_PKG_NAME}"
1419 2259
1420 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib" 2260 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib"
1421 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}" 2261 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}"
1422 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps" 2262 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps"
1423 2263
1436# Writes the package.env out to disk. 2276# Writes the package.env out to disk.
1437# 2277#
1438# ------------------------------------------------------------------------------ 2278# ------------------------------------------------------------------------------
1439# TODO change to do-write, to match everything else 2279# TODO change to do-write, to match everything else
1440java-pkg_do_write_() { 2280java-pkg_do_write_() {
2281 debug-print-function ${FUNCNAME} $*
2282 java-pkg_init_paths_
1441 # Create directory for package.env 2283 # Create directory for package.env
1442 dodir "${JAVA_PKG_SHAREPATH}" 2284 dodir "${JAVA_PKG_SHAREPATH}"
1443 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 2285 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f \
2286 "${JAVA_PKG_DEPEND_FILE}" || -f \
2287 "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]]; then
1444 # Create package.env 2288 # Create package.env
1445 ( 2289 (
1446 echo "DESCRIPTION=\"${DESCRIPTION}\"" 2290 echo "DESCRIPTION=\"${DESCRIPTION}\""
1447 echo "GENERATION=\"2\"" 2291 echo "GENERATION=\"2\""
1448 2292
1449 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\"" 2293 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
1450 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 2294 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1451 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 2295 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1452 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 2296 [[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
2297 && echo "DEPEND=\"$(cat "${JAVA_PKG_DEPEND_FILE}" | uniq | tr '\n' ':')\""
2298 [[ -f "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]] \
2299 && echo "OPTIONAL_DEPEND=\"$(cat "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" | uniq | tr '\n' ':')\""
1453 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 2300 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1454 ) > "${JAVA_PKG_ENV}" 2301 ) > "${JAVA_PKG_ENV}"
1455 2302
1456 # register target/source 2303 # register target/source
1457 local target="$(java-pkg_get-target)" 2304 local target="$(java-pkg_get-target)"
1458 local source="$(java-pkg_get-source)" 2305 local source="$(java-pkg_get-source)"
1459 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}" 2306 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
1460 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}" 2307 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
1468 2315
1469 2316
1470 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}" 2317 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
1471 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}" 2318 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
1472 2319
2320 # extra env variables
2321 if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
2322 cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}" || die
2323 # nested echo to remove leading/trailing spaces
2324 echo "ENV_VARS=\"$(echo ${JAVA_PKG_EXTRA_ENV_VARS})\"" \
2325 >> "${JAVA_PKG_ENV}" || die
2326 fi
2327
1473 # Strip unnecessary leading and trailing colons 2328 # Strip unnecessary leading and trailing colons
1474 # TODO try to cleanup if possible 2329 # TODO try to cleanup if possible
1475 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 2330 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
2331 else
2332 debug-print "JAVA_PKG_CLASSPATH, JAVA_PKG_LIBRARY, JAVA_PKG_DEPEND_FILE"
2333 debug-print "or JAVA_PKG_OPTIONAL_DEPEND_FILE not defined so can't"
2334 debug-print "write package.env."
1476 fi 2335 fi
1477} 2336}
1478
1479 2337
1480# ------------------------------------------------------------------------------ 2338# ------------------------------------------------------------------------------
1481# @internal-function java-pkg_record-jar_ 2339# @internal-function java-pkg_record-jar_
1482# 2340#
1483# Record a dependency to the package.env 2341# Record an (optional) dependency to the package.env
1484# 2342# @param --optional - record dependency as optional
2343# @param $1 - package to record
2344# @param $2 - (optional) jar of package to record
1485# ------------------------------------------------------------------------------ 2345# ------------------------------------------------------------------------------
1486JAVA_PKG_DEPEND="${T}/java-pkg-depend" 2346JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2347JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
1487 2348
1488java-pkg_record-jar_() { 2349java-pkg_record-jar_() {
1489 debug-print-function ${FUNCNAME} $* 2350 debug-print-function ${FUNCNAME} $*
2351
2352 local depend_file="${JAVA_PKG_DEPEND_FILE}"
2353 if [[ "${1}" == "--optional" ]]; then
2354 depend_file="${JAVA_PKG_OPTIONAL_DEPEND_FILE}"
2355 shift
2356 fi
1490 2357
1491 local pkg=${1} jar=${2} append 2358 local pkg=${1} jar=${2} append
1492 if [[ -z "${jar}" ]]; then 2359 if [[ -z "${jar}" ]]; then
1493 append="${pkg}" 2360 append="${pkg}"
1494 else 2361 else
1495 append="$(basename ${jar})@${pkg}" 2362 append="$(basename ${jar})@${pkg}"
1496 fi 2363 fi
1497 2364
1498 echo ${append} >> ${JAVA_PKG_DEPEND} 2365 echo "${append}" >> "${depend_file}"
1499} 2366}
1500 2367
1501# ------------------------------------------------------------------------------ 2368# ------------------------------------------------------------------------------
1502# @internal-function java-pkg_append_ 2369# @internal-function java-pkg_append_
1503# 2370#
1527 fi 2394 fi
1528} 2395}
1529 2396
1530# ------------------------------------------------------------------------------ 2397# ------------------------------------------------------------------------------
1531# @internal-function java-pkg_expand_dir_ 2398# @internal-function java-pkg_expand_dir_
1532# 2399#
1533# Gets the full path of the file/directory's parent. 2400# Gets the full path of the file/directory's parent.
1534# @param $1 - file/directory to find parent directory for 2401# @param $1 - file/directory to find parent directory for
1535# @return - path to $1's parent directory 2402# @return - path to $1's parent directory
1536# ------------------------------------------------------------------------------ 2403# ------------------------------------------------------------------------------
1537java-pkg_expand_dir_() { 2404java-pkg_expand_dir_() {
1563# 2430#
1564# ------------------------------------------------------------------------------ 2431# ------------------------------------------------------------------------------
1565java-pkg_setup-vm() { 2432java-pkg_setup-vm() {
1566 debug-print-function ${FUNCNAME} $* 2433 debug-print-function ${FUNCNAME} $*
1567 2434
2435 export LANG="C" LC_ALL="C"
2436
1568 local vendor="$(java-pkg_get-vm-vendor)" 2437 local vendor="$(java-pkg_get-vm-vendor)"
1569 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge 1 5; then 2438 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1570 addpredict "/dev/random" 2439 addpredict "/dev/random"
1571 elif [[ "${vendor}" == "ibm" ]]; then 2440 elif [[ "${vendor}" == "ibm" ]]; then
1572 addpredict "/proc/self/maps" 2441 addpredict "/proc/self/maps"
1573 addpredict "/proc/cpuinfo" 2442 addpredict "/proc/cpuinfo"
1574 export LANG="C" LC_ALL="C"
1575 elif [[ "${vendor}" == "jrockit" ]]; then 2443 elif [[ "${vendor}" == "jrockit" ]]; then
1576 addpredict "/proc/cpuinfo" 2444 addpredict "/proc/cpuinfo"
1577 fi 2445 fi
1578} 2446}
1579 2447
1623# @return - The version of the current VM 2491# @return - The version of the current VM
1624# ------------------------------------------------------------------------------ 2492# ------------------------------------------------------------------------------
1625java-pkg_get-vm-version() { 2493java-pkg_get-vm-version() {
1626 debug-print-function ${FUNCNAME} $* 2494 debug-print-function ${FUNCNAME} $*
1627 2495
1628 java-pkg_get-current-vm | sed -e "s/.*-\([0-9.]\+\).*/\1/" 2496 java-config -g PROVIDES_VERSION
1629} 2497}
1630 2498
1631# ------------------------------------------------------------------------------ 2499# ------------------------------------------------------------------------------
1632# @internal-function java-pkg_switch-vm 2500# @internal-function java-pkg_switch-vm
1633# 2501#
1634# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 2502# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1635# verify that the current VM is sufficient. 2503# verify that the current VM is sufficient.
1636# Setup the environment for the VM being used. 2504# Setup the environment for the VM being used.
1637# ------------------------------------------------------------------------------ 2505# ------------------------------------------------------------------------------
1638java-pkg_switch-vm() { 2506java-pkg_switch-vm() {
2507 debug-print-function ${FUNCNAME} $*
2508
1639 if java-pkg_needs-vm; then 2509 if java-pkg_needs-vm; then
1640 # Use the VM specified by JAVA_PKG_FORCE_VM 2510 # Use the VM specified by JAVA_PKG_FORCE_VM
1641 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then 2511 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1642 # If you're forcing the VM, I hope you know what your doing... 2512 # If you're forcing the VM, I hope you know what your doing...
2513 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1643 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 2514 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1644 # if we're allowed to switch the vm... 2515 # if we're allowed to switch the vm...
1645 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 2516 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1646 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}" 2517 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1647 if [[ -n ${JAVA_PKG_VNEED} ]]; then 2518 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1648 export GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2519 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1649 else 2520 else
1650 export GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2521 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
2522 fi
2523 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
2524 eerror "Unable to determine VM for building from dependencies:"
2525 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
2526 echo "VNEED: ${JAVA_PKG_VNEED}"
2527 die "Failed to determine VM for building."
2528 else
2529 export GENTOO_VM
1651 fi 2530 fi
1652 # otherwise just make sure the current VM is sufficient 2531 # otherwise just make sure the current VM is sufficient
1653 else 2532 else
1654 java-pkg_ensure-vm-version-sufficient 2533 java-pkg_ensure-vm-version-sufficient
1655 fi 2534 fi
1656 debug-print "Using: $(java-config -f)" 2535 debug-print "Using: $(java-config -f)"
1657 2536
1658 java-pkg_setup-vm 2537 java-pkg_setup-vm
1659 2538
2539 export JAVA=$(java-config --java)
2540 export JAVAC=$(java-config --javac)
1660 export JAVACFLAGS="$(java-pkg_javac-args)" 2541 JAVACFLAGS="$(java-pkg_javac-args)"
2542 if [[ ${?} != 0 ]]; then
2543 eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
2544 die "java-pkg_javac-args failed"
2545 fi
1661 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 2546 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
2547 export JAVACFLAGS
1662 2548
1663 export JAVA_HOME="$(java-config -g JAVA_HOME)" 2549 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1664 export JDK_HOME=${JAVA_HOME} 2550 export JDK_HOME=${JAVA_HOME}
1665 2551
1666 #TODO If you know a better solution let us know. 2552 #TODO If you know a better solution let us know.
1667 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 2553 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1668 2554
1669 local tann="${T}/announced-vm" 2555 local tann="${T}/announced-vm"
2556 # With the hooks we should only get here once from pkg_setup but better safe than sorry
2557 # if people have for example modified eclasses some where
1670 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 2558 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1671 # Add a check for setup/preinst phase... to avoid duplicate outputs
1672 # for when FEATURES=buildpkg
1673 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1674 then
1675 einfo "Using: $(java-config -f)" 2559 einfo "Using: $(java-config -f)"
1676 [[ ! -f "${tann}" ]] && touch "${tann}" 2560 [[ ! -f "${tann}" ]] && touch "${tann}"
1677 fi
1678 fi 2561 fi
1679 2562
1680 else 2563 else
1681 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!" 2564 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!"
1682 fi 2565 fi
1698 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2 2581 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2
1699 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2 2582 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2
1700 echo "and of course, the output of emerge --info" >&2 2583 echo "and of course, the output of emerge --info" >&2
1701} 2584}
1702 2585
2586
2587# TODO document
2588# List jars in the source directory, ${S}
2589java-pkg_jar-list() {
2590 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
2591 einfo "Linked Jars"
2592 find "${S}" -type l -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2593 einfo "Jars"
2594 find "${S}" -type f -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2595 einfo "Classes"
2596 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2597 fi
2598}
2599
2600# ------------------------------------------------------------------------------
2601# @internal-function java-pkg_verify-classes
2602#
2603# Verify that the classes were compiled for the right source / target. Dies if
2604# not.
2605# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2606# ------------------------------------------------------------------------------
2607java-pkg_verify-classes() {
2608 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
2609 local target=$(java-pkg_get-target)
2610 local result
2611 local log="${T}/class-version-verify.log"
2612 if [[ -n "${1}" ]]; then
2613 class-version-verify.py -v -t ${target} "${1}" > "${log}"
2614 result=$?
2615 else
2616 ebegin "Verifying java class versions (target: ${target})"
2617 class-version-verify.py -v -t ${target} -r "${D}" > "${log}"
2618 result=$?
2619 eend ${result}
2620 fi
2621 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2622 if [[ ${result} != 0 ]]; then
2623 eerror "Incorrect bytecode version found"
2624 [[ -n "${1}" ]] && eerror "in file: ${1}"
2625 eerror "See ${log} for more details."
2626 die "Incorrect bytecode found"
2627 fi
2628}
2629
2630# ----------------------------------------------------------------------------
2631# @internal-function java-pkg_ensure-dep
2632# Check that a package being used in jarfrom, getjars and getjar is contained
2633# within DEPEND or RDEPEND.
2634# @param $1 - empty - check both vars; "runtime" or "build" - check only
2635# RDEPEND, resp. DEPEND
2636# @param $2 - Package name and slot.
2637
2638java-pkg_ensure-dep() {
2639 debug-print-function ${FUNCNAME} $*
2640
2641 local limit_to="${1}"
2642 local target_pkg="${2}"
2643 local dev_error=""
2644
2645 local stripped_pkg=$(echo "${target_pkg}" | sed \
2646 's/-[0-9]*\(\.[0-9]\)*$//')
2647
2648 debug-print "Matching against: ${stripped_pkg}"
2649
2650 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2651 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2652 dev_error="${dev_error} declared in DEPEND."
2653 if is-java-strict; then
2654 eerror "${dev_error}"
2655 die "${dev_error}"
2656 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2657 eerror "${dev_error}"
2658 elog "Because you have this package installed the package will"
2659 elog "build without problems, but please report this to"
2660 elog "http://bugs.gentoo.org"
2661 fi
2662 fi
2663
2664 if [[ ${limit_to} != build ]]; then
2665 if [[ ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2666 if [[ ! ( ${PDEPEND} =~ "${stripped_pkg}" ) ]]; then
2667 dev_error="The ebuild is attempting to use ${target_pkg},"
2668 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND"
2669 dev_error="${dev_error} or PDEPEND."
2670 if is-java-strict; then
2671 eerror "${dev_error}"
2672 die "${dev_error}"
2673 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2674 eerror "${dev_error}"
2675 elog "The package will build without problems, but may fail to run"
2676 elog "if you don't have ${target_pkg} installed, so please report"
2677 elog "this to http://bugs.gentoo.org"
2678 fi
2679 fi
2680 fi
2681 fi
2682}
2683
1703# ------------------------------------------------------------------------------ 2684# ------------------------------------------------------------------------------
1704# @section-end internal 2685# @section-end internal
1705# ------------------------------------------------------------------------------ 2686# ------------------------------------------------------------------------------
1706 2687
1707java-pkg_check-phase() { 2688java-pkg_check-phase() {
1708 local phase=${1} 2689 local phase=${1}
1709 local funcname=${2} 2690 local funcname=${FUNCNAME[1]}
1710 # TODO add check for java-stricter
1711 if [[ ${EBUILD_PHASE} != ${phase} ]]; then 2691 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
1712 java-pkg_announce-qa-violation \
1713 "${funcname} used outside of src_${phase}" 2692 local msg="${funcname} used outside of src_${phase}"
2693 java-pkg_announce-qa-violation "${msg}"
1714 fi 2694 fi
1715} 2695}
1716 2696
1717java-pkg_check-versioned-jar() { 2697java-pkg_check-versioned-jar() {
1718 local jar=${1} 2698 local jar=${1}
1727 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2707 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1728 fi 2708 fi
1729} 2709}
1730 2710
1731java-pkg_announce-qa-violation() { 2711java-pkg_announce-qa-violation() {
1732 if hasq java-strict ${FEATURES}; then 2712 local nodie
2713 if [[ ${1} == "--nodie" ]]; then
2714 nodie="true"
2715 shift
2716 fi
1733 echo "Java QA Notice: $@" >&2 2717 echo "Java QA Notice: $@" >&2
1734 increment-qa-violations 2718 increment-qa-violations
1735 fi 2719 [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
1736} 2720}
1737 2721
1738increment-qa-violations() { 2722increment-qa-violations() {
1739 let "JAVA_PKG_QA_VIOLATIONS+=1" 2723 let "JAVA_PKG_QA_VIOLATIONS+=1"
1740 export JAVA_PKG_QA_VIOLATIONS 2724 export JAVA_PKG_QA_VIOLATIONS
1741} 2725}
1742 2726
2727is-java-strict() {
2728 [[ -n ${JAVA_PKG_STRICT} ]]
2729 return $?
2730}
2731
1743# ------------------------------------------------------------------------------ 2732# ------------------------------------------------------------------------------
1744# @eclass-end 2733# @eclass-end
1745# ------------------------------------------------------------------------------ 2734# ------------------------------------------------------------------------------

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.100

  ViewVC Help
Powered by ViewVC 1.1.20