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

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

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

Revision 1.3 Revision 1.98
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.98 2007/11/26 21:00:59 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: - The javadoc root directory.
563#
564# @example:
565# java-pkg_dojavadoc docs/api
566#
567# ------------------------------------------------------------------------------
418java-pkg_dojavadoc() { 568java-pkg_dojavadoc() {
569 debug-print-function ${FUNCNAME} $*
419 local dir="$1" 570 local dir="$1"
571
572 # QA checks
420 573
421 java-pkg_check-phase install 574 java-pkg_check-phase install
422 575
423 [[ -z "${dir}" ]] && die "Must specify a directory!" 576 [[ -z "${dir}" ]] && die "Must specify a directory!"
424 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!" 577 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!"
578 if [[ ! -e "${dir}/index.html" ]]; then
579 local msg="No index.html in javadoc directory"
580 ewarn "${msg}"
581 is-java-strict && die "${msg}"
582 fi
583
584 # Renaming to match our directory layout
425 585
426 local dir_to_install="${dir}" 586 local dir_to_install="${dir}"
427 if [[ "$(basename "${dir}")" != "api" ]]; then 587 if [[ "$(basename "${dir}")" != "api" ]]; then
428 dir_to_install="${T}/api" 588 dir_to_install="${T}/api"
429 # TODO use doins 589 # TODO use doins
430 cp -r "${dir}" "${dir_to_install}" || die "cp failed" 590 cp -r "${dir}" "${dir_to_install}" || die "cp failed"
431 fi 591 fi
432 592
593 # Actual installation
594
433 java-pkg_dohtml -r ${dir_to_install} 595 java-pkg_dohtml -r ${dir_to_install}
434} 596}
435 597
436# ------------------------------------------------------------------------------ 598# ------------------------------------------------------------------------------
437# @ebuild-function java-pkg_dosrc 599# @ebuild-function java-pkg_dosrc
438# 600#
439# Installs a zip containing the source for a package, so it can used in 601# Installs a zip containing the source for a package, so it can used in
440# from IDEs like eclipse and netbeans. 602# from IDEs like eclipse and netbeans.
441# 603#
442# Ebuild needs to DEPEND on app-arch/zip to use this. 604# Ebuild needs to DEPEND on app-arch/zip to use this.
443# 605#
444# It also should be controlled by USE=source. 606# It also should be controlled by USE=source.
445# 607#
446# @example: 608# @example:
447# java-pkg_dosrc src/* 609# java-pkg_dosrc src/*
448# 610#
449# ------------------------------------------------------------------------------ 611# ------------------------------------------------------------------------------
450# TODO change so it the arguments it takes are the base directories containing 612# TODO change so it the arguments it takes are the base directories containing
451# source -nichoj 613# source -nichoj
452# TODO should we be able to handle multiple calls to dosrc? -nichoj 614# TODO should we be able to handle multiple calls to dosrc? -nichoj
453# TODO maybe we can take an existing zip/jar? -nichoj 615# TODO maybe we can take an existing zip/jar? -nichoj
454# FIXME apparently this fails if you give it an empty directories 616# FIXME apparently this fails if you give it an empty directories
455java-pkg_dosrc() { 617java-pkg_dosrc() {
456 debug-print-function ${FUNCNAME} $* 618 debug-print-function ${FUNCNAME} $*
457 619
458 [ ${#} -lt 1 ] && die "At least one argument needed" 620 [ ${#} -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 621
463 java-pkg_check-phase install 622 java-pkg_check-phase install
464 623
465 [[ ${#} -lt 1 ]] && die "At least one argument needed" 624 [[ ${#} -lt 1 ]] && die "At least one argument needed"
625
626 if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
627 local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
628 if is-java-strict; then
629 eerror "${msg}"
630 die "${msg}"
631 else
632 echo "${msg}"
633 echo "Please report this to http://bugs.gentoo.org."
634 fi
635 fi
466 636
467 java-pkg_init_paths_ 637 java-pkg_init_paths_
468 638
469 local zip_name="${PN}-src.zip" 639 local zip_name="${PN}-src.zip"
470 local zip_path="${T}/${zip_name}" 640 local zip_path="${T}/${zip_name}"
471 local dir 641 local dir
472 for dir in ${@}; do 642 for dir in "${@}"; do
473 local dir_parent=$(dirname "${dir}") 643 local dir_parent=$(dirname "${dir}")
474 local dir_name=$(basename "${dir}") 644 local dir_name=$(basename "${dir}")
475 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 645 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
476 zip -q -r ${zip_path} ${dir_name} -i '*.java' 646 zip -q -r ${zip_path} ${dir_name} -i '*.java'
477 local result=$? 647 local result=$?
494# @ebuild-function java-pkg_dolauncher 664# @ebuild-function java-pkg_dolauncher
495# 665#
496# Make a wrapper script to lauch/start this package 666# Make a wrapper script to lauch/start this package
497# If necessary, the wrapper will switch to the appropriate VM. 667# If necessary, the wrapper will switch to the appropriate VM.
498# 668#
669# Can be called without parameters if the package installs only one jar
670# that has the Main-class attribute set. The wrapper will be named ${PN}.
671#
499# @param $1 - filename of launcher to create 672# @param $1 - filename of launcher to create
500# @param $2 - options, as follows: 673# @param $2 - options, as follows:
501# --main the.main.class.too.start 674# --main the.main.class.too.start
502# --jar /the/jar/too/launch.jar 675# --jar /the/jar/too/launch.jar or just <name>.jar
503# --java_args 'Extra arguments to pass too jave' 676# --java_args 'Extra arguments to pass to java'
504# --pkg_args 'extra arguments too pass too the package' 677# --pkg_args 'Extra arguments to pass to the package'
505# --pwd 678# --pwd Directory the launcher changes to before executing java
506# -into 679# -into Directory to install the launcher to, instead of /usr/bin
507# -pre 680# -pre Prepend contents of this file to the launcher
508# ------------------------------------------------------------------------------ 681# ------------------------------------------------------------------------------
509java-pkg_dolauncher() { 682java-pkg_dolauncher() {
510 debug-print-function ${FUNCNAME} $* 683 debug-print-function ${FUNCNAME} $*
511 684
512 java-pkg_check-phase install 685 java-pkg_check-phase install
513
514 [[ ${#} -lt 1 ]] && die "Need at least one argument"
515
516 java-pkg_init_paths_ 686 java-pkg_init_paths_
517 687
688 if [[ ${#} = 0 ]]; then
689 local name="${PN}"
690 else
518 local name="${1}" 691 local name="${1}"
692 shift
693 fi
694
519 # TODO rename to launcher 695 # TODO rename to launcher
520 local target="${T}/${name}" 696 local target="${T}/${name}"
697 local var_tmp="${T}/launcher_variables_tmp"
521 local target_dir pre 698 local target_dir pre
522 shift
523 699
524 echo "#!/bin/bash" > "${target}" 700 # Process the other the rest of the arguments
525 while [[ -n "${1}" && -n "${2}" ]]; do 701 while [[ -n "${1}" && -n "${2}" ]]; do
526 local var=${1} value=${2} 702 local var="${1}" value="${2}"
527 if [[ "${var:0:2}" == "--" ]]; then 703 if [[ "${var:0:2}" == "--" ]]; then
704 local var=${var:2}
528 echo "gjl_${var:2}=\"${value}\"" >> "${target}" 705 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
706 local gjl_${var}="${value}"
529 elif [[ "${var}" == "-into" ]]; then 707 elif [[ "${var}" == "-into" ]]; then
530 target_dir="${value}" 708 target_dir="${value}"
531 elif [[ "${var}" == "-pre" ]]; then 709 elif [[ "${var}" == "-pre" ]]; then
532 pre="${value}" 710 pre="${value}"
533 fi 711 fi
534 shift 2 712 shift 2
535 done 713 done
714
715 # Test if no --jar and --main arguments were given and
716 # in that case check if the package only installs one jar
717 # and use that jar.
718 if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
719 local cp="${JAVA_PKG_CLASSPATH}"
720 if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
721 echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
722 else
723 local msg="Not enough information to create a launcher given."
724 msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
725 die "${msg}"
726 fi
727 fi
728
729 # Write the actual script
730 echo "#!/bin/bash" > "${target}"
731 if [[ -n "${pre}" ]]; then
732 if [[ -f "${pre}" ]]; then
733 cat "${pre}" >> "${target}"
734 else
735 die "-pre specified file '${pre}' does not exist"
736 fi
737 fi
536 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 738 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
537 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 739 cat "${var_tmp}" >> "${target}"
740 rm -f "${var_tmp}"
538 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 741 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
539 742
540 if [[ -n "${into}" ]]; then 743 if [[ -n "${target_dir}" ]]; then
541 DESTTREE="${target_dir}" dobin "${target}" 744 DESTTREE="${target_dir}" dobin "${target}"
542 local ret=$? 745 local ret=$?
543 return ${ret} 746 return ${ret}
544 else 747 else
545 dobin "${target}" 748 dobin "${target}"
573 echo "dowar: warning, skipping directory ${war}" 776 echo "dowar: warning, skipping directory ${war}"
574 continue 777 continue
575 else 778 else
576 warpath="${war}" 779 warpath="${war}"
577 fi 780 fi
578 781
579 # Install those files like you mean it 782 # Install those files like you mean it
580 INSOPTIONS="-m 0644" \ 783 INSOPTIONS="-m 0644" \
581 INSDESTTREE=${JAVA_PKG_WARDEST} \ 784 INSDESTTREE=${JAVA_PKG_WARDEST} \
582 doins ${warpath} 785 doins ${warpath}
583 done 786 done
618# @ebuild-function java-pkg_jar-from 821# @ebuild-function java-pkg_jar-from
619# 822#
620# Makes a symlink to a jar from a certain package 823# Makes a symlink to a jar from a certain package
621# A lot of java packages include dependencies in a lib/ directory 824# A lot of java packages include dependencies in a lib/ directory
622# You can use this function to replace these bundled dependencies. 825# You can use this function to replace these bundled dependencies.
826# The dependency is recorded into package.env DEPEND line, unless "--build-only"
827# is passed as the very first argument, for jars that have to be present only
828# at build time and are not needed on runtime (junit testing etc).
623# 829#
624# Example: get all jars from xerces slot 2 830# Example: get all jars from xerces slot 2
625# java-pkg_jar-from xerces-2 831# java-pkg_jar-from xerces-2
626# Example: get a specific jar from xerces slot 2 832# Example: get a specific jar from xerces slot 2
627# java-pkg_jar-from xerces-2 xml-apis.jar 833# java-pkg_jar-from xerces-2 xml-apis.jar
628# Example get a specific jar from xerces slot 2, and name it diffrently 834# 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 835# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
836# Example: get junit.jar which is needed only for building
837# java-pkg_jar-from --build-only junit junit.jar
630# 838#
631# @param $1 - Package to get jars from. 839# @param $opt
840# --build-only - makes the jar(s) not added into package.env DEPEND line.
841# (assumed automatically when called inside src_test)
842# --with-dependencies - get jars also from requested package's dependencies
843# transitively.
844# --virtual - Packages passed to this function are to be handled as virtuals
845# and will not have individual jar dependencies recorded.
846# --into $dir - symlink jar(s) into $dir (must exist) instead of .
847# @param $1 - Package to get jars from, or comma-separated list of packages in
848# case other parameters are not used.
632# @param $2 - jar from package. If not specified, all jars will be used. 849# @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 850# @param $3 - When a single jar is specified, destination filename of the
634# symlink. Defaults to the name of the jar. 851# symlink. Defaults to the name of the jar.
635# ------------------------------------------------------------------------------ 852# ------------------------------------------------------------------------------
636# TODO could probably be cleaned up a little 853# TODO could probably be cleaned up a little
637java-pkg_jar-from() { 854java-pkg_jar-from() {
638 debug-print-function ${FUNCNAME} $* 855 debug-print-function ${FUNCNAME} $*
639 856
857 local build_only=""
858 local destdir="."
859 local deep=""
860 local virtual=""
861
862 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
863
864 while [[ "${1}" == --* ]]; do
865 if [[ "${1}" = "--build-only" ]]; then
866 build_only="build"
867 elif [[ "${1}" = "--with-dependencies" ]]; then
868 deep="--with-dependencies"
869 elif [[ "${1}" = "--virtual" ]]; then
870 virtual="true"
871 elif [[ "${1}" = "--into" ]]; then
872 destdir="${2}"
873 shift
874 else
875 die "java-pkg_jar-from called with unknown parameter: ${1}"
876 fi
877 shift
878 done
879
640 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 880 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
641 881
642 [[ -z ${target_pkg} ]] && die "Must specify a package" 882 [[ -z ${target_pkg} ]] && die "Must specify a package"
643 883
644 # default destjar to the target jar 884 # default destjar to the target jar
645 [[ -z "${destjar}" ]] && destjar="${target_jar}" 885 [[ -z "${destjar}" ]] && destjar="${target_jar}"
646 886
887 local error_msg="There was a problem getting the classpath for ${target_pkg}."
888 local classpath
647 local classpath="$(java-config --classpath=${target_pkg})" 889 classpath="$(java-config ${deep} --classpath=${target_pkg})"
648 [[ $? != 0 ]] && die "There was a problem getting the classpath for ${target_pkg}" 890 [[ $? != 0 ]] && die ${error_msg}
891
892 # When we have commas this functions is called to bring jars from multiple
893 # packages. This affects recording of dependencencies performed later
894 # which expects one package only, so we do it here.
895 if [[ ${target_pkg} = *,* ]]; then
896 for pkg in ${target_pkg//,/ }; do
897 java-pkg_ensure-dep "${build_only}" "${pkg}"
898 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
899 done
900 # setting this disables further record-jar_ calls later
901 build_only="build"
902 else
903 java-pkg_ensure-dep "${build_only}" "${target_pkg}"
904 fi
905
906 # Record the entire virtual as a dependency so that
907 # no jars are missed.
908 if [[ -z "${build_only}" && -n "${virtual}" ]]; then
909 java-pkg_record-jar_ "${target_pkg}"
910 # setting this disables further record-jars_ calls later
911 build_only="build"
912 fi
913
914 pushd ${destdir} > /dev/null \
915 || die "failed to change directory to ${destdir}"
649 916
650 local jar 917 local jar
651 for jar in ${classpath//:/ }; do 918 for jar in ${classpath//:/ }; do
652 local jar_name=$(basename "${jar}") 919 local jar_name=$(basename "${jar}")
653 if [[ ! -f "${jar}" ]] ; then 920 if [[ ! -f "${jar}" ]] ; then
657 # If no specific target jar was indicated, link it 924 # If no specific target jar was indicated, link it
658 if [[ -z "${target_jar}" ]] ; then 925 if [[ -z "${target_jar}" ]] ; then
659 [[ -f "${target_jar}" ]] && rm "${target_jar}" 926 [[ -f "${target_jar}" ]] && rm "${target_jar}"
660 ln -snf "${jar}" \ 927 ln -snf "${jar}" \
661 || die "Failed to make symlink from ${jar} to ${jar_name}" 928 || die "Failed to make symlink from ${jar} to ${jar_name}"
662 java-pkg_record-jar_ "${target_pkg}" "${jar}" 929 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
663 # otherwise, if the current jar is the target jar, link it 930 # otherwise, if the current jar is the target jar, link it
664 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 931 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
665 [[ -f "${destjar}" ]] && rm "${destjar}" 932 [[ -f "${destjar}" ]] && rm "${destjar}"
666 ln -snf "${jar}" "${destjar}" \ 933 ln -snf "${jar}" "${destjar}" \
667 || die "Failed to make symlink from ${jar} to ${destjar}" 934 || die "Failed to make symlink from ${jar} to ${destjar}"
668 java-pkg_record-jar_ "${target_pkg}" "${jar}" 935 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
936 popd > /dev/null
669 return 0 937 return 0
670 fi 938 fi
671 done 939 done
940 popd > /dev/null
672 # if no target was specified, we're ok 941 # if no target was specified, we're ok
673 if [[ -z "${target_jar}" ]] ; then 942 if [[ -z "${target_jar}" ]] ; then
674 return 0 943 return 0
675 # otherwise, die bitterly 944 # otherwise, die bitterly
676 else 945 else
690# ------------------------------------------------------------------------------ 959# ------------------------------------------------------------------------------
691# @ebuild-function java-pkg_getjars 960# @ebuild-function java-pkg_getjars
692# 961#
693# Get the classpath provided by any number of packages 962# Get the classpath provided by any number of packages
694# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'. 963# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
964# The providing packages are recorded as dependencies into package.env DEPEND
965# line, unless "--build-only" is passed as the very first argument, for jars
966# that have to be present only at build time and are not needed on runtime
967# (junit testing etc).
695# 968#
696# Example: Get the classpath for xerces-2, 969# Example: Get the classpath for xerces-2 and xalan,
697# java-pkg_getjars xerces-2 xalan 970# java-pkg_getjars xerces-2,xalan
698# Example Return: 971# Example Return:
699# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 972# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
700# 973#
974# @param $opt
975# --build-only - makes the jar(s) not added into package.env DEPEND line.
976# (assumed automatically when called inside src_test)
977# --with-dependencies - get jars also from requested package's dependencies
978# transitively.
701# @param $@ - list of packages to get jars from 979# @param $1 - list of packages to get jars from
980# (passed to java-config --classpath)
702# ------------------------------------------------------------------------------ 981# ------------------------------------------------------------------------------
703java-pkg_getjars() { 982java-pkg_getjars() {
704 debug-print-function ${FUNCNAME} $* 983 debug-print-function ${FUNCNAME} $*
705 984
706 [[ ${#} -lt 1 ]] && die "At least one argument needed" 985 local build_only=""
986 local deep=""
707 987
708 # NOTE could probably just pass $@ to java-config --classpath. and return it 988 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
709 local classpath pkg 989
710 for pkg in ${@//,/ }; do 990 while [[ "${1}" == --* ]]; do
711 #for pkg in $(echo "$@" | tr ',' ' '); do 991 if [[ "${1}" = "--build-only" ]]; then
712 jars="$(java-config --classpath=${pkg})" 992 build_only="build"
713 debug-print "${pkg}:${jars}" 993 elif [[ "${1}" = "--with-dependencies" ]]; then
714 # TODO should we ensure jars exist? 994 deep="--with-dependencies"
715 if [[ -z "${classpath}" ]]; then
716 classpath="${jars}"
717 else 995 else
718 classpath="${classpath}:${jars}" 996 die "java-pkg_jar-from called with unknown parameter: ${1}"
719 fi 997 fi
720 java-pkg_record-jar_ "${pkg}" 998 shift
721 done 999 done
1000
1001 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
1002
1003
1004 local classpath pkgs="${1}"
1005 jars="$(java-config ${deep} --classpath=${pkgs})"
1006 [[ $? != 0 || -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed"
1007 debug-print "${pkgs}:${jars}"
1008
1009 for pkg in ${pkgs//,/ }; do
1010 java-pkg_ensure-dep "${build_only}" "${pkg}"
1011 done
1012
1013 if [[ -z "${classpath}" ]]; then
1014 classpath="${jars}"
1015 else
1016 classpath="${classpath}:${jars}"
1017 fi
1018
1019 # Only record jars that aren't build-only
1020 if [[ -z "${build_only}" ]]; then
1021 for pkg in ${pkgs//,/ }; do
1022 java-pkg_record-jar_ "${pkg}"
1023 done
1024 fi
1025
722 echo "${classpath}" 1026 echo "${classpath}"
723} 1027}
724 1028
725# ------------------------------------------------------------------------------ 1029# ------------------------------------------------------------------------------
726# @ebuild-function java-pkg_getjar 1030# @ebuild-function java-pkg_getjar
727# 1031#
728# Get the filename of a single jar from a package 1032# Get the filename of a single jar from a package
1033# The providing package is recorded as runtime dependency into package.env
1034# DEPEND line, unless "--build-only" is passed as the very first argument, for
1035# jars that have to be present only at build time and are not needed on runtime
1036# (junit testing etc).
729# 1037#
730# @example 1038# @example
731# java-pkg_getjar xerces-2 xml-apis.jar 1039# java-pkg_getjar xerces-2 xml-apis.jar
732# @example-return 1040# @example-return
733# /usr/share/xerces-2/lib/xml-apis.jar 1041# /usr/share/xerces-2/lib/xml-apis.jar
734# 1042#
1043# @param $opt
1044# --build-only - makes the jar not added into package.env DEPEND line.
1045# --virtual - Packages passed to this function are to be handled as virtuals
1046# and will not have individual jar dependencies recorded.
735# @param $1 - package to use 1047# @param $1 - package to use
736# @param $2 - jar to get 1048# @param $2 - jar to get
737# ------------------------------------------------------------------------------ 1049# ------------------------------------------------------------------------------
738java-pkg_getjar() { 1050java-pkg_getjar() {
739 debug-print-function ${FUNCNAME} $* 1051 debug-print-function ${FUNCNAME} $*
1052
1053 local build_only=""
1054 local virtual=""
1055
1056 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1057
1058 while [[ "${1}" == --* ]]; do
1059 if [[ "${1}" = "--build-only" ]]; then
1060 build_only="build"
1061 elif [[ "${1}" == --* ]]; then
1062 virtual="true"
1063 else
1064 die "java-pkg_jar-from called with unknown parameter: ${1}"
1065 fi
1066 shift
1067 done
1068
1069 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
740 1070
741 local pkg="${1}" target_jar="${2}" jar 1071 local pkg="${1}" target_jar="${2}" jar
742 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 1072 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
743 [[ -z ${target_jar} ]] && die "Must specify jar to get" 1073 [[ -z ${target_jar} ]] && die "Must specify jar to get"
744 1074
745 # TODO check that package is actually installed 1075 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
1076 local classpath
746 local classpath=$(java-config --classpath=${pkg}) 1077 classpath=$(java-config --classpath=${pkg})
747 [[ $? != 0 ]] && die "There could not find classpath for ${pkg}. Are you sure its installed?" 1078 [[ $? != 0 ]] && die ${error_msg}
1079
1080 java-pkg_ensure-dep "${build_only}" "${pkg}"
1081
1082 # Record the package(Virtual) as a dependency and then set build_only
1083 # So that individual jars are not recorded.
1084 if [[ -n "${virtual}" ]]; then
1085 java-pkg_record-jar_ "${pkg}"
1086 build_only="true"
1087 fi
1088
748 for jar in ${classpath//:/ }; do 1089 for jar in ${classpath//:/ }; do
749 if [[ ! -f "${jar}" ]] ; then 1090 if [[ ! -f "${jar}" ]] ; then
750 die "Installation problems with jars in ${pkg} - is it installed?" 1091 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
751 fi 1092 fi
752 1093
753 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then 1094 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
754 java-pkg_record-jar_ "${pkg}" "${jar}" 1095 # Only record jars that aren't build-only
1096 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" "${jar}"
755 echo "${jar}" 1097 echo "${jar}"
756 return 0 1098 return 0
757 fi 1099 fi
758 done 1100 done
759 1101
760 die "Could not find ${target_jar} in ${pkg}" 1102 die "Could not find ${target_jar} in ${pkg}"
761 return 1 1103 return 1
1104}
1105
1106# ------------------------------------------------------------------------------
1107# @ebuild-function java-pkg_register-dependency
1108#
1109# Registers runtime dependency on a package, list of packages, or a single jar
1110# from a package, into package.env DEPEND line. Can only be called in
1111# src_install phase.
1112# Intended for binary packages where you don't need to symlink the jars or get
1113# their classpath during build. As such, the dependencies only need to be
1114# specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1115#
1116# @param $1 - comma-separated list of packages, or a single package
1117# @param $2 - if param $1 is a single package, optionally specify the jar
1118# to depend on
1119#
1120# Example: Record the dependency on whole xerces-2 and xalan,
1121# java-pkg_register-dependency xerces-2,xalan
1122# Example: Record the dependency on ant.jar from ant-core
1123# java-pkg_register-dependency ant-core ant.jar
1124#
1125# Note: Passing both list of packages as the first parameter AND specifying the
1126# jar as the second is not allowed and will cause the function to die. We assume
1127# that there's more chance one passes such combination as a mistake, than that
1128# there are more packages providing identically named jar without class
1129# collisions.
1130# ------------------------------------------------------------------------------
1131java-pkg_register-dependency() {
1132 debug-print-function ${FUNCNAME} $*
1133
1134 java-pkg_check-phase install
1135
1136 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1137
1138 local pkgs="${1}"
1139 local jar="${2}"
1140
1141 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1142
1143 if [[ -z "${jar}" ]]; then
1144 for pkg in ${pkgs//,/ }; do
1145 java-pkg_ensure-dep runtime "${pkg}"
1146 java-pkg_record-jar_ "${pkg}"
1147 done
1148 else
1149 [[ ${pkgs} == *,* ]] && \
1150 die "${FUNCNAME} called with both package list and jar name"
1151 java-pkg_ensure-dep runtime "${pkgs}"
1152 java-pkg_record-jar_ "${pkgs}" "${jar}"
1153 fi
1154
1155 java-pkg_do_write_
1156}
1157
1158# ------------------------------------------------------------------------------
1159# @ebuild-function java-pkg_register-optional-dependency
1160#
1161# Registers optional runtime dependency on a package, list of packages, or a
1162# single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be
1163# called in src_install phase.
1164# Intended for packages that can use other packages when those are in classpath.
1165# Will be put on classpath by launcher if they are installed. Typical case is
1166# JDBC implementations for various databases. It's better than having USE flag
1167# for each implementation triggering hard dependency.
1168#
1169# @param $1 - comma-separated list of packages, or a single package
1170# @param $2 - if param $1 is a single package, optionally specify the jar
1171# to depend on
1172#
1173# Example: Record the optional dependency on some jdbc providers
1174# java-pkg_register-optional-dependency jdbc-jaybird,jtds-1.2,jdbc-mysql
1175#
1176# Note: Passing both list of packages as the first parameter AND specifying the
1177# jar as the second is not allowed and will cause the function to die. We assume
1178# that there's more chance one passes such combination as a mistake, than that
1179# there are more packages providing identically named jar without class
1180# collisions.
1181# ------------------------------------------------------------------------------
1182java-pkg_register-optional-dependency() {
1183 debug-print-function ${FUNCNAME} $*
1184
1185 java-pkg_check-phase install
1186
1187 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1188
1189 local pkgs="${1}"
1190 local jar="${2}"
1191
1192 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1193
1194 if [[ -z "${jar}" ]]; then
1195 for pkg in ${pkgs//,/ }; do
1196 java-pkg_record-jar_ --optional "${pkg}"
1197 done
1198 else
1199 [[ ${pkgs} == *,* ]] && \
1200 die "${FUNCNAME} called with both package list and jar name"
1201 java-pkg_record-jar_ --optional "${pkgs}" "${jar}"
1202 fi
1203
1204 java-pkg_do_write_
1205}
1206
1207# ------------------------------------------------------------------------------
1208# @ebuild-function java-pkg_register-environment-variable
1209#
1210# Register an arbitrary environment variable into package.env. The gjl launcher
1211# for this package or any package depending on this will export it into
1212# environement before executing java command.
1213# Must only be called in src_install phase.
1214#
1215# @param $1 - variable name
1216# @param $2 - variable value
1217# ------------------------------------------------------------------------------
1218JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
1219JAVA_PKG_EXTRA_ENV_VARS=""
1220java-pkg_register-environment-variable() {
1221 debug-print-function ${FUNCNAME} $*
1222
1223 java-pkg_check-phase install
1224
1225 [[ ${#} != 2 ]] && die "${FUNCNAME} takes two arguments"
1226
1227 echo "${1}=\"${2}\"" >> ${JAVA_PKG_EXTRA_ENV}
1228 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
1229
1230 java-pkg_do_write_
762} 1231}
763 1232
764# This function reads stdin, and based on that input, figures out how to 1233# This function reads stdin, and based on that input, figures out how to
765# populate jars from the filesystem. 1234# populate jars from the filesystem.
766# Need to figure out a good way of making use of this, ie be able to use a 1235# Need to figure out a good way of making use of this, ie be able to use a
778# line="${line// /}" 1247# line="${line// /}"
779# 1248#
780# # format: path=jarinfo 1249# # format: path=jarinfo
781# local path=${line%%=*} 1250# local path=${line%%=*}
782# local jarinfo=${line##*=} 1251# local jarinfo=${line##*=}
783# 1252#
784# # format: jar@package 1253# # format: jar@package
785# local jar=${jarinfo%%@*}.jar 1254# local jar=${jarinfo%%@*}.jar
786# local package=${jarinfo##*@} 1255# local package=${jarinfo##*@}
787# if [[ -n ${replace_only} ]]; then 1256# if [[ -n ${replace_only} ]]; then
788# [[ ! -f $path ]] && die "No jar exists at ${path}" 1257# [[ ! -f $path ]] && die "No jar exists at ${path}"
801# @section-end query 1270# @section-end query
802# ------------------------------------------------------------------------------ 1271# ------------------------------------------------------------------------------
803 1272
804# ------------------------------------------------------------------------------ 1273# ------------------------------------------------------------------------------
805# @section-begin helper 1274# @section-begin helper
806# @section-summary Helper functions 1275# @section-summary Helper functions
807# 1276#
808# Various other functions to use from an ebuild 1277# Various other functions to use from an ebuild
809# ------------------------------------------------------------------------------ 1278# ------------------------------------------------------------------------------
810 1279
811# ------------------------------------------------------------------------------ 1280# ------------------------------------------------------------------------------
817# jdbc-stdext 1286# jdbc-stdext
818# jaf 1287# jaf
819# jdbc-rowset 1288# jdbc-rowset
820# jms 1289# jms
821# 1290#
822# @param $1 - Optionally indicate that the dependencies are controlled by 1291# @param $1 - Optionally indicate that the dependencies are controlled by
823# a use flag by specifying '--use' Requires $2. 1292# a use flag by specifying '--use' Requires $2.
824# @param $2 - USE flag which will enable the dependencies. 1293# @param $2 - USE flag which will enable the dependencies.
825# @param $@ - virtual packages to add depenedencies for 1294# @param $@ - virtual packages to add depenedencies for
826# ------------------------------------------------------------------------------ 1295# ------------------------------------------------------------------------------
827# TODO rewrite to parse a line based declaration file instead -- karltk 1296# TODO rewrite to parse a line based declaration file instead -- karltk
883# 1352#
884# export DEPEND="${DEPEND} ${depstr}" 1353# export DEPEND="${DEPEND} ${depstr}"
885# export RDEPEND="${RDEPEND} ${depstr}" 1354# export RDEPEND="${RDEPEND} ${depstr}"
886#} 1355#}
887 1356
1357# ------------------------------------------------------------------------------
1358# @ebuild-function java-pkg_find-normal-jars
1359#
1360# Find the files with suffix .jar file in the given directory or $WORKDIR
1361#
1362# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1363# ------------------------------------------------------------------------------
1364java-pkg_find-normal-jars() {
1365 local dir=$1
1366 [[ "${dir}" ]] || dir="${WORKDIR}"
1367 local found
1368 for jar in $(find "${dir}" -name "*.jar" -type f); do
1369 echo "${jar}"
1370 found="true"
1371 done
1372 [[ "${found}" ]]
1373 return $?
1374}
1375
1376# ------------------------------------------------------------------------------
1377# @ebuild-function java-pkg_ensure-no-bundled-jars
1378#
1379# 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 1380# This function should be called after WORKDIR has been populated with symlink
889# TODO document 1381# to system jar files or bundled jars removed.
1382# ------------------------------------------------------------------------------
890java-pkg_ensure-no-bundled-jars() { 1383java-pkg_ensure-no-bundled-jars() {
891 debug-print-function ${FUNCNAME} $* 1384 debug-print-function ${FUNCNAME} $*
892 pushd ${WORKDIR} >/dev/null 2>/dev/null
893 1385
894 local bundled_jars=$(find . -name "*.jar" -type f) 1386 local bundled_jars=$(java-pkg_find-normal-jars)
895 if [[ -n ${bundled_jars} ]]; then 1387 if [[ -n ${bundled_jars} ]]; then
896 echo "Bundled jars found:" 1388 echo "Bundled jars found:"
897 local jar 1389 local jar
898 for jar in ${bundled_jars}; do 1390 for jar in ${bundled_jars}; do
899 echo $(pwd)${jar/./} 1391 echo $(pwd)${jar/./}
900 done 1392 done
901 die "Bundled jars found!" 1393 die "Bundled jars found!"
902
903 fi 1394 fi
904 popd >/dev/null 2>/dev/null
905} 1395}
906 1396
907# ------------------------------------------------------------------------------ 1397# ------------------------------------------------------------------------------
908# @internal-function java-pkg_ensure-vm-version-sufficient 1398# @internal-function java-pkg_ensure-vm-version-sufficient
909# 1399#
921 fi 1411 fi
922} 1412}
923 1413
924# ------------------------------------------------------------------------------ 1414# ------------------------------------------------------------------------------
925# @internal-function java-pkg_is-vm-version-sufficient 1415# @internal-function java-pkg_is-vm-version-sufficient
926# 1416#
927# @return zero - VM is sufficient 1417# @return zero - VM is sufficient
928# @return non-zero - VM is not sufficient 1418# @return non-zero - VM is not sufficient
929# ------------------------------------------------------------------------------ 1419# ------------------------------------------------------------------------------
930java-pkg_is-vm-version-sufficient() { 1420java-pkg_is-vm-version-sufficient() {
931 debug-print-function ${FUNCNAME} $* 1421 debug-print-function ${FUNCNAME} $*
951 die "Active Java VM too old" 1441 die "Active Java VM too old"
952 fi 1442 fi
953} 1443}
954 1444
955# ------------------------------------------------------------------------------ 1445# ------------------------------------------------------------------------------
956# @internal-function java-pkg_is-vm-version-eq 1446# @internal-function java-pkg_is-vm-version-eq
957# 1447#
958# @param $@ - VM version to compare current VM to 1448# @param $@ - VM version to compare current VM to
959# @return zero - VM versions are equal 1449# @return zero - VM versions are equal
960# @return non-zero - VM version are not equal 1450# @return non-zero - VM version are not equal
961# ------------------------------------------------------------------------------ 1451# ------------------------------------------------------------------------------
962java-pkg_is-vm-version-eq() { 1452java-pkg_is-vm-version-eq() {
992# 1482#
993# @param $@ - VM version to compare current to 1483# @param $@ - VM version to compare current to
994# ------------------------------------------------------------------------------ 1484# ------------------------------------------------------------------------------
995java-pkg_ensure-vm-version-ge() { 1485java-pkg_ensure-vm-version-ge() {
996 debug-print-function ${FUNCNAME} $* 1486 debug-print-function ${FUNCNAME} $*
997 1487
998 if ! java-pkg_is-vm-version-ge "$@" ; then 1488 if ! java-pkg_is-vm-version-ge "$@" ; then
999 debug-print "vm is not suffient" 1489 debug-print "vm is not suffient"
1000 eerror "This package requires a Java VM version >= $@" 1490 eerror "This package requires a Java VM version >= $@"
1001 einfo "Please use java-config -S to set the correct one" 1491 einfo "Please use java-config -S to set the correct one"
1002 die "Active Java VM too old" 1492 die "Active Java VM too old"
1003 fi 1493 fi
1004} 1494}
1005 1495
1006# ------------------------------------------------------------------------------ 1496# ------------------------------------------------------------------------------
1007# @internal-function java-pkg_is-vm-version-ge 1497# @internal-function java-pkg_is-vm-version-ge
1008# 1498#
1009# @param $@ - VM version to compare current VM to 1499# @param $@ - VM version to compare current VM to
1010# @return zero - current VM version is greater than checked version 1500# @return zero - current VM version is greater than checked version
1011# @return non-zero - current VM version is not greater than checked version 1501# @return non-zero - current VM version is not greater than checked version
1012# ------------------------------------------------------------------------------ 1502# ------------------------------------------------------------------------------
1013java-pkg_is-vm-version-ge() { 1503java-pkg_is-vm-version-ge() {
1027 return 1 1517 return 1
1028 fi 1518 fi
1029 fi 1519 fi
1030} 1520}
1031 1521
1522java-pkg_set-current-vm() {
1523 export GENTOO_VM=${1}
1524}
1525
1526java-pkg_get-current-vm() {
1527 echo ${GENTOO_VM}
1528}
1529
1530java-pkg_current-vm-matches() {
1531 hasq $(java-pkg_get-current-vm) ${@}
1532 return $?
1533}
1534
1032# ------------------------------------------------------------------------------ 1535# ------------------------------------------------------------------------------
1033# @ebuild-function java-pkg_get-source 1536# @ebuild-function java-pkg_get-source
1034# 1537#
1035# Determines what source version should be used, for passing to -source. 1538# 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 1539# Unless you want to break things you probably shouldn't set _WANT_SOURCE
1037# 1540#
1038# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE 1541# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1039# ------------------------------------------------------------------------------ 1542# ------------------------------------------------------------------------------
1044# ------------------------------------------------------------------------------ 1547# ------------------------------------------------------------------------------
1045# @ebuild-function java-pkg_get-target 1548# @ebuild-function java-pkg_get-target
1046# 1549#
1047# Determines what target version should be used, for passing to -target. 1550# 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 1551# If you don't care about lower versions, you can set _WANT_TARGET to the
1049# version of your JDK. 1552# 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# 1553#
1054# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1554# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1055# ------------------------------------------------------------------------------ 1555# ------------------------------------------------------------------------------
1056java-pkg_get-target() { 1556java-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}")} 1557 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1070} 1558}
1071 1559
1072java-pkg_get-javac() { 1560java-pkg_get-javac() {
1073 debug-print-function ${FUNCNAME} $* 1561 debug-print-function ${FUNCNAME} $*
1074 1562
1075 java-pkg_init-compiler_ 1563
1076 local compiler="${GENTOO_COMPILER}" 1564 local compiler="${GENTOO_COMPILER}"
1077 1565
1078 local compiler_executable 1566 local compiler_executable
1079 if [[ "${compiler}" = "javac" ]]; then 1567 if [[ "${compiler}" = "javac" ]]; then
1080 # nothing fancy needs to be done for javac 1568 # nothing fancy needs to be done for javac
1088 unset JAVAC 1576 unset JAVAC
1089 # try to get value of JAVAC 1577 # try to get value of JAVAC
1090 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1578 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1091 export JAVAC=${old_javac} 1579 export JAVAC=${old_javac}
1092 1580
1093 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1581 if [[ -z ${compiler_executable} ]]; then
1094 1582 echo "JAVAC is empty or undefined in ${compiler_env}"
1583 return 1
1584 fi
1585
1095 # check that it's executable 1586 # check that it's executable
1096 if [[ ! -x ${compiler_executable} ]]; then 1587 if [[ ! -x ${compiler_executable} ]]; then
1097 eerror "Could not find ${compiler_executable}!"
1098 die "${compiler_executable} doesn't exist, or isn't executable" 1588 echo "${compiler_executable} doesn't exist, or isn't executable"
1589 return 1
1099 fi 1590 fi
1100 else 1591 else
1101 eerror "Could not find environment file for ${compiler}" 1592 echo "Could not find environment file for ${compiler}"
1102 die "Could not find ${compiler_env}" 1593 return 1
1103 fi 1594 fi
1104 fi 1595 fi
1105 echo ${compiler_executable} 1596 echo ${compiler_executable}
1106} 1597}
1107 1598
1108# ------------------------------------------------------------------------------ 1599# ------------------------------------------------------------------------------
1109# @ebuild-function java-pkg_javac-args 1600# @ebuild-function java-pkg_javac-args
1110# 1601#
1111# If an ebuild uses javac directly, instead of using ejavac, it should call this 1602# If an ebuild uses javac directly, instead of using ejavac, it should call this
1112# to know what -source/-target to use. 1603# to know what -source/-target to use.
1113# 1604#
1114# @return string - arguments to pass to javac, complete with -target and -source 1605# @return string - arguments to pass to javac, complete with -target and -source
1117 debug-print-function ${FUNCNAME} $* 1608 debug-print-function ${FUNCNAME} $*
1118 1609
1119 local want_source="$(java-pkg_get-source)" 1610 local want_source="$(java-pkg_get-source)"
1120 local want_target="$(java-pkg_get-target)" 1611 local want_target="$(java-pkg_get-target)"
1121 1612
1122 local source_str="-source ${want_source}" 1613 local source_str="-source ${want_source}"
1123 local target_str="-target ${want_target}" 1614 local target_str="-target ${want_target}"
1124 1615
1125 debug-print "want source: ${want_source}" 1616 debug-print "want source: ${want_source}"
1126 debug-print "want target: ${want_target}" 1617 debug-print "want target: ${want_target}"
1127 1618
1128 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1619 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1129 debug-print "could not find valid -source/-target values" 1620 debug-print "could not find valid -source/-target values for javac"
1130 die "Could not find valid -source/-target values" 1621 echo "Could not find valid -source/-target values for javac"
1622 return 1
1131 else 1623 else
1132 if java-pkg_is-vm-version-ge "1.4"; then 1624 if java-pkg_is-vm-version-ge "1.4"; then
1133 echo "${source_str} ${target_str}" 1625 echo "${source_str} ${target_str}"
1134 else 1626 else
1135 echo "${target_str}" 1627 echo "${target_str}"
1139 1631
1140# TODO document 1632# TODO document
1141java-pkg_get-jni-cflags() { 1633java-pkg_get-jni-cflags() {
1142 local flags="-I${JAVA_HOME}/include" 1634 local flags="-I${JAVA_HOME}/include"
1143 1635
1144 # TODO figure out how to cope with other things than linux... 1636 local platform="linux"
1637 use elibc_FreeBSD && platform="freebsd"
1638
1639 # TODO do a check that the directories are valid
1145 flags="${flags} -I${JAVA_HOME}/include/linux" 1640 flags="${flags} -I${JAVA_HOME}/include/${platform}"
1146 1641
1147 echo ${flags} 1642 echo ${flags}
1643}
1644
1645java-pkg_ensure-gcj() {
1646 if ! built_with_use sys-devel/gcc gcj ; then
1647 ewarn
1648 ewarn "You must build gcc with the gcj support to build with gcj"
1649 ewarn
1650 ebeep 5
1651 die "No GCJ support found!"
1652 fi
1653}
1654
1655java-pkg_ensure-test() {
1656 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \
1657 && hasq test ${IUSE} && ! use test;
1658 then
1659 eerror "You specified FEATURES=test, but USE=test is needed"
1660 eerror "to pull in the additional dependencies for testing"
1661 die "Need USE=test enabled"
1662 fi
1663}
1664
1665# ------------------------------------------------------------------------------
1666# @ebuild-function java-pkg_register-ant-task
1667#
1668# Register this package as ant task, so that ant will load it when no specific
1669# ANT_TASKS are specified. Note that even without this registering, all packages
1670# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1671# packages, but can be also used by other ebuilds that used to symlink their
1672# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1673# compatibility.
1674#
1675# @param --version x.y Register only for ant version x.y (otherwise for any ant
1676# version). Used by the ant-* packages to prevent loading of mismatched
1677# ant-core ant tasks after core was updated, before the tasks are updated,
1678# without a need for blockers.
1679# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1680# ------------------------------------------------------------------------------
1681java-pkg_register-ant-task() {
1682 local TASKS_DIR="tasks"
1683
1684 # check for --version x.y parameters
1685 while [[ -n "${1}" && -n "${2}" ]]; do
1686 local var="${1#--}"
1687 local val="${2}"
1688 if [[ "${var}" == "version" ]]; then
1689 TASKS_DIR="tasks-${val}"
1690 else
1691 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1692 fi
1693 shift 2
1694 done
1695
1696 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1697
1698 dodir /usr/share/ant/${TASKS_DIR}
1699 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1700}
1701
1702# ------------------------------------------------------------------------------
1703# @internal-function java-pkg_ant-tasks-from-deps
1704#
1705# Function to determine ANT_TASKS from DEPEND variable for backwards
1706# compatibility with ebuilds that don't set ANT_TASKS before calling eant() or
1707# WANT_ANT_TASKS before inheriting java-pkg-2. If the DEPEND string contains
1708# "dev-java/ant" or "dev-java/ant-tasks", then it returns "all", otherwise
1709# "none". It's not smart enough to cope with USE flag depends but that shouldn't
1710# be a problem, the worst it can do is activace all tasks when not needed.
1711# Note that this is called only with JAVA_PKG_STRICT=1, to find ebuilds with
1712# insufficient dependencies, otherwise all available tasks are used for
1713# backwards compatilbility.
1714#
1715# @return "all" or "none"
1716# ------------------------------------------------------------------------------
1717java-pkg_ant-tasks-from-deps() {
1718 local found_ant found_ant_tasks
1719
1720 for dep in ${DEPEND}
1721 do
1722 local ant="$(awk '/(dev-java\/ant)/ { if (match($1, "(dev-java/ant)((-[0-9])+|$)", m)) print m[1] }' <<< ${dep})"
1723 [[ "${ant}" == "dev-java/ant" ]] && found_ant=true
1724 [[ "${dep}" == *"ant-tasks"* ]] && found_ant_tasks=true
1725 done
1726
1727 if [[ -n "${found_ant}" || -n "${found_ant_tasks}" ]]; then
1728 java-pkg_announce-qa-violation --nodie "The ebuild DEPENDS on deprecated ant or ant-tasks"
1729 echo "all"
1730 else
1731 # ebuild doesn't set ANT_TASKS and doesn't depend on ant-tasks or ant
1732 # so we deactivate all tasks that may be installed
1733 echo "none"
1734 fi
1735}
1736
1737# ------------------------------------------------------------------------------
1738# @internal-function java-pkg_ant-tasks-depend
1739#
1740# Translates the WANT_ANT_TASKS variable into valid dependencies.
1741# ------------------------------------------------------------------------------
1742java-pkg_ant-tasks-depend() {
1743 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1744
1745 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1746 local DEP=""
1747 for i in ${WANT_ANT_TASKS}
1748 do
1749 if [[ ${i} != ant-* ]]; then
1750 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1751 return 1
1752 fi
1753 DEP="${DEP}dev-java/${i} "
1754 done
1755 echo ${DEP}
1756 return 0
1757 else
1758 return 0
1759 fi
1760}
1761
1762# ------------------------------------------------------------------------------
1763# @ebuild-function ejunit
1764#
1765# Junit wrapper function. Makes it easier to run the tests and checks for
1766# dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner.
1767#
1768# Examples:
1769# ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1770# ejunit org.blinkenlights.jid3.test.AllTests
1771#
1772# @param $1 - -cp or -classpath
1773# @param $2 - classpath; junit and recorded dependencies get appended
1774# @param $@ - the rest of the parameters are passed to java
1775# ------------------------------------------------------------------------------
1776ejunit() {
1777 debug-print-function ${FUNCNAME} $*
1778
1779 local pkgs
1780 for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
1781 pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
1782 done
1783
1784 local cp=$(java-pkg_getjars --with-dependencies junit${pkgs})
1785 if [[ ${1} = -cp || ${1} = -classpath ]]; then
1786 cp="${2}:${cp}"
1787 shift 2
1788 else
1789 cp=".:${cp}"
1790 fi
1791
1792 local runner=junit.textui.TestRunner
1793 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}"
1794 java -cp "${cp}" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
1148} 1795}
1149 1796
1150# ------------------------------------------------------------------------------ 1797# ------------------------------------------------------------------------------
1151# @section-end helper 1798# @section-end helper
1152# ------------------------------------------------------------------------------ 1799# ------------------------------------------------------------------------------
1161 1808
1162# ------------------------------------------------------------------------------ 1809# ------------------------------------------------------------------------------
1163# @ebuild-function eant 1810# @ebuild-function eant
1164# 1811#
1165# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1812# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1166# compiler. 1813# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1167# 1814# variables:
1815# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1816# gentoo.classpath property. Be sure to call
1817# java-ant_rewrite-classpath in src_unpack.
1818# JAVA_PKG_NO_BUNDLED_SEARCH - Don't search for bundled jars or class files
1819# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1168# ------------------------------------------------------------------------------ 1820# ------------------------------------------------------------------------------
1169eant() { 1821eant() {
1170 debug-print-function ${FUNCNAME} $* 1822 debug-print-function ${FUNCNAME} $*
1171 1823
1172 local antflags 1824 if [[ ${EBUILD_PHASE} = compile ]]; then
1825 # Used to be done in hooks in java-ant-2.eclass but moved here so that we can
1826 # finally get rid of the hooks without breaking stuff
1827
1828 [[ "${JAVA_ANT_IGNORE_SYSTEM_CLASSES}" && "${JAVA_PKG_BSFIX}" ]] \
1829 && java-ant_ignore-system-classes "${S}/build.xml"
1830
1831 if hasq java-ant-2 ${INHERITED}; then
1832 java-ant_bsfix
1833 fi
1834
1835 # eant can be called multiple times
1836 JAVA_PKG_BSFIX="off"
1837
1838 if [[ -z ${JAVA_PKG_NO_BUNDLED_SEARCH} ]] && is-java-strict; then
1839 echo "Searching for bundled jars:"
1840 java-pkg_find-normal-jars || echo "None found."
1841 echo "Searching for bundled classes (no output if none found):"
1842 find "${WORKDIR}" -name "*.class"
1843 echo "Search done."
1844 JAVA_PKG_NO_BUNDLED_SEARCH=true # eant can be called many times
1845 fi
1846 fi
1847
1848 if ! hasq java-ant-2 ${INHERITED}; then
1849 local msg="You should inherit java-ant-2 when using eant"
1850 java-pkg_announce-qa-violation "${msg}"
1851 fi
1852
1853 local antflags="-Dnoget=true -Dmaven.mode.offline=true -Dbuild.sysclasspath=ignore"
1854
1173 java-pkg_init-compiler_ 1855 java-pkg_init-compiler_
1174 local compiler="${GENTOO_COMPILER}" 1856 local compiler="${GENTOO_COMPILER}"
1175 1857
1176 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1858 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})" 1859 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})"
1179 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1860 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1180 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1861 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1181 fi 1862 fi
1182 1863
1183 if [[ ${compiler} != "javac" ]]; then 1864 if [[ ${compiler} != "javac" ]]; then
1184 antflags="-Dbuild.compiler=${build_compiler}" 1865 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1185 # Figure out any extra stuff to put on the classpath for compilers aside 1866 # Figure out any extra stuff to put on the classpath for compilers aside
1186 # from javac 1867 # from javac
1187 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to 1868 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1188 # java-config -p 1869 # java-config -p
1189 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1870 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 1871 if [[ -n ${build_compiler_deps} ]]; then
1191 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})" 1872 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1192 fi 1873 fi
1193 fi 1874 fi
1194 1875
1195 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1876 for arg in "${@}"; do
1196 antflags="${antflags} -debug" 1877 if [[ ${arg} = -lib ]]; then
1878 if is-java-strict; then
1879 eerror "You should not use the -lib argument to eant because it will fail"
1880 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1881 eerror "or ant properties to make dependencies available."
1882 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1883 eerror "split ant (>=dev-java/ant-core-1.7)."
1884 die "eant -lib is deprecated/forbidden"
1885 else
1886 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1887 echo "more info."
1888 fi
1197 fi 1889 fi
1198 1890 done
1891
1892 # we use this in src_* so we run ant from /
1893 if ROOT=/ has_version ">=dev-java/ant-core-1.7.0"; then
1894 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1895 ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}"
1896
1897 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1898 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1899
1900 if is-java-strict; then
1901 # if ant-tasks were not set by ebuild or forced, try to determine them from depends
1902 if [[ -z "${ANT_TASKS}" ]]; then
1903 ANT_TASKS="$(java-pkg_ant-tasks-from-deps)"
1904 fi
1905 else
1906 # if ant-tasks is not set by ebuild or forced, activate all of them
1907 ANT_TASKS="${ANT_TASKS:-all}"
1908 fi
1909
1910 # at this point, ANT_TASKS should be "all", "none" or explicit list
1911 if [[ "${ANT_TASKS}" == "all" ]]; then
1912 einfo "Using all available ANT_TASKS"
1913 elif [[ "${ANT_TASKS}" == "none" ]]; then
1914 einfo "Disabling all optional ANT_TASKS"
1915 else
1916 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1917 fi
1918
1919 export ANT_TASKS
1920 fi
1921
1922 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1923 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1924
1925 local gcp="${EANT_GENTOO_CLASSPATH}"
1926 local getjarsarg=""
1927
1928 if [[ ${EBUILD_PHASE} = "test" ]]; then
1929 antflags="${antflags} -DJunit.present=true"
1930 [[ ${gcp} && ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1931 getjarsarg="--with-dependencies"
1932 fi
1933
1934 local cp
1935
1936 for atom in ${gcp}; do
1937 cp="${cp}:$(java-pkg_getjars ${getjarsarg} ${atom})"
1938 done
1939
1940 if [[ ${cp} ]]; then
1941 # It seems ant does not like single quotes around ${cp}
1942 antflags="${antflags} -Dgentoo.classpath=\"${cp#:}\""
1943 fi
1944
1199 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1945 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1946 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
1200 ant ${antflags} "${@}" || die "eant failed" 1947 ant ${antflags} "${@}" || die "eant failed"
1201
1202} 1948}
1203 1949
1204# ------------------------------------------------------------------------------ 1950# ------------------------------------------------------------------------------
1205# @ebuild-function ejavac 1951# @ebuild-function ejavac
1206# 1952#
1207# Javac wrapper function. Will use the appropriate compiler, based on 1953# Javac wrapper function. Will use the appropriate compiler, based on
1208# /etc/java-config/compilers.conf 1954# /etc/java-config/compilers.conf
1209# 1955#
1210# @param $@ - Arguments to be passed to the compiler 1956# @param $@ - Arguments to be passed to the compiler
1211# ------------------------------------------------------------------------------ 1957# ------------------------------------------------------------------------------
1212ejavac() { 1958ejavac() {
1213 debug-print-function ${FUNCNAME} $* 1959 debug-print-function ${FUNCNAME} $*
1214 1960
1961 java-pkg_init-compiler_
1962
1963 local compiler_executable
1215 local compiler_executable=$(java-pkg_get-javac) 1964 compiler_executable=$(java-pkg_get-javac)
1965 if [[ ${?} != 0 ]]; then
1966 eerror "There was a problem determining compiler: ${compiler_executable}"
1967 die "get-javac failed"
1968 fi
1216 1969
1970 local javac_args
1971 javac_args="$(java-pkg_javac-args)"
1972 if [[ ${?} != 0 ]]; then
1973 eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
1974 die "java-pkg_javac-args failed"
1975 fi
1976
1217 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 1977 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1218 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 1978 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1219} 1979}
1220 1980
1221# ------------------------------------------------------------------------------ 1981# ------------------------------------------------------------------------------
1222# @ebuild-function java-pkg_filter-compiler 1982# @ebuild-function java-pkg_filter-compiler
1223# 1983#
1224# Used to prevent the use of some compilers. Should be used in src_compile. 1984# Used to prevent the use of some compilers. Should be used in src_compile.
1225# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER 1985# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
1226# 1986#
1227# @param $@ - compilers to filter 1987# @param $@ - compilers to filter
1228# ------------------------------------------------------------------------------ 1988# ------------------------------------------------------------------------------
1229java-pkg_filter-compiler() { 1989java-pkg_filter-compiler() {
1230 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@" 1990 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@"
1231} 1991}
1232 1992
1233# ------------------------------------------------------------------------------ 1993# ------------------------------------------------------------------------------
1994# @ebuild-function java-pkg_force-compiler
1995#
1996# Used to force the use of particular compilers. Should be used in src_compile.
1997# A common use of this would be to force ecj-3.1 to be used on amd64, to avoid
1998# OutOfMemoryErrors that may come up.
1999#
2000# @param $@ - compilers to force
2001# ------------------------------------------------------------------------------
2002java-pkg_force-compiler() {
2003 JAVA_PKG_FORCE_COMPILER="$@"
2004}
2005
2006# ------------------------------------------------------------------------------
1234# @ebuild-function use_doc 2007# @ebuild-function use_doc
1235# 2008#
1236# Helper function for getting ant to build javadocs. If the user has USE=doc, 2009# 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. 2010# then 'javadoc' or the argument are returned. Otherwise, there is no return.
1238# 2011#
1239# The output of this should be passed to ant. 2012# The output of this should be passed to ant.
1240# 2013#
1241# Example: build javadocs by calling 'javadoc' target 2014# Example: build javadocs by calling 'javadoc' target
1242# eant $(use_doc) 2015# eant $(use_doc)
1243# Example: build javadocs by calling 'apidoc' target 2016# Example: build javadocs by calling 'apidoc' target
1248# ------------------------------------------------------------------------------ 2021# ------------------------------------------------------------------------------
1249use_doc() { 2022use_doc() {
1250 use doc && echo ${@:-javadoc} 2023 use doc && echo ${@:-javadoc}
1251} 2024}
1252 2025
2026
1253# ------------------------------------------------------------------------------ 2027# ------------------------------------------------------------------------------
1254# @section-end build 2028# @section-end build
1255# ------------------------------------------------------------------------------ 2029# ------------------------------------------------------------------------------
1256 2030
1257# ------------------------------------------------------------------------------ 2031# ------------------------------------------------------------------------------
1258# @section-begin internal 2032# @section-begin internal
1259# @section-summary Internal functions 2033# @section-summary Internal functions
1260# 2034#
1261# Do __NOT__ use any of these from an ebuild! These are only to be used from 2035# Do __NOT__ use any of these from an ebuild! These are only to be used from
1262# within the java eclasses. 2036# within the java eclasses.
1263# ------------------------------------------------------------------------------ 2037# ------------------------------------------------------------------------------
1264 2038
1265# ----------------------------------------------------------------------------- 2039# -----------------------------------------------------------------------------
1266# @function-internal java-pkg_init 2040# @function-internal java-pkg_init
1267# 2041#
1268# The purpose of this function, as the name might imply, is to initialize the 2042# 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 2043# 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 2044# that'll muss things up. It initializes some variables, which are used
1271# internally. And most importantly, it'll switch the VM if necessary. 2045# internally. And most importantly, it'll switch the VM if necessary.
1272# 2046#
1273# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will 2047# 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. 2048# call it during each of the phases of the merge process.
1275# 2049#
1276# ----------------------------------------------------------------------------- 2050# -----------------------------------------------------------------------------
1277java-pkg_init() { 2051java-pkg_init() {
2052 debug-print-function ${FUNCNAME} $*
1278 unset JAVAC 2053 unset JAVAC
1279 unset JAVA_HOME 2054 unset JAVA_HOME
2055
2056 # People do all kinds of weird things.
2057 # http://forums.gentoo.org/viewtopic-p-3943166.html
2058 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
2059 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
2060 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
2061 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
2062 ewarn "sun-jdk vms and and as such break configure scripts that"
2063 ewarn "use it (for example app-office/openoffice) so we filter it out."
2064 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
2065 ewarn "make.conf for example) to silence this warning or"
2066 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
2067 fi
2068
2069 if [[ -z ${accept} ]]; then
2070 # export _JAVA_OPTIONS= doesn't work because it will show up in java
2071 # -version output
2072 unset _JAVA_OPTIONS
2073 # phase hooks make this run many times without this
2074 I_WANT_GLOBAL_JAVA_OPTIONS="true"
2075 fi
2076
2077 if java-pkg_func-exists ant_src_unpack; then
2078 java-pkg_announce-qa-violation "Using old ant_src_unpack. Should be src_unpack"
2079 fi
2080
1280 java-pkg_init_paths_ 2081 java-pkg_init_paths_
1281 java-pkg_switch-vm 2082 java-pkg_switch-vm
1282 PATH=${JAVA_HOME}/bin:${PATH} 2083 PATH=${JAVA_HOME}/bin:${PATH}
1283 2084
1284 # TODO we will probably want to set JAVAC and JAVACFLAGS 2085 # TODO we will probably want to set JAVAC and JAVACFLAGS
1285 2086
1286 # Do some QA checks 2087 # Do some QA checks
1287 java-pkg_check-jikes 2088 java-pkg_check-jikes
1288 2089
2090 # Can't use unset here because Portage does not save the unset
2091 # see https://bugs.gentoo.org/show_bug.cgi?id=189417#c11
2092
1289 # When users have crazy classpaths some packages can fail to compile. 2093 # When users have crazy classpaths some packages can fail to compile.
1290 # and everything should work with empty CLASSPATH. 2094 # and everything should work with empty CLASSPATH.
1291 # This also helps prevent unexpected dependencies on random things 2095 # This also helps prevent unexpected dependencies on random things
1292 # from the CLASSPATH. 2096 # from the CLASSPATH.
1293 unset CLASSPATH 2097 export CLASSPATH=
2098
2099 # Unset external ANT_ stuff
2100 export ANT_TASKS=
2101 export ANT_OPTS=
1294} 2102}
1295 2103
1296# ------------------------------------------------------------------------------ 2104# ------------------------------------------------------------------------------
1297# @function-internal java-pkg-init-compiler_ 2105# @function-internal java-pkg-init-compiler_
1298# 2106#
1299# This function attempts to figure out what compiler should be used. It does 2107# 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 2108# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
1301# COMPILERS variable defined there. 2109# COMPILERS variable defined there.
1302# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER 2110# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
1303# 2111#
1304# It will go through the list of compilers, and verify that it supports the 2112# 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 2113# 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 2114# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
1307# isn't done. 2115# isn't done.
1308# 2116#
1330 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 2138 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1331 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})" 2139 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
1332 else 2140 else
1333 compilers=${JAVA_PKG_FORCE_COMPILER} 2141 compilers=${JAVA_PKG_FORCE_COMPILER}
1334 fi 2142 fi
1335 2143
1336 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}" 2144 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
1337 2145
1338 # Figure out if we should announce what compiler we're using 2146 # Figure out if we should announce what compiler we're using
1339 local compiler 2147 local compiler
1340 for compiler in ${compilers}; do 2148 for compiler in ${compilers}; do
1343 if [[ ${compiler} = "javac" ]]; then 2151 if [[ ${compiler} = "javac" ]]; then
1344 debug-print "Found javac... breaking" 2152 debug-print "Found javac... breaking"
1345 export GENTOO_COMPILER="javac" 2153 export GENTOO_COMPILER="javac"
1346 break 2154 break
1347 fi 2155 fi
1348 2156
1349 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then 2157 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
1350 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 2158 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1351 einfo "Filtering ${compiler}" 2159 einfo "Filtering ${compiler}"
1352 continue 2160 continue
1353 fi 2161 fi
1354 fi 2162 fi
1355 2163
1356 # for non-javac, we need to make sure it supports the right target and 2164 # for non-javac, we need to make sure it supports the right target and
1357 # source 2165 # source
1358 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 2166 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1359 if [[ -f ${compiler_env} ]]; then 2167 if [[ -f ${compiler_env} ]]; then
1360 local desired_target="$(java-pkg_get-target)" 2168 local desired_target="$(java-pkg_get-target)"
1420 fi 2228 fi
1421 2229
1422 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}" 2230 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}"
1423 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/" 2231 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/"
1424 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env" 2232 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env"
2233 JAVA_PKG_VIRTUALS_PATH="${DESTTREE}/share/java-config-2/virtuals"
2234 JAVA_PKG_VIRTUAL_PROVIDER="${D}/${JAVA_PKG_VIRTUALS_PATH}/${JAVA_PKG_NAME}"
1425 2235
1426 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib" 2236 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib"
1427 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}" 2237 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}"
1428 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps" 2238 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps"
1429 2239
1442# Writes the package.env out to disk. 2252# Writes the package.env out to disk.
1443# 2253#
1444# ------------------------------------------------------------------------------ 2254# ------------------------------------------------------------------------------
1445# TODO change to do-write, to match everything else 2255# TODO change to do-write, to match everything else
1446java-pkg_do_write_() { 2256java-pkg_do_write_() {
2257 debug-print-function ${FUNCNAME} $*
2258 java-pkg_init_paths_
1447 # Create directory for package.env 2259 # Create directory for package.env
1448 dodir "${JAVA_PKG_SHAREPATH}" 2260 dodir "${JAVA_PKG_SHAREPATH}"
1449 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 2261 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f \
2262 "${JAVA_PKG_DEPEND_FILE}" || -f \
2263 "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]]; then
1450 # Create package.env 2264 # Create package.env
1451 ( 2265 (
1452 echo "DESCRIPTION=\"${DESCRIPTION}\"" 2266 echo "DESCRIPTION=\"${DESCRIPTION}\""
1453 echo "GENERATION=\"2\"" 2267 echo "GENERATION=\"2\""
1454 2268
1455 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\"" 2269 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
1456 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 2270 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1457 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 2271 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1458 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 2272 [[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
2273 && echo "DEPEND=\"$(cat "${JAVA_PKG_DEPEND_FILE}" | uniq | tr '\n' ':')\""
2274 [[ -f "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]] \
2275 && echo "OPTIONAL_DEPEND=\"$(cat "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" | uniq | tr '\n' ':')\""
1459 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 2276 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1460 ) > "${JAVA_PKG_ENV}" 2277 ) > "${JAVA_PKG_ENV}"
1461 2278
1462 # register target/source 2279 # register target/source
1463 local target="$(java-pkg_get-target)" 2280 local target="$(java-pkg_get-target)"
1464 local source="$(java-pkg_get-source)" 2281 local source="$(java-pkg_get-source)"
1465 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}" 2282 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
1466 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}" 2283 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
1474 2291
1475 2292
1476 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}" 2293 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
1477 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}" 2294 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
1478 2295
2296 # extra env variables
2297 if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
2298 cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}" || die
2299 # nested echo to remove leading/trailing spaces
2300 echo "ENV_VARS=\"$(echo ${JAVA_PKG_EXTRA_ENV_VARS})\"" \
2301 >> "${JAVA_PKG_ENV}" || die
2302 fi
2303
1479 # Strip unnecessary leading and trailing colons 2304 # Strip unnecessary leading and trailing colons
1480 # TODO try to cleanup if possible 2305 # TODO try to cleanup if possible
1481 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 2306 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
2307 else
2308 debug-print "JAVA_PKG_CLASSPATH, JAVA_PKG_LIBRARY, JAVA_PKG_DEPEND_FILE"
2309 debug-print "or JAVA_PKG_OPTIONAL_DEPEND_FILE not defined so can't"
2310 debug-print "write package.env."
1482 fi 2311 fi
1483} 2312}
1484
1485 2313
1486# ------------------------------------------------------------------------------ 2314# ------------------------------------------------------------------------------
1487# @internal-function java-pkg_record-jar_ 2315# @internal-function java-pkg_record-jar_
1488# 2316#
1489# Record a dependency to the package.env 2317# Record an (optional) dependency to the package.env
1490# 2318# @param --optional - record dependency as optional
2319# @param $1 - package to record
2320# @param $2 - (optional) jar of package to record
1491# ------------------------------------------------------------------------------ 2321# ------------------------------------------------------------------------------
1492JAVA_PKG_DEPEND="${T}/java-pkg-depend" 2322JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2323JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
1493 2324
1494java-pkg_record-jar_() { 2325java-pkg_record-jar_() {
1495 debug-print-function ${FUNCNAME} $* 2326 debug-print-function ${FUNCNAME} $*
2327
2328 local depend_file="${JAVA_PKG_DEPEND_FILE}"
2329 if [[ "${1}" == "--optional" ]]; then
2330 depend_file="${JAVA_PKG_OPTIONAL_DEPEND_FILE}"
2331 shift
2332 fi
1496 2333
1497 local pkg=${1} jar=${2} append 2334 local pkg=${1} jar=${2} append
1498 if [[ -z "${jar}" ]]; then 2335 if [[ -z "${jar}" ]]; then
1499 append="${pkg}" 2336 append="${pkg}"
1500 else 2337 else
1501 append="$(basename ${jar})@${pkg}" 2338 append="$(basename ${jar})@${pkg}"
1502 fi 2339 fi
1503 2340
1504 echo ${append} >> ${JAVA_PKG_DEPEND} 2341 echo "${append}" >> "${depend_file}"
1505} 2342}
1506 2343
1507# ------------------------------------------------------------------------------ 2344# ------------------------------------------------------------------------------
1508# @internal-function java-pkg_append_ 2345# @internal-function java-pkg_append_
1509# 2346#
1533 fi 2370 fi
1534} 2371}
1535 2372
1536# ------------------------------------------------------------------------------ 2373# ------------------------------------------------------------------------------
1537# @internal-function java-pkg_expand_dir_ 2374# @internal-function java-pkg_expand_dir_
1538# 2375#
1539# Gets the full path of the file/directory's parent. 2376# Gets the full path of the file/directory's parent.
1540# @param $1 - file/directory to find parent directory for 2377# @param $1 - file/directory to find parent directory for
1541# @return - path to $1's parent directory 2378# @return - path to $1's parent directory
1542# ------------------------------------------------------------------------------ 2379# ------------------------------------------------------------------------------
1543java-pkg_expand_dir_() { 2380java-pkg_expand_dir_() {
1569# 2406#
1570# ------------------------------------------------------------------------------ 2407# ------------------------------------------------------------------------------
1571java-pkg_setup-vm() { 2408java-pkg_setup-vm() {
1572 debug-print-function ${FUNCNAME} $* 2409 debug-print-function ${FUNCNAME} $*
1573 2410
2411 export LANG="C" LC_ALL="C"
2412
1574 local vendor="$(java-pkg_get-vm-vendor)" 2413 local vendor="$(java-pkg_get-vm-vendor)"
1575 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge 1 5; then 2414 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1576 addpredict "/dev/random" 2415 addpredict "/dev/random"
1577 elif [[ "${vendor}" == "ibm" ]]; then 2416 elif [[ "${vendor}" == "ibm" ]]; then
1578 addpredict "/proc/self/maps" 2417 addpredict "/proc/self/maps"
1579 addpredict "/proc/cpuinfo" 2418 addpredict "/proc/cpuinfo"
1580 export LANG="C" LC_ALL="C"
1581 elif [[ "${vendor}" == "jrockit" ]]; then 2419 elif [[ "${vendor}" == "jrockit" ]]; then
1582 addpredict "/proc/cpuinfo" 2420 addpredict "/proc/cpuinfo"
1583 fi 2421 fi
1584} 2422}
1585 2423
1629# @return - The version of the current VM 2467# @return - The version of the current VM
1630# ------------------------------------------------------------------------------ 2468# ------------------------------------------------------------------------------
1631java-pkg_get-vm-version() { 2469java-pkg_get-vm-version() {
1632 debug-print-function ${FUNCNAME} $* 2470 debug-print-function ${FUNCNAME} $*
1633 2471
1634 java-pkg_get-current-vm | sed -e "s/.*-\([0-9.]\+\).*/\1/" 2472 java-config -g PROVIDES_VERSION
1635} 2473}
1636 2474
1637# ------------------------------------------------------------------------------ 2475# ------------------------------------------------------------------------------
1638# @internal-function java-pkg_switch-vm 2476# @internal-function java-pkg_switch-vm
1639# 2477#
1640# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 2478# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1641# verify that the current VM is sufficient. 2479# verify that the current VM is sufficient.
1642# Setup the environment for the VM being used. 2480# Setup the environment for the VM being used.
1643# ------------------------------------------------------------------------------ 2481# ------------------------------------------------------------------------------
1644java-pkg_switch-vm() { 2482java-pkg_switch-vm() {
2483 debug-print-function ${FUNCNAME} $*
2484
1645 if java-pkg_needs-vm; then 2485 if java-pkg_needs-vm; then
1646 # Use the VM specified by JAVA_PKG_FORCE_VM 2486 # Use the VM specified by JAVA_PKG_FORCE_VM
1647 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then 2487 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1648 # If you're forcing the VM, I hope you know what your doing... 2488 # If you're forcing the VM, I hope you know what your doing...
2489 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1649 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 2490 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1650 # if we're allowed to switch the vm... 2491 # if we're allowed to switch the vm...
1651 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 2492 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1652 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}" 2493 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1653 if [[ -n ${JAVA_PKG_VNEED} ]]; then 2494 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1654 export GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2495 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1655 else 2496 else
1656 export GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2497 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
2498 fi
2499 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
2500 eerror "Unable to determine VM for building from dependencies:"
2501 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
2502 echo "VNEED: ${JAVA_PKG_VNEED}"
2503 die "Failed to determine VM for building."
2504 else
2505 export GENTOO_VM
1657 fi 2506 fi
1658 # otherwise just make sure the current VM is sufficient 2507 # otherwise just make sure the current VM is sufficient
1659 else 2508 else
1660 java-pkg_ensure-vm-version-sufficient 2509 java-pkg_ensure-vm-version-sufficient
1661 fi 2510 fi
1662 debug-print "Using: $(java-config -f)" 2511 debug-print "Using: $(java-config -f)"
1663 2512
1664 java-pkg_setup-vm 2513 java-pkg_setup-vm
1665 2514
1666 export JAVA=$(java-config -java) 2515 export JAVA=$(java-config --java)
1667 export JAVAC=$(java-config -javac) 2516 export JAVAC=$(java-config --javac)
1668 export JAVACFLAGS="$(java-pkg_javac-args)" 2517 JAVACFLAGS="$(java-pkg_javac-args)"
2518 if [[ ${?} != 0 ]]; then
2519 eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
2520 die "java-pkg_javac-args failed"
2521 fi
1669 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 2522 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
2523 export JAVACFLAGS
1670 2524
1671 export JAVA_HOME="$(java-config -g JAVA_HOME)" 2525 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1672 export JDK_HOME=${JAVA_HOME} 2526 export JDK_HOME=${JAVA_HOME}
1673 2527
1674 #TODO If you know a better solution let us know. 2528 #TODO If you know a better solution let us know.
1675 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 2529 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1676 2530
1677 local tann="${T}/announced-vm" 2531 local tann="${T}/announced-vm"
2532 # With the hooks we should only get here once from pkg_setup but better safe than sorry
2533 # if people have for example modified eclasses some where
1678 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 2534 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1679 # Add a check for setup/preinst phase... to avoid duplicate outputs
1680 # for when FEATURES=buildpkg
1681 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1682 then
1683 einfo "Using: $(java-config -f)" 2535 einfo "Using: $(java-config -f)"
1684 [[ ! -f "${tann}" ]] && touch "${tann}" 2536 [[ ! -f "${tann}" ]] && touch "${tann}"
1685 fi
1686 fi 2537 fi
1687 2538
1688 else 2539 else
1689 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!" 2540 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!"
1690 fi 2541 fi
1706 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2 2557 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2
1707 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2 2558 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2
1708 echo "and of course, the output of emerge --info" >&2 2559 echo "and of course, the output of emerge --info" >&2
1709} 2560}
1710 2561
2562
2563# TODO document
2564# List jars in the source directory, ${S}
2565java-pkg_jar-list() {
2566 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
2567 einfo "Linked Jars"
2568 find "${S}" -type l -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2569 einfo "Jars"
2570 find "${S}" -type f -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2571 einfo "Classes"
2572 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2573 fi
2574}
2575
2576# ------------------------------------------------------------------------------
2577# @internal-function java-pkg_verify-classes
2578#
2579# Verify that the classes were compiled for the right source / target. Dies if
2580# not.
2581# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2582# ------------------------------------------------------------------------------
2583java-pkg_verify-classes() {
2584 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
2585 local target=$(java-pkg_get-target)
2586 local result
2587 local log="${T}/class-version-verify.log"
2588 if [[ -n "${1}" ]]; then
2589 class-version-verify.py -v -t ${target} "${1}" > "${log}"
2590 result=$?
2591 else
2592 ebegin "Verifying java class versions (target: ${target})"
2593 class-version-verify.py -v -t ${target} -r "${D}" > "${log}"
2594 result=$?
2595 eend ${result}
2596 fi
2597 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2598 if [[ ${result} != 0 ]]; then
2599 eerror "Incorrect bytecode version found"
2600 [[ -n "${1}" ]] && eerror "in file: ${1}"
2601 eerror "See ${log} for more details."
2602 die "Incorrect bytecode found"
2603 fi
2604}
2605
2606# ----------------------------------------------------------------------------
2607# @internal-function java-pkg_ensure-dep
2608# Check that a package being used in jarfrom, getjars and getjar is contained
2609# within DEPEND or RDEPEND.
2610# @param $1 - empty - check both vars; "runtime" or "build" - check only
2611# RDEPEND, resp. DEPEND
2612# @param $2 - Package name and slot.
2613
2614java-pkg_ensure-dep() {
2615 debug-print-function ${FUNCNAME} $*
2616
2617 local limit_to="${1}"
2618 local target_pkg="${2}"
2619 local dev_error=""
2620
2621 local stripped_pkg=$(echo "${target_pkg}" | sed \
2622 's/-[0-9]*\(\.[0-9]\)*$//')
2623
2624 debug-print "Matching against: ${stripped_pkg}"
2625
2626 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2627 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2628 dev_error="${dev_error} declared in DEPEND."
2629 if is-java-strict; then
2630 eerror "${dev_error}"
2631 die "${dev_error}"
2632 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2633 eerror "${dev_error}"
2634 elog "Because you have this package installed the package will"
2635 elog "build without problems, but please report this to"
2636 elog "http://bugs.gentoo.org"
2637 fi
2638 fi
2639
2640 if [[ ${limit_to} != build ]]; then
2641 if [[ ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2642 if [[ ! ( ${PDEPEND} =~ "${stripped_pkg}" ) ]]; then
2643 dev_error="The ebuild is attempting to use ${target_pkg},"
2644 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND"
2645 dev_error="${dev_error} or PDEPEND."
2646 if is-java-strict; then
2647 eerror "${dev_error}"
2648 die "${dev_error}"
2649 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2650 eerror "${dev_error}"
2651 elog "The package will build without problems, but may fail to run"
2652 elog "if you don't have ${target_pkg} installed, so please report"
2653 elog "this to http://bugs.gentoo.org"
2654 fi
2655 fi
2656 fi
2657 fi
2658}
2659
1711# ------------------------------------------------------------------------------ 2660# ------------------------------------------------------------------------------
1712# @section-end internal 2661# @section-end internal
1713# ------------------------------------------------------------------------------ 2662# ------------------------------------------------------------------------------
1714 2663
1715java-pkg_check-phase() { 2664java-pkg_check-phase() {
1716 local phase=${1} 2665 local phase=${1}
1717 local funcname=${2} 2666 local funcname=${FUNCNAME[1]}
1718 # TODO add check for java-stricter
1719 if [[ ${EBUILD_PHASE} != ${phase} ]]; then 2667 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
1720 java-pkg_announce-qa-violation \
1721 "${funcname} used outside of src_${phase}" 2668 local msg="${funcname} used outside of src_${phase}"
2669 java-pkg_announce-qa-violation "${msg}"
1722 fi 2670 fi
1723} 2671}
1724 2672
1725java-pkg_check-versioned-jar() { 2673java-pkg_check-versioned-jar() {
1726 local jar=${1} 2674 local jar=${1}
1735 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2683 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1736 fi 2684 fi
1737} 2685}
1738 2686
1739java-pkg_announce-qa-violation() { 2687java-pkg_announce-qa-violation() {
1740 if hasq java-strict ${FEATURES}; then 2688 local nodie
2689 if [[ ${1} == "--nodie" ]]; then
2690 nodie="true"
2691 shift
2692 fi
1741 echo "Java QA Notice: $@" >&2 2693 echo "Java QA Notice: $@" >&2
1742 increment-qa-violations 2694 increment-qa-violations
1743 fi 2695 [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
1744} 2696}
1745 2697
1746increment-qa-violations() { 2698increment-qa-violations() {
1747 let "JAVA_PKG_QA_VIOLATIONS+=1" 2699 let "JAVA_PKG_QA_VIOLATIONS+=1"
1748 export JAVA_PKG_QA_VIOLATIONS 2700 export JAVA_PKG_QA_VIOLATIONS
1749} 2701}
1750 2702
2703is-java-strict() {
2704 [[ -n ${JAVA_PKG_STRICT} ]]
2705 return $?
2706}
2707
1751# ------------------------------------------------------------------------------ 2708# ------------------------------------------------------------------------------
1752# @eclass-end 2709# @eclass-end
1753# ------------------------------------------------------------------------------ 2710# ------------------------------------------------------------------------------

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

  ViewVC Help
Powered by ViewVC 1.1.20