/[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.128
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.128 2009/06/02 07:02:01 ali_bush 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. For EAPI 2 we have new enough stuff so let's have cleaner deps.
65# -----------------------------------------------------------------------------
66hasq "${EAPI}" 0 1 && JAVA_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.1.6 ${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
196 done 291 done
197 292
198 java-pkg_do_write_ 293 java-pkg_do_write_
199} 294}
200 295
296# ------------------------------------------------------------------------------
297# @internal-function depend-java-query
298#
299# Wrapper for the depend-java-query binary to enable passing USE in env.
300# Using env variables keeps this eclass working with java-config versions that
301# do not handle use flags.
302# ------------------------------------------------------------------------------
201 303
304depend-java-query() {
305 # Used to have a which call here but it caused endless loops for some people
306 # that had some weird bashrc voodoo for which.
307 USE="${USE}" /usr/bin/depend-java-query "${@}"
308}
202 309
203# ------------------------------------------------------------------------------ 310# ------------------------------------------------------------------------------
204# @ebuild-function java-pkg_regjar 311# @ebuild-function java-pkg_regjar
205# 312#
206# Records an already installed jar in the package.env 313# 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 314# This would mostly be used if the package has make or a custom script to
208# install things. 315# install things.
209# 316#
210# Example: 317# Example:
211# java-pkg-regjar ${D}/opt/foo/lib/foo.jar 318# java-pkg_regjar ${D}/opt/foo/lib/foo.jar
319#
320# WARNING:
321# if you want to use shell expansion, you have to use ${D}/... as the for in
322# this function will not be able to expand the path, here's an example:
323#
324# java-pkg_regjar /opt/my-java/lib/*.jar
325#
326# will not work, because:
327# * the `for jar in "$@"` can't expand the path to jar file names, as they
328# don't exist yet
329# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar'
330# doesn't exist
331#
332# you have to use it as:
333#
334# java-pkg_regjar ${D}/opt/my-java/lib/*.jar
212# 335#
213# @param $@ - jars to record 336# @param $@ - jars to record
214# ------------------------------------------------------------------------------ 337# ------------------------------------------------------------------------------
215# TODO fix me! 338# TODO should we be making sure the jar is present on ${D} or wherever?
216java-pkg_regjar() { 339java-pkg_regjar() {
217 debug-print-function ${FUNCNAME} $* 340 debug-print-function ${FUNCNAME} $*
218 341
219 java-pkg_check-phase install 342 java-pkg_check-phase install
220 343
221 [[ ${#} -lt 1 ]] && die "at least one argument needed" 344 [[ ${#} -lt 1 ]] && die "at least one argument needed"
222 345
223 java-pkg_init_paths_ 346 java-pkg_init_paths_
224 347
225 local jar jar_dir jar_file 348 local jar jar_dir jar_file
226 for jar in "$@"; do 349 for jar in "${@}"; do
227 # TODO use java-pkg_check-versioned-jar 350 # 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 351 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
352 [[ -d "${jar}" || -d "${D}${jar}" ]] \
353 && die "Called ${FUNCNAME} on a directory $*"
354
355 #check that class version correct when in strict mode
356 is-java-strict && java-pkg_verify-classes "${jar}"
357
358 # nelchael: we should strip ${D} in this case too, here's why:
359 # imagine such call:
360 # java-pkg_regjar ${D}/opt/java/*.jar
361 # such call will fall into this case (-e ${jar}) and will
362 # record paths with ${D} in package.env
231 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 363 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
232 else 364 else
365 if [[ ${jar} = *\** ]]; then
366 eerror "The argument ${jar} to ${FUNCNAME}"
367 eerror "has * in it. If you want it to glob in"
368 eerror '${D} add ${D} to the argument.'
369 fi
370 debug-print "${jar} or ${D}${jar} not found"
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:
294# @param $@ - JNI libraries to install 430# @param $@ - JNI libraries to install
295# ------------------------------------------------------------------------------ 431# ------------------------------------------------------------------------------
296java-pkg_doso() { 432java-pkg_doso() {
297 debug-print-function ${FUNCNAME} $* 433 debug-print-function ${FUNCNAME} $*
298 434
299 [[ ${#} -lt 1 ]] && "At least one argument required for ${FUNCNAME}"
300 java-pkg_check-phase install 435 java-pkg_check-phase install
301 436
302 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 437 [[ ${#} -lt 1 ]] && die "${FUNCNAME} requires at least one argument"
303 438
304 java-pkg_init_paths_ 439 java-pkg_init_paths_
305 440
306 local lib 441 local lib
307 # for each lib 442 # for each lib
310 if [[ -e "${lib}" ]] ; then 445 if [[ -e "${lib}" ]] ; then
311 # install if it isn't a symlink 446 # install if it isn't a symlink
312 if [[ ! -L "${lib}" ]] ; then 447 if [[ ! -L "${lib}" ]] ; then
313 INSDESTTREE="${JAVA_PKG_LIBDEST}" \ 448 INSDESTTREE="${JAVA_PKG_LIBDEST}" \
314 INSOPTIONS="${LIBOPTIONS}" \ 449 INSOPTIONS="${LIBOPTIONS}" \
315 doins "${lib}" || "failed to install ${lib}" 450 doins "${lib}" || die "failed to install ${lib}"
316 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 451 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
317 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 452 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
318 # otherwise make a symlink to the symlink's origin 453 # otherwise make a symlink to the symlink's origin
319 else 454 else
320 # TODO use dosym
321 ln -s "$(readlink "${lib}")" "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")" 455 dosym "$(readlink "${lib}")" "${JAVA_PKG_LIBDEST}/${lib##*/}"
322 debug-print "${lib} is a symlink, linking accordanly" 456 debug-print "${lib} is a symlink, linking accordantly"
323 fi 457 fi
324 # otherwise die 458 # otherwise die
325 else 459 else
326 die "${lib} does not exist" 460 die "${lib} does not exist"
327 fi 461 fi
343java-pkg_regso() { 477java-pkg_regso() {
344 debug-print-function ${FUNCNAME} $* 478 debug-print-function ${FUNCNAME} $*
345 479
346 java-pkg_check-phase install 480 java-pkg_check-phase install
347 481
348 [[ ${#} -lt 1 ]] && "at least one argument needed" 482 [[ ${#} -lt 1 ]] && die "${FUNCNAME} requires at least one argument"
349 483
350 java-pkg_init_paths_ 484 java-pkg_init_paths_
351 485
352 local lib target_dir 486 local lib target_dir
353 for lib in "$@" ; do 487 for lib in "$@" ; do
354 # Check the absolute path of the lib 488 # Check the absolute path of the lib
355 if [[ -e "${lib}" ]] ; then 489 if [[ -e "${lib}" ]] ; then
356 target_dir="$(java-pkg_expand_dir_ ${lib})" 490 target_dir="$(java-pkg_expand_dir_ ${lib})"
404# ------------------------------------------------------------------------------ 538# ------------------------------------------------------------------------------
405java-pkg_dohtml() { 539java-pkg_dohtml() {
406 debug-print-function ${FUNCNAME} $* 540 debug-print-function ${FUNCNAME} $*
407 541
408 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 542 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
409 # TODO-nichoj find out what exactly -f package-list does 543
544 # from /usr/lib/portage/bin/dohtml -h
545 # -f Set list of allowed extensionless file names.
410 dohtml -f package-list "$@" 546 dohtml -f package-list "$@"
547
411 # this probably shouldn't be here but it provides 548 # this probably shouldn't be here but it provides
412 # a reasonable way to catch # docs for all of the 549 # a reasonable way to catch # docs for all of the
413 # old ebuilds. 550 # old ebuilds.
414 java-pkg_recordjavadoc 551 java-pkg_recordjavadoc
415} 552}
416 553
417# TODO document 554# ------------------------------------------------------------------------------
555# @ebuild-function java-pkg_dojavadoc
556#
557# Installs javadoc documentation. This should be controlled by the doc use flag.
558#
559# @param $1: optional --symlink creates to symlink like this for html
560# documentation bundles.
561# @param $2: - The javadoc root directory.
562#
563# @example:
564# java-pkg_dojavadoc docs/api
565# java-pkg_dojavadoc --symlink apidocs docs/api
566#
567# ------------------------------------------------------------------------------
418java-pkg_dojavadoc() { 568java-pkg_dojavadoc() {
569 debug-print-function ${FUNCNAME} $*
570
571 # For html documentation bundles that link to Javadoc
572 local symlink
573 if [[ ${1} = --symlink ]]; then
574 symlink=${2}
575 shift 2
576 fi
577
419 local dir="$1" 578 local dir="$1"
579 local dest=/usr/share/doc/${PF}/html
580
581 # QA checks
420 582
421 java-pkg_check-phase install 583 java-pkg_check-phase install
422 584
423 [[ -z "${dir}" ]] && die "Must specify a directory!" 585 [[ -z "${dir}" ]] && die "Must specify a directory!"
424 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!" 586 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!"
587 if [[ ! -e "${dir}/index.html" ]]; then
588 local msg="No index.html in javadoc directory"
589 ewarn "${msg}"
590 is-java-strict && die "${msg}"
591 fi
592
593 if [[ -e ${D}/${dest}/api ]]; then
594 eerror "${dest} already exists. Will not overwrite."
595 die "${dest}"
596 fi
597
598 # Renaming to match our directory layout
425 599
426 local dir_to_install="${dir}" 600 local dir_to_install="${dir}"
427 if [[ "$(basename "${dir}")" != "api" ]]; then 601 if [[ "$(basename "${dir}")" != "api" ]]; then
428 dir_to_install="${T}/api" 602 dir_to_install="${T}/api"
429 # TODO use doins 603 # TODO use doins
430 cp -r "${dir}" "${dir_to_install}" || die "cp failed" 604 cp -r "${dir}" "${dir_to_install}" || die "cp failed"
431 fi 605 fi
432 606
607 # Actual installation
608
433 java-pkg_dohtml -r ${dir_to_install} 609 java-pkg_dohtml -r "${dir_to_install}"
610
611 # Let's make a symlink to the directory we have everything else under
612 dosym ${dest}/api "${JAVA_PKG_SHAREPATH}/api" || die
613
614 if [[ ${symlink} ]]; then
615 debug-print "symlinking ${dest}/{api,${symlink}}"
616 dosym ${dest}/{api,${symlink}} || die
617 fi
434} 618}
435 619
436# ------------------------------------------------------------------------------ 620# ------------------------------------------------------------------------------
437# @ebuild-function java-pkg_dosrc 621# @ebuild-function java-pkg_dosrc
438# 622#
439# Installs a zip containing the source for a package, so it can used in 623# Installs a zip containing the source for a package, so it can used in
440# from IDEs like eclipse and netbeans. 624# from IDEs like eclipse and netbeans.
441# 625#
442# Ebuild needs to DEPEND on app-arch/zip to use this. 626# Ebuild needs to DEPEND on app-arch/zip to use this.
443# 627#
444# It also should be controlled by USE=source. 628# It also should be controlled by USE=source.
445# 629#
446# @example: 630# @example:
447# java-pkg_dosrc src/* 631# java-pkg_dosrc src/*
448# 632#
449# ------------------------------------------------------------------------------ 633# ------------------------------------------------------------------------------
450# TODO change so it the arguments it takes are the base directories containing 634# TODO change so it the arguments it takes are the base directories containing
451# source -nichoj 635# source -nichoj
452# TODO should we be able to handle multiple calls to dosrc? -nichoj 636# TODO should we be able to handle multiple calls to dosrc? -nichoj
453# TODO maybe we can take an existing zip/jar? -nichoj 637# TODO maybe we can take an existing zip/jar? -nichoj
454# FIXME apparently this fails if you give it an empty directories 638# FIXME apparently this fails if you give it an empty directories
455java-pkg_dosrc() { 639java-pkg_dosrc() {
456 debug-print-function ${FUNCNAME} $* 640 debug-print-function ${FUNCNAME} $*
457 641
458 [ ${#} -lt 1 ] && die "At least one argument needed" 642 [ ${#} -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 643
463 java-pkg_check-phase install 644 java-pkg_check-phase install
464 645
465 [[ ${#} -lt 1 ]] && die "At least one argument needed" 646 [[ ${#} -lt 1 ]] && die "At least one argument needed"
647
648 if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
649 local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
650 java-pkg_announce-qa-violation ${msg}
651 fi
466 652
467 java-pkg_init_paths_ 653 java-pkg_init_paths_
468 654
469 local zip_name="${PN}-src.zip" 655 local zip_name="${PN}-src.zip"
470 local zip_path="${T}/${zip_name}" 656 local zip_path="${T}/${zip_name}"
471 local dir 657 local dir
472 for dir in ${@}; do 658 for dir in "${@}"; do
473 local dir_parent=$(dirname "${dir}") 659 local dir_parent=$(dirname "${dir}")
474 local dir_name=$(basename "${dir}") 660 local dir_name=$(basename "${dir}")
475 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 661 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
476 zip -q -r ${zip_path} ${dir_name} -i '*.java' 662 zip -q -r ${zip_path} ${dir_name} -i '*.java'
477 local result=$? 663 local result=$?
494# @ebuild-function java-pkg_dolauncher 680# @ebuild-function java-pkg_dolauncher
495# 681#
496# Make a wrapper script to lauch/start this package 682# Make a wrapper script to lauch/start this package
497# If necessary, the wrapper will switch to the appropriate VM. 683# If necessary, the wrapper will switch to the appropriate VM.
498# 684#
685# Can be called without parameters if the package installs only one jar
686# that has the Main-class attribute set. The wrapper will be named ${PN}.
687#
499# @param $1 - filename of launcher to create 688# @param $1 - filename of launcher to create
500# @param $2 - options, as follows: 689# @param $2 - options, as follows:
501# --main the.main.class.too.start 690# --main the.main.class.too.start
502# --jar /the/jar/too/launch.jar 691# --jar /the/jar/too/launch.jar or just <name>.jar
503# --java_args 'Extra arguments to pass too jave' 692# --java_args 'Extra arguments to pass to java'
504# --pkg_args 'extra arguments too pass too the package' 693# --pkg_args 'Extra arguments to pass to the package'
505# --pwd 694# --pwd Directory the launcher changes to before executing java
506# -into 695# -into Directory to install the launcher to, instead of /usr/bin
507# -pre 696# -pre Prepend contents of this file to the launcher
508# ------------------------------------------------------------------------------ 697# ------------------------------------------------------------------------------
509java-pkg_dolauncher() { 698java-pkg_dolauncher() {
510 debug-print-function ${FUNCNAME} $* 699 debug-print-function ${FUNCNAME} $*
511 700
512 java-pkg_check-phase install 701 java-pkg_check-phase install
513
514 [[ ${#} -lt 1 ]] && die "Need at least one argument"
515
516 java-pkg_init_paths_ 702 java-pkg_init_paths_
517 703
704 if [[ ${#} = 0 ]]; then
705 local name="${PN}"
706 else
518 local name="${1}" 707 local name="${1}"
708 shift
709 fi
710
519 # TODO rename to launcher 711 # TODO rename to launcher
520 local target="${T}/${name}" 712 local target="${T}/${name}"
713 local var_tmp="${T}/launcher_variables_tmp"
521 local target_dir pre 714 local target_dir pre
522 shift
523 715
524 echo "#!/bin/bash" > "${target}" 716 # Process the other the rest of the arguments
525 while [[ -n "${1}" && -n "${2}" ]]; do 717 while [[ -n "${1}" && -n "${2}" ]]; do
526 local var=${1} value=${2} 718 local var="${1}" value="${2}"
527 if [[ "${var:0:2}" == "--" ]]; then 719 if [[ "${var:0:2}" == "--" ]]; then
720 local var=${var:2}
528 echo "gjl_${var:2}=\"${value}\"" >> "${target}" 721 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
722 local gjl_${var}="${value}"
529 elif [[ "${var}" == "-into" ]]; then 723 elif [[ "${var}" == "-into" ]]; then
530 target_dir="${value}" 724 target_dir="${value}"
531 elif [[ "${var}" == "-pre" ]]; then 725 elif [[ "${var}" == "-pre" ]]; then
532 pre="${value}" 726 pre="${value}"
533 fi 727 fi
534 shift 2 728 shift 2
535 done 729 done
730
731 # Test if no --jar and --main arguments were given and
732 # in that case check if the package only installs one jar
733 # and use that jar.
734 if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
735 local cp="${JAVA_PKG_CLASSPATH}"
736 if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
737 echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
738 else
739 local msg="Not enough information to create a launcher given."
740 msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
741 die "${msg}"
742 fi
743 fi
744
745 # Write the actual script
746 echo "#!/bin/bash" > "${target}"
747 if [[ -n "${pre}" ]]; then
748 if [[ -f "${pre}" ]]; then
749 cat "${pre}" >> "${target}"
750 else
751 die "-pre specified file '${pre}' does not exist"
752 fi
753 fi
536 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 754 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
537 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 755 cat "${var_tmp}" >> "${target}"
756 rm -f "${var_tmp}"
538 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 757 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
539 758
540 if [[ -n "${into}" ]]; then 759 if [[ -n "${target_dir}" ]]; then
541 DESTTREE="${target_dir}" dobin "${target}" 760 DESTTREE="${target_dir}" dobin "${target}"
542 local ret=$? 761 local ret=$?
543 return ${ret} 762 return ${ret}
544 else 763 else
545 dobin "${target}" 764 dobin "${target}"
573 echo "dowar: warning, skipping directory ${war}" 792 echo "dowar: warning, skipping directory ${war}"
574 continue 793 continue
575 else 794 else
576 warpath="${war}" 795 warpath="${war}"
577 fi 796 fi
578 797
579 # Install those files like you mean it 798 # Install those files like you mean it
580 INSOPTIONS="-m 0644" \ 799 INSOPTIONS="-m 0644" \
581 INSDESTTREE=${JAVA_PKG_WARDEST} \ 800 INSDESTTREE=${JAVA_PKG_WARDEST} \
582 doins ${warpath} 801 doins ${warpath}
583 done 802 done
618# @ebuild-function java-pkg_jar-from 837# @ebuild-function java-pkg_jar-from
619# 838#
620# Makes a symlink to a jar from a certain package 839# Makes a symlink to a jar from a certain package
621# A lot of java packages include dependencies in a lib/ directory 840# A lot of java packages include dependencies in a lib/ directory
622# You can use this function to replace these bundled dependencies. 841# You can use this function to replace these bundled dependencies.
842# The dependency is recorded into package.env DEPEND line, unless "--build-only"
843# is passed as the very first argument, for jars that have to be present only
844# at build time and are not needed on runtime (junit testing etc).
623# 845#
624# Example: get all jars from xerces slot 2 846# Example: get all jars from xerces slot 2
625# java-pkg_jar-from xerces-2 847# java-pkg_jar-from xerces-2
626# Example: get a specific jar from xerces slot 2 848# Example: get a specific jar from xerces slot 2
627# java-pkg_jar-from xerces-2 xml-apis.jar 849# java-pkg_jar-from xerces-2 xml-apis.jar
628# Example get a specific jar from xerces slot 2, and name it diffrently 850# 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 851# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
852# Example: get junit.jar which is needed only for building
853# java-pkg_jar-from --build-only junit junit.jar
630# 854#
631# @param $1 - Package to get jars from. 855# @param $opt
856# --build-only - makes the jar(s) not added into package.env DEPEND line.
857# (assumed automatically when called inside src_test)
858# --with-dependencies - get jars also from requested package's dependencies
859# transitively.
860# --virtual - Packages passed to this function are to be handled as virtuals
861# and will not have individual jar dependencies recorded.
862# --into $dir - symlink jar(s) into $dir (must exist) instead of .
863# @param $1 - Package to get jars from, or comma-separated list of packages in
864# case other parameters are not used.
632# @param $2 - jar from package. If not specified, all jars will be used. 865# @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 866# @param $3 - When a single jar is specified, destination filename of the
634# symlink. Defaults to the name of the jar. 867# symlink. Defaults to the name of the jar.
635# ------------------------------------------------------------------------------ 868# ------------------------------------------------------------------------------
636# TODO could probably be cleaned up a little 869# TODO could probably be cleaned up a little
637java-pkg_jar-from() { 870java-pkg_jar-from() {
638 debug-print-function ${FUNCNAME} $* 871 debug-print-function ${FUNCNAME} $*
639 872
873 local build_only=""
874 local destdir="."
875 local deep=""
876 local virtual=""
877
878 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
879
880 while [[ "${1}" == --* ]]; do
881 if [[ "${1}" = "--build-only" ]]; then
882 build_only="build"
883 elif [[ "${1}" = "--with-dependencies" ]]; then
884 deep="--with-dependencies"
885 elif [[ "${1}" = "--virtual" ]]; then
886 virtual="true"
887 elif [[ "${1}" = "--into" ]]; then
888 destdir="${2}"
889 shift
890 else
891 die "java-pkg_jar-from called with unknown parameter: ${1}"
892 fi
893 shift
894 done
895
640 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 896 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
641 897
642 [[ -z ${target_pkg} ]] && die "Must specify a package" 898 [[ -z ${target_pkg} ]] && die "Must specify a package"
899
900 if [[ "${EAPI}" == "1" ]]; then
901 target_pkg="${target_pkg//:/-}"
902 fi
643 903
644 # default destjar to the target jar 904 # default destjar to the target jar
645 [[ -z "${destjar}" ]] && destjar="${target_jar}" 905 [[ -z "${destjar}" ]] && destjar="${target_jar}"
646 906
907 local error_msg="There was a problem getting the classpath for ${target_pkg}."
908 local classpath
647 local classpath="$(java-config --classpath=${target_pkg})" 909 classpath="$(java-config ${deep} --classpath=${target_pkg})"
648 [[ $? != 0 ]] && die "There was a problem getting the classpath for ${target_pkg}" 910 [[ $? != 0 ]] && die ${error_msg}
911
912 # When we have commas this functions is called to bring jars from multiple
913 # packages. This affects recording of dependencencies performed later
914 # which expects one package only, so we do it here.
915 if [[ ${target_pkg} = *,* ]]; then
916 for pkg in ${target_pkg//,/ }; do
917 java-pkg_ensure-dep "${build_only}" "${pkg}"
918 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
919 done
920 # setting this disables further record-jar_ calls later
921 build_only="build"
922 else
923 java-pkg_ensure-dep "${build_only}" "${target_pkg}"
924 fi
925
926 # Record the entire virtual as a dependency so that
927 # no jars are missed.
928 if [[ -z "${build_only}" && -n "${virtual}" ]]; then
929 java-pkg_record-jar_ "${target_pkg}"
930 # setting this disables further record-jars_ calls later
931 build_only="build"
932 fi
933
934 pushd ${destdir} > /dev/null \
935 || die "failed to change directory to ${destdir}"
649 936
650 local jar 937 local jar
651 for jar in ${classpath//:/ }; do 938 for jar in ${classpath//:/ }; do
652 local jar_name=$(basename "${jar}") 939 local jar_name=$(basename "${jar}")
653 if [[ ! -f "${jar}" ]] ; then 940 if [[ ! -f "${jar}" ]] ; then
657 # If no specific target jar was indicated, link it 944 # If no specific target jar was indicated, link it
658 if [[ -z "${target_jar}" ]] ; then 945 if [[ -z "${target_jar}" ]] ; then
659 [[ -f "${target_jar}" ]] && rm "${target_jar}" 946 [[ -f "${target_jar}" ]] && rm "${target_jar}"
660 ln -snf "${jar}" \ 947 ln -snf "${jar}" \
661 || die "Failed to make symlink from ${jar} to ${jar_name}" 948 || die "Failed to make symlink from ${jar} to ${jar_name}"
662 java-pkg_record-jar_ "${target_pkg}" "${jar}" 949 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
663 # otherwise, if the current jar is the target jar, link it 950 # otherwise, if the current jar is the target jar, link it
664 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 951 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
665 [[ -f "${destjar}" ]] && rm "${destjar}" 952 [[ -f "${destjar}" ]] && rm "${destjar}"
666 ln -snf "${jar}" "${destjar}" \ 953 ln -snf "${jar}" "${destjar}" \
667 || die "Failed to make symlink from ${jar} to ${destjar}" 954 || die "Failed to make symlink from ${jar} to ${destjar}"
668 java-pkg_record-jar_ "${target_pkg}" "${jar}" 955 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
956 popd > /dev/null
669 return 0 957 return 0
670 fi 958 fi
671 done 959 done
960 popd > /dev/null
672 # if no target was specified, we're ok 961 # if no target was specified, we're ok
673 if [[ -z "${target_jar}" ]] ; then 962 if [[ -z "${target_jar}" ]] ; then
674 return 0 963 return 0
675 # otherwise, die bitterly 964 # otherwise, die bitterly
676 else 965 else
690# ------------------------------------------------------------------------------ 979# ------------------------------------------------------------------------------
691# @ebuild-function java-pkg_getjars 980# @ebuild-function java-pkg_getjars
692# 981#
693# Get the classpath provided by any number of packages 982# Get the classpath provided by any number of packages
694# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'. 983# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
984# The providing packages are recorded as dependencies into package.env DEPEND
985# line, unless "--build-only" is passed as the very first argument, for jars
986# that have to be present only at build time and are not needed on runtime
987# (junit testing etc).
695# 988#
696# Example: Get the classpath for xerces-2, 989# Example: Get the classpath for xerces-2 and xalan,
697# java-pkg_getjars xerces-2 xalan 990# java-pkg_getjars xerces-2,xalan
698# Example Return: 991# Example Return:
699# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 992# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
700# 993#
994# @param $opt
995# --build-only - makes the jar(s) not added into package.env DEPEND line.
996# (assumed automatically when called inside src_test)
997# --with-dependencies - get jars also from requested package's dependencies
998# transitively.
701# @param $@ - list of packages to get jars from 999# @param $1 - list of packages to get jars from
1000# (passed to java-config --classpath)
702# ------------------------------------------------------------------------------ 1001# ------------------------------------------------------------------------------
703java-pkg_getjars() { 1002java-pkg_getjars() {
704 debug-print-function ${FUNCNAME} $* 1003 debug-print-function ${FUNCNAME} $*
705 1004
706 [[ ${#} -lt 1 ]] && die "At least one argument needed" 1005 local build_only=""
1006 local deep=""
707 1007
708 # NOTE could probably just pass $@ to java-config --classpath. and return it 1008 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
709 local classpath pkg 1009
710 for pkg in ${@//,/ }; do 1010 while [[ "${1}" == --* ]]; do
711 #for pkg in $(echo "$@" | tr ',' ' '); do 1011 if [[ "${1}" = "--build-only" ]]; then
712 jars="$(java-config --classpath=${pkg})" 1012 build_only="build"
713 debug-print "${pkg}:${jars}" 1013 elif [[ "${1}" = "--with-dependencies" ]]; then
714 # TODO should we ensure jars exist? 1014 deep="--with-dependencies"
715 if [[ -z "${classpath}" ]]; then
716 classpath="${jars}"
717 else 1015 else
718 classpath="${classpath}:${jars}" 1016 die "java-pkg_jar-from called with unknown parameter: ${1}"
719 fi 1017 fi
720 java-pkg_record-jar_ "${pkg}" 1018 shift
721 done 1019 done
722 echo "${classpath}" 1020
1021 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
1022
1023
1024 local pkgs="${1}"
1025
1026 if [[ "${EAPI}" == "1" ]]; then
1027 pkgs="${pkgs//:/-}"
1028 fi
1029
1030 jars="$(java-config ${deep} --classpath=${pkgs})"
1031 [[ $? != 0 ]] && die "java-config --classpath=${pkgs} failed"
1032 debug-print "${pkgs}:${jars}"
1033
1034 for pkg in ${pkgs//,/ }; do
1035 java-pkg_ensure-dep "${build_only}" "${pkg}"
1036 done
1037
1038 # Only record jars that aren't build-only
1039 if [[ -z "${build_only}" ]]; then
1040 for pkg in ${pkgs//,/ }; do
1041 java-pkg_record-jar_ "${pkg}"
1042 done
1043 fi
1044
1045 echo "${jars}"
723} 1046}
724 1047
725# ------------------------------------------------------------------------------ 1048# ------------------------------------------------------------------------------
726# @ebuild-function java-pkg_getjar 1049# @ebuild-function java-pkg_getjar
727# 1050#
728# Get the filename of a single jar from a package 1051# Get the filename of a single jar from a package
1052# The providing package is recorded as runtime dependency into package.env
1053# DEPEND line, unless "--build-only" is passed as the very first argument, for
1054# jars that have to be present only at build time and are not needed on runtime
1055# (junit testing etc).
729# 1056#
730# @example 1057# @example
731# java-pkg_getjar xerces-2 xml-apis.jar 1058# java-pkg_getjar xerces-2 xml-apis.jar
732# @example-return 1059# @example-return
733# /usr/share/xerces-2/lib/xml-apis.jar 1060# /usr/share/xerces-2/lib/xml-apis.jar
734# 1061#
1062# @param $opt
1063# --build-only - makes the jar not added into package.env DEPEND line.
1064# --virtual - Packages passed to this function are to be handled as virtuals
1065# and will not have individual jar dependencies recorded.
735# @param $1 - package to use 1066# @param $1 - package to use
736# @param $2 - jar to get 1067# @param $2 - jar to get
737# ------------------------------------------------------------------------------ 1068# ------------------------------------------------------------------------------
738java-pkg_getjar() { 1069java-pkg_getjar() {
739 debug-print-function ${FUNCNAME} $* 1070 debug-print-function ${FUNCNAME} $*
740 1071
1072 local build_only=""
1073 local virtual=""
1074
1075 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1076
1077 while [[ "${1}" == --* ]]; do
1078 if [[ "${1}" = "--build-only" ]]; then
1079 build_only="build"
1080 elif [[ "${1}" == "--virtual" ]]; then
1081 virtual="true"
1082 else
1083 die "java-pkg_getjar called with unknown parameter: ${1}"
1084 fi
1085 shift
1086 done
1087
1088 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
1089
741 local pkg="${1}" target_jar="${2}" jar 1090 local pkg="${1}" target_jar="${2}" jar
1091
1092 if [[ "${EAPI}" == "1" ]]; then
1093 pkg="${pkg//:/-}"
1094 fi
1095
742 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 1096 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
743 [[ -z ${target_jar} ]] && die "Must specify jar to get" 1097 [[ -z ${target_jar} ]] && die "Must specify jar to get"
744 1098
745 # TODO check that package is actually installed 1099 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
1100 local classpath
746 local classpath=$(java-config --classpath=${pkg}) 1101 classpath=$(java-config --classpath=${pkg})
747 [[ $? != 0 ]] && die "There could not find classpath for ${pkg}. Are you sure its installed?" 1102 [[ $? != 0 ]] && die ${error_msg}
1103
1104 java-pkg_ensure-dep "${build_only}" "${pkg}"
1105
1106 # Record the package(Virtual) as a dependency and then set build_only
1107 # So that individual jars are not recorded.
1108 if [[ -n "${virtual}" ]]; then
1109 java-pkg_record-jar_ "${pkg}"
1110 build_only="true"
1111 fi
1112
748 for jar in ${classpath//:/ }; do 1113 for jar in ${classpath//:/ }; do
749 if [[ ! -f "${jar}" ]] ; then 1114 if [[ ! -f "${jar}" ]] ; then
750 die "Installation problems with jars in ${pkg} - is it installed?" 1115 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
751 fi 1116 fi
752 1117
753 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then 1118 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
754 java-pkg_record-jar_ "${pkg}" "${jar}" 1119 # Only record jars that aren't build-only
1120 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" "${jar}"
755 echo "${jar}" 1121 echo "${jar}"
756 return 0 1122 return 0
757 fi 1123 fi
758 done 1124 done
759 1125
760 die "Could not find ${target_jar} in ${pkg}" 1126 die "Could not find ${target_jar} in ${pkg}"
761 return 1 1127 return 1
1128}
1129
1130# ------------------------------------------------------------------------------
1131# @ebuild-function java-pkg_register-dependency
1132#
1133# Registers runtime dependency on a package, list of packages, or a single jar
1134# from a package, into package.env DEPEND line. Can only be called in
1135# src_install phase.
1136# Intended for binary packages where you don't need to symlink the jars or get
1137# their classpath during build. As such, the dependencies only need to be
1138# specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1139#
1140# @param $1 - comma-separated list of packages, or a single package
1141# @param $2 - if param $1 is a single package, optionally specify the jar
1142# to depend on
1143#
1144# Example: Record the dependency on whole xerces-2 and xalan,
1145# java-pkg_register-dependency xerces-2,xalan
1146# Example: Record the dependency on ant.jar from ant-core
1147# java-pkg_register-dependency ant-core ant.jar
1148#
1149# Note: Passing both list of packages as the first parameter AND specifying the
1150# jar as the second is not allowed and will cause the function to die. We assume
1151# that there's more chance one passes such combination as a mistake, than that
1152# there are more packages providing identically named jar without class
1153# collisions.
1154# ------------------------------------------------------------------------------
1155java-pkg_register-dependency() {
1156 debug-print-function ${FUNCNAME} $*
1157
1158 java-pkg_check-phase install
1159
1160 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1161
1162 local pkgs="${1}"
1163 local jar="${2}"
1164
1165 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1166
1167 if [[ "${EAPI}" == "1" ]]; then
1168 pkgs="${pkgs//:/-}"
1169 fi
1170
1171 if [[ -z "${jar}" ]]; then
1172 for pkg in ${pkgs//,/ }; do
1173 java-pkg_ensure-dep runtime "${pkg}"
1174 java-pkg_record-jar_ "${pkg}"
1175 done
1176 else
1177 [[ ${pkgs} == *,* ]] && \
1178 die "${FUNCNAME} called with both package list and jar name"
1179 java-pkg_ensure-dep runtime "${pkgs}"
1180 java-pkg_record-jar_ "${pkgs}" "${jar}"
1181 fi
1182
1183 java-pkg_do_write_
1184}
1185
1186# ------------------------------------------------------------------------------
1187# @ebuild-function java-pkg_register-optional-dependency
1188#
1189# Registers optional runtime dependency on a package, list of packages, or a
1190# single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be
1191# called in src_install phase.
1192# Intended for packages that can use other packages when those are in classpath.
1193# Will be put on classpath by launcher if they are installed. Typical case is
1194# JDBC implementations for various databases. It's better than having USE flag
1195# for each implementation triggering hard dependency.
1196#
1197# @param $1 - comma-separated list of packages, or a single package
1198# @param $2 - if param $1 is a single package, optionally specify the jar
1199# to depend on
1200#
1201# Example: Record the optional dependency on some jdbc providers
1202# java-pkg_register-optional-dependency jdbc-jaybird,jtds-1.2,jdbc-mysql
1203#
1204# Note: Passing both list of packages as the first parameter AND specifying the
1205# jar as the second is not allowed and will cause the function to die. We assume
1206# that there's more chance one passes such combination as a mistake, than that
1207# there are more packages providing identically named jar without class
1208# collisions.
1209# ------------------------------------------------------------------------------
1210java-pkg_register-optional-dependency() {
1211 debug-print-function ${FUNCNAME} $*
1212
1213 java-pkg_check-phase install
1214
1215 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1216
1217 local pkgs="${1}"
1218 local jar="${2}"
1219
1220 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1221
1222 if [[ "${EAPI}" == "1" ]]; then
1223 pkgs="${pkgs//:/-}"
1224 fi
1225
1226 if [[ -z "${jar}" ]]; then
1227 for pkg in ${pkgs//,/ }; do
1228 java-pkg_record-jar_ --optional "${pkg}"
1229 done
1230 else
1231 [[ ${pkgs} == *,* ]] && \
1232 die "${FUNCNAME} called with both package list and jar name"
1233 java-pkg_record-jar_ --optional "${pkgs}" "${jar}"
1234 fi
1235
1236 java-pkg_do_write_
1237}
1238
1239# ------------------------------------------------------------------------------
1240# @ebuild-function java-pkg_register-environment-variable
1241#
1242# Register an arbitrary environment variable into package.env. The gjl launcher
1243# for this package or any package depending on this will export it into
1244# environement before executing java command.
1245# Must only be called in src_install phase.
1246#
1247# @param $1 - variable name
1248# @param $2 - variable value
1249# ------------------------------------------------------------------------------
1250JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
1251JAVA_PKG_EXTRA_ENV_VARS=""
1252java-pkg_register-environment-variable() {
1253 debug-print-function ${FUNCNAME} $*
1254
1255 java-pkg_check-phase install
1256
1257 [[ ${#} != 2 ]] && die "${FUNCNAME} takes two arguments"
1258
1259 echo "${1}=\"${2}\"" >> ${JAVA_PKG_EXTRA_ENV}
1260 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
1261
1262 java-pkg_do_write_
762} 1263}
763 1264
764# This function reads stdin, and based on that input, figures out how to 1265# This function reads stdin, and based on that input, figures out how to
765# populate jars from the filesystem. 1266# populate jars from the filesystem.
766# Need to figure out a good way of making use of this, ie be able to use a 1267# Need to figure out a good way of making use of this, ie be able to use a
778# line="${line// /}" 1279# line="${line// /}"
779# 1280#
780# # format: path=jarinfo 1281# # format: path=jarinfo
781# local path=${line%%=*} 1282# local path=${line%%=*}
782# local jarinfo=${line##*=} 1283# local jarinfo=${line##*=}
783# 1284#
784# # format: jar@package 1285# # format: jar@package
785# local jar=${jarinfo%%@*}.jar 1286# local jar=${jarinfo%%@*}.jar
786# local package=${jarinfo##*@} 1287# local package=${jarinfo##*@}
787# if [[ -n ${replace_only} ]]; then 1288# if [[ -n ${replace_only} ]]; then
788# [[ ! -f $path ]] && die "No jar exists at ${path}" 1289# [[ ! -f $path ]] && die "No jar exists at ${path}"
801# @section-end query 1302# @section-end query
802# ------------------------------------------------------------------------------ 1303# ------------------------------------------------------------------------------
803 1304
804# ------------------------------------------------------------------------------ 1305# ------------------------------------------------------------------------------
805# @section-begin helper 1306# @section-begin helper
806# @section-summary Helper functions 1307# @section-summary Helper functions
807# 1308#
808# Various other functions to use from an ebuild 1309# Various other functions to use from an ebuild
809# ------------------------------------------------------------------------------ 1310# ------------------------------------------------------------------------------
810 1311
811# ------------------------------------------------------------------------------ 1312# ------------------------------------------------------------------------------
812# @ebuild-function java-pkg_need 1313# @ebuild-function java-pkg_find-normal-jars
813# 1314#
814# Adds virtual dependencies, which can optionally be controlled by a USE flag. 1315# Find the files with suffix .jar file in the given directory or $WORKDIR
815# Currently supported virtuals are:
816# javamail
817# jdbc-stdext
818# jaf
819# jdbc-rowset
820# jms
821# 1316#
822# @param $1 - Optionally indicate that the dependencies are controlled by 1317# @param $1 - The directory to search for jar files (default: ${WORKDIR})
823# a use flag by specifying '--use' Requires $2.
824# @param $2 - USE flag which will enable the dependencies.
825# @param $@ - virtual packages to add depenedencies for
826# ------------------------------------------------------------------------------ 1318# ------------------------------------------------------------------------------
827# TODO rewrite to parse a line based declaration file instead -- karltk 1319java-pkg_find-normal-jars() {
828#java-pkg_need() { 1320 local dir=$1
829# debug-print-function ${FUNCNAME} $* 1321 [[ "${dir}" ]] || dir="${WORKDIR}"
830# local useflag 1322 local found
831# if [[ ${1} == "--use" ]]; then 1323 for jar in $(find "${dir}" -name "*.jar" -type f); do
832# useflag="${2}" 1324 echo "${jar}"
833# shift 2 1325 found="true"
834# fi
835#
836# if [[ -z ${1} ]]; then
837# die "Must specify at least one virtual package."
838# fi
839#
840# local depstr newdepstr
841#
842# for virtual in ${@}; do
843# if has ${virtual} ${JAVA_PKG_VNEED}; then
844# debug-print "Already registered virtual ${virtual}"
845# continue
846# fi
847# case ${virtual} in
848# javamail)
849# debug-print "java-pkg_need: adding javamail dependencies"
850# newdepstr="|| ( dev-java/gnu-javamail dev-java/sun-javamail-bin )"
851# ;;
852# jdbc-stdext)
853# debug-print "java-pkg_need: adding jdbc-stdext dependencies"
854# newdepstr="|| ( >=virtual/jdk-1.4 dev-java/jdbc2-stdext )"
855# ;;
856# jaf)
857# debug-print "java-pkg_need: adding jaf dependencies"
858# newdepstr="|| ( dev-java/gnu-jaf dev-java/sun-jaf-bin )"
859# ;;
860# jdbc-rowset)
861# debug-print "java-pkg_need: adding jdbc-rowset dependencies"
862# newdepstr="|| ( >=virtual/jdk-1.5 dev-java/sun-jdbc-rowset )"
863# ;;
864# jms)
865# debug-print "java-pkg_need: adding jms dependencies"
866# newdepstr="|| ( dev-java/sun-jms dev-java/openjms )"
867# ;;
868# *)
869# die "Invalid virtual: ${virtual}"
870# esac
871#
872# export JAVA_PKG_VNEED="${JAVA_PKG_VNEED} ${virtual}"
873#
874# if [[ -n ${useflag} ]]; then
875# depstr="${depstr} ${useflag}? ( ${newdepstr} )"
876# else
877# depstr="${depstr} ${newdepstr}"
878# fi
879# done 1326 done
880# 1327 [[ "${found}" ]]
881# [[ -z ${JAVA_PKG_NV_DEPEND} ]] && export JAVA_PKG_NV_DEPEND="${DEPEND}" 1328 return $?
882# [[ -z ${JAVA_PKG_NV_RDEPEND} ]] && export JAVA_PKG_NV_RDEPEND="${RDEPEND}" 1329}
883#
884# export DEPEND="${DEPEND} ${depstr}"
885# export RDEPEND="${RDEPEND} ${depstr}"
886#}
887 1330
1331# ------------------------------------------------------------------------------
1332# @ebuild-function java-pkg_ensure-no-bundled-jars
1333#
1334# 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 1335# This function should be called after WORKDIR has been populated with symlink
889# TODO document 1336# to system jar files or bundled jars removed.
1337# ------------------------------------------------------------------------------
890java-pkg_ensure-no-bundled-jars() { 1338java-pkg_ensure-no-bundled-jars() {
891 debug-print-function ${FUNCNAME} $* 1339 debug-print-function ${FUNCNAME} $*
892 pushd ${WORKDIR} >/dev/null 2>/dev/null
893 1340
894 local bundled_jars=$(find . -name "*.jar" -type f) 1341 local bundled_jars=$(java-pkg_find-normal-jars)
895 if [[ -n ${bundled_jars} ]]; then 1342 if [[ -n ${bundled_jars} ]]; then
896 echo "Bundled jars found:" 1343 echo "Bundled jars found:"
897 local jar 1344 local jar
898 for jar in ${bundled_jars}; do 1345 for jar in ${bundled_jars}; do
899 echo $(pwd)${jar/./} 1346 echo $(pwd)${jar/./}
900 done 1347 done
901 die "Bundled jars found!" 1348 die "Bundled jars found!"
902
903 fi 1349 fi
904 popd >/dev/null 2>/dev/null
905} 1350}
906 1351
907# ------------------------------------------------------------------------------ 1352# ------------------------------------------------------------------------------
908# @internal-function java-pkg_ensure-vm-version-sufficient 1353# @internal-function java-pkg_ensure-vm-version-sufficient
909# 1354#
921 fi 1366 fi
922} 1367}
923 1368
924# ------------------------------------------------------------------------------ 1369# ------------------------------------------------------------------------------
925# @internal-function java-pkg_is-vm-version-sufficient 1370# @internal-function java-pkg_is-vm-version-sufficient
926# 1371#
927# @return zero - VM is sufficient 1372# @return zero - VM is sufficient
928# @return non-zero - VM is not sufficient 1373# @return non-zero - VM is not sufficient
929# ------------------------------------------------------------------------------ 1374# ------------------------------------------------------------------------------
930java-pkg_is-vm-version-sufficient() { 1375java-pkg_is-vm-version-sufficient() {
931 debug-print-function ${FUNCNAME} $* 1376 debug-print-function ${FUNCNAME} $*
951 die "Active Java VM too old" 1396 die "Active Java VM too old"
952 fi 1397 fi
953} 1398}
954 1399
955# ------------------------------------------------------------------------------ 1400# ------------------------------------------------------------------------------
956# @internal-function java-pkg_is-vm-version-eq 1401# @internal-function java-pkg_is-vm-version-eq
957# 1402#
958# @param $@ - VM version to compare current VM to 1403# @param $@ - VM version to compare current VM to
959# @return zero - VM versions are equal 1404# @return zero - VM versions are equal
960# @return non-zero - VM version are not equal 1405# @return non-zero - VM version are not equal
961# ------------------------------------------------------------------------------ 1406# ------------------------------------------------------------------------------
962java-pkg_is-vm-version-eq() { 1407java-pkg_is-vm-version-eq() {
992# 1437#
993# @param $@ - VM version to compare current to 1438# @param $@ - VM version to compare current to
994# ------------------------------------------------------------------------------ 1439# ------------------------------------------------------------------------------
995java-pkg_ensure-vm-version-ge() { 1440java-pkg_ensure-vm-version-ge() {
996 debug-print-function ${FUNCNAME} $* 1441 debug-print-function ${FUNCNAME} $*
997 1442
998 if ! java-pkg_is-vm-version-ge "$@" ; then 1443 if ! java-pkg_is-vm-version-ge "$@" ; then
999 debug-print "vm is not suffient" 1444 debug-print "vm is not suffient"
1000 eerror "This package requires a Java VM version >= $@" 1445 eerror "This package requires a Java VM version >= $@"
1001 einfo "Please use java-config -S to set the correct one" 1446 einfo "Please use java-config -S to set the correct one"
1002 die "Active Java VM too old" 1447 die "Active Java VM too old"
1003 fi 1448 fi
1004} 1449}
1005 1450
1006# ------------------------------------------------------------------------------ 1451# ------------------------------------------------------------------------------
1007# @internal-function java-pkg_is-vm-version-ge 1452# @internal-function java-pkg_is-vm-version-ge
1008# 1453#
1009# @param $@ - VM version to compare current VM to 1454# @param $@ - VM version to compare current VM to
1010# @return zero - current VM version is greater than checked version 1455# @return zero - current VM version is greater than checked version
1011# @return non-zero - current VM version is not greater than checked version 1456# @return non-zero - current VM version is not greater than checked version
1012# ------------------------------------------------------------------------------ 1457# ------------------------------------------------------------------------------
1013java-pkg_is-vm-version-ge() { 1458java-pkg_is-vm-version-ge() {
1027 return 1 1472 return 1
1028 fi 1473 fi
1029 fi 1474 fi
1030} 1475}
1031 1476
1477java-pkg_set-current-vm() {
1478 export GENTOO_VM=${1}
1479}
1480
1481java-pkg_get-current-vm() {
1482 echo ${GENTOO_VM}
1483}
1484
1485java-pkg_current-vm-matches() {
1486 hasq $(java-pkg_get-current-vm) ${@}
1487 return $?
1488}
1489
1032# ------------------------------------------------------------------------------ 1490# ------------------------------------------------------------------------------
1033# @ebuild-function java-pkg_get-source 1491# @ebuild-function java-pkg_get-source
1034# 1492#
1035# Determines what source version should be used, for passing to -source. 1493# 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 1494# Unless you want to break things you probably shouldn't set _WANT_SOURCE
1037# 1495#
1038# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE 1496# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1039# ------------------------------------------------------------------------------ 1497# ------------------------------------------------------------------------------
1044# ------------------------------------------------------------------------------ 1502# ------------------------------------------------------------------------------
1045# @ebuild-function java-pkg_get-target 1503# @ebuild-function java-pkg_get-target
1046# 1504#
1047# Determines what target version should be used, for passing to -target. 1505# 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 1506# If you don't care about lower versions, you can set _WANT_TARGET to the
1049# version of your JDK. 1507# 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# 1508#
1054# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1509# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1055# ------------------------------------------------------------------------------ 1510# ------------------------------------------------------------------------------
1056java-pkg_get-target() { 1511java-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}")} 1512 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1070} 1513}
1071 1514
1072java-pkg_get-javac() { 1515java-pkg_get-javac() {
1073 debug-print-function ${FUNCNAME} $* 1516 debug-print-function ${FUNCNAME} $*
1074 1517
1075 java-pkg_init-compiler_ 1518
1076 local compiler="${GENTOO_COMPILER}" 1519 local compiler="${GENTOO_COMPILER}"
1077 1520
1078 local compiler_executable 1521 local compiler_executable
1079 if [[ "${compiler}" = "javac" ]]; then 1522 if [[ "${compiler}" = "javac" ]]; then
1080 # nothing fancy needs to be done for javac 1523 # nothing fancy needs to be done for javac
1088 unset JAVAC 1531 unset JAVAC
1089 # try to get value of JAVAC 1532 # try to get value of JAVAC
1090 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1533 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1091 export JAVAC=${old_javac} 1534 export JAVAC=${old_javac}
1092 1535
1093 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1536 if [[ -z ${compiler_executable} ]]; then
1094 1537 echo "JAVAC is empty or undefined in ${compiler_env}"
1538 return 1
1539 fi
1540
1095 # check that it's executable 1541 # check that it's executable
1096 if [[ ! -x ${compiler_executable} ]]; then 1542 if [[ ! -x ${compiler_executable} ]]; then
1097 eerror "Could not find ${compiler_executable}!"
1098 die "${compiler_executable} doesn't exist, or isn't executable" 1543 echo "${compiler_executable} doesn't exist, or isn't executable"
1544 return 1
1099 fi 1545 fi
1100 else 1546 else
1101 eerror "Could not find environment file for ${compiler}" 1547 echo "Could not find environment file for ${compiler}"
1102 die "Could not find ${compiler_env}" 1548 return 1
1103 fi 1549 fi
1104 fi 1550 fi
1105 echo ${compiler_executable} 1551 echo ${compiler_executable}
1106} 1552}
1107 1553
1108# ------------------------------------------------------------------------------ 1554# ------------------------------------------------------------------------------
1109# @ebuild-function java-pkg_javac-args 1555# @ebuild-function java-pkg_javac-args
1110# 1556#
1111# If an ebuild uses javac directly, instead of using ejavac, it should call this 1557# If an ebuild uses javac directly, instead of using ejavac, it should call this
1112# to know what -source/-target to use. 1558# to know what -source/-target to use.
1113# 1559#
1114# @return string - arguments to pass to javac, complete with -target and -source 1560# @return string - arguments to pass to javac, complete with -target and -source
1117 debug-print-function ${FUNCNAME} $* 1563 debug-print-function ${FUNCNAME} $*
1118 1564
1119 local want_source="$(java-pkg_get-source)" 1565 local want_source="$(java-pkg_get-source)"
1120 local want_target="$(java-pkg_get-target)" 1566 local want_target="$(java-pkg_get-target)"
1121 1567
1122 local source_str="-source ${want_source}" 1568 local source_str="-source ${want_source}"
1123 local target_str="-target ${want_target}" 1569 local target_str="-target ${want_target}"
1124 1570
1125 debug-print "want source: ${want_source}" 1571 debug-print "want source: ${want_source}"
1126 debug-print "want target: ${want_target}" 1572 debug-print "want target: ${want_target}"
1127 1573
1128 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1574 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1129 debug-print "could not find valid -source/-target values" 1575 debug-print "could not find valid -source/-target values for javac"
1130 die "Could not find valid -source/-target values" 1576 echo "Could not find valid -source/-target values for javac"
1577 return 1
1131 else 1578 else
1132 if java-pkg_is-vm-version-ge "1.4"; then 1579 if java-pkg_is-vm-version-ge "1.4"; then
1133 echo "${source_str} ${target_str}" 1580 echo "${source_str} ${target_str}"
1134 else 1581 else
1135 echo "${target_str}" 1582 echo "${target_str}"
1139 1586
1140# TODO document 1587# TODO document
1141java-pkg_get-jni-cflags() { 1588java-pkg_get-jni-cflags() {
1142 local flags="-I${JAVA_HOME}/include" 1589 local flags="-I${JAVA_HOME}/include"
1143 1590
1144 # TODO figure out how to cope with other things than linux... 1591 local platform="linux"
1592 use elibc_FreeBSD && platform="freebsd"
1593
1594 # TODO do a check that the directories are valid
1145 flags="${flags} -I${JAVA_HOME}/include/linux" 1595 flags="${flags} -I${JAVA_HOME}/include/${platform}"
1146 1596
1147 echo ${flags} 1597 echo ${flags}
1148} 1598}
1149 1599
1600java-pkg_ensure-gcj() {
1601 if ! built_with_use sys-devel/gcc gcj ; then
1602 ewarn
1603 ewarn "You must build gcc with the gcj support to build with gcj"
1604 ewarn
1605 ebeep 5
1606 die "No GCJ support found!"
1607 fi
1608}
1609
1610java-pkg_ensure-test() {
1611 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \
1612 && hasq test ${IUSE} && ! use test;
1613 then
1614 eerror "You specified FEATURES=test, but USE=test is needed"
1615 eerror "to pull in the additional dependencies for testing"
1616 die "Need USE=test enabled"
1617 fi
1618}
1619
1620# ------------------------------------------------------------------------------
1621# @ebuild-function java-pkg_register-ant-task
1622#
1623# Register this package as ant task, so that ant will load it when no specific
1624# ANT_TASKS are specified. Note that even without this registering, all packages
1625# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1626# packages, but can be also used by other ebuilds that used to symlink their
1627# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1628# compatibility.
1629#
1630# @param --version x.y Register only for ant version x.y (otherwise for any ant
1631# version). Used by the ant-* packages to prevent loading of mismatched
1632# ant-core ant tasks after core was updated, before the tasks are updated,
1633# without a need for blockers.
1634# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1635# ------------------------------------------------------------------------------
1636java-pkg_register-ant-task() {
1637 local TASKS_DIR="tasks"
1638
1639 # check for --version x.y parameters
1640 while [[ -n "${1}" && -n "${2}" ]]; do
1641 local var="${1#--}"
1642 local val="${2}"
1643 if [[ "${var}" == "version" ]]; then
1644 TASKS_DIR="tasks-${val}"
1645 else
1646 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1647 fi
1648 shift 2
1649 done
1650
1651 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1652
1653 dodir /usr/share/ant/${TASKS_DIR}
1654 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1655}
1656
1657# ------------------------------------------------------------------------------
1658# @internal-function java-pkg_ant-tasks-depend
1659#
1660# Translates the WANT_ANT_TASKS variable into valid dependencies.
1661# ------------------------------------------------------------------------------
1662java-pkg_ant-tasks-depend() {
1663 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1664
1665 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1666 local DEP=""
1667 for i in ${WANT_ANT_TASKS}
1668 do
1669 if [[ ${i} = ant-* ]]; then
1670 DEP="${DEP}dev-java/${i} "
1671 elif [[ ${i} = */*:* ]]; then
1672 DEP="${DEP}${i} "
1673 else
1674 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1675 return 1
1676 fi
1677 done
1678 echo ${DEP}
1679 return 0
1680 else
1681 return 0
1682 fi
1683}
1684
1685# ------------------------------------------------------------------------------
1686# @ebuild-function ejunit
1687#
1688# Junit wrapper function. Makes it easier to run the tests and checks for
1689# dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner.
1690#
1691# Examples:
1692# ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1693# ejunit org.blinkenlights.jid3.test.AllTests
1694#
1695# @param $1 - -cp or -classpath
1696# @param $2 - classpath; junit and recorded dependencies get appended
1697# @param $@ - the rest of the parameters are passed to java
1698# ------------------------------------------------------------------------------
1699ejunit() {
1700 debug-print-function ${FUNCNAME} $*
1701
1702 local pkgs
1703 if [[ -f ${JAVA_PKG_DEPEND_FILE} ]]; then
1704 for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
1705 pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
1706 done
1707 fi
1708
1709 local cp=$(java-pkg_getjars --with-dependencies junit${pkgs})
1710 if [[ ${1} = -cp || ${1} = -classpath ]]; then
1711 cp="${2}:${cp}"
1712 shift 2
1713 else
1714 cp=".:${cp}"
1715 fi
1716
1717 local runner=junit.textui.TestRunner
1718 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}"
1719 java -cp "${cp}" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
1720}
1721
1150# ------------------------------------------------------------------------------ 1722# ------------------------------------------------------------------------------
1151# @section-end helper 1723# @section-end helper
1152# ------------------------------------------------------------------------------ 1724# ------------------------------------------------------------------------------
1725
1726# ------------------------------------------------------------------------------
1727# @eclass-src_prepare
1728#
1729# src_prepare Searches for bundled jars
1730# Don't call directly, but via java-pkg-2_src_prepare!
1731# ------------------------------------------------------------------------------
1732
1733java-utils-2_src_prepare() {
1734 [[ ${EBUILD_PHASE} == prepare ]] &&
1735 java-pkg_func-exists java_prepare && java_prepare
1736
1737 # Remember that eant will call this unless called via Portage
1738 if [[ ! -e "${T}/java-utils-2_src_prepare-run" ]] && is-java-strict; then
1739 echo "Searching for bundled jars:"
1740 java-pkg_find-normal-jars || echo "None found."
1741 echo "Searching for bundled classes (no output if none found):"
1742 find "${WORKDIR}" -name "*.class"
1743 echo "Search done."
1744 fi
1745 touch "${T}/java-utils-2_src_prepare-run"
1746}
1747
1748# ------------------------------------------------------------------------------
1749# @eclass-pkg_preinst
1750#
1751# pkg_preinst Searches for missing and unneeded dependencies
1752# Don't call directly, but via java-pkg-2_pkg_preinst!
1753# ------------------------------------------------------------------------------
1754
1755java-utils-2_pkg_preinst() {
1756 if is-java-strict; then
1757 if has_version dev-java/java-dep-check; then
1758 [[ -e "${JAVA_PKG_ENV}" ]] || return
1759 local output=$(GENTOO_VM= java-dep-check --image "${D}" "${JAVA_PKG_ENV}")
1760 if [[ ${output} && has_version <=dev-java/java-dep-check-0.2 ]]; then
1761 ewarn "Possibly unneeded dependencies found in package.env:"
1762 for dep in ${output}; do
1763 ewarn "\t${dep}"
1764 done
1765 fi
1766 if [[ ${output} && has_version >dev-java/java-dep-check-0.2 ]]; then
1767 ewarn "${output}"
1768 fi
1769 else
1770 eerror "Install dev-java/java-dep-check for dependency checking"
1771 fi
1772 fi
1773}
1153 1774
1154# ------------------------------------------------------------------------------ 1775# ------------------------------------------------------------------------------
1155# @section-begin build 1776# @section-begin build
1156# @section-summary Build functions 1777# @section-summary Build functions
1157# 1778#
1161 1782
1162# ------------------------------------------------------------------------------ 1783# ------------------------------------------------------------------------------
1163# @ebuild-function eant 1784# @ebuild-function eant
1164# 1785#
1165# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1786# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1166# compiler. 1787# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1167# 1788# variables:
1789# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1790# gentoo.classpath property. Be sure to call
1791# java-ant_rewrite-classpath in src_unpack.
1792# EANT_NEEDS_TOOLS - add tools.jar to the gentoo.classpath. Should only be used
1793# for build-time purposes, the dependency is not recorded to
1794# package.env!
1795# JAVA_PKG_NO_BUNDLED_SEARCH - Don't search for bundled jars or class files
1796# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1168# ------------------------------------------------------------------------------ 1797# ------------------------------------------------------------------------------
1169eant() { 1798eant() {
1170 debug-print-function ${FUNCNAME} $* 1799 debug-print-function ${FUNCNAME} $*
1171 1800
1172 local antflags 1801 if [[ ${EBUILD_PHASE} = compile ]]; then
1802 java-ant-2_src_configure
1803 java-utils-2_src_prepare
1804 fi
1805
1806 if ! hasq java-ant-2 ${INHERITED}; then
1807 local msg="You should inherit java-ant-2 when using eant"
1808 java-pkg_announce-qa-violation "${msg}"
1809 fi
1810
1811 local antflags="-Dnoget=true -Dmaven.mode.offline=true -Dbuild.sysclasspath=ignore"
1812
1173 java-pkg_init-compiler_ 1813 java-pkg_init-compiler_
1174 local compiler="${GENTOO_COMPILER}" 1814 local compiler="${GENTOO_COMPILER}"
1175 1815
1176 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1816 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})" 1817 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})"
1179 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1818 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1180 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1819 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1181 fi 1820 fi
1182 1821
1183 if [[ ${compiler} != "javac" ]]; then 1822 if [[ ${compiler} != "javac" ]]; then
1184 antflags="-Dbuild.compiler=${build_compiler}" 1823 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1185 # Figure out any extra stuff to put on the classpath for compilers aside 1824 # Figure out any extra stuff to put on the classpath for compilers aside
1186 # from javac 1825 # from javac
1187 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to 1826 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1188 # java-config -p 1827 # java-config -p
1189 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1828 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 1829 if [[ -n ${build_compiler_deps} ]]; then
1191 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})" 1830 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1192 fi 1831 fi
1193 fi 1832 fi
1194 1833
1195 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1834 for arg in "${@}"; do
1196 antflags="${antflags} -debug" 1835 if [[ ${arg} = -lib ]]; then
1836 if is-java-strict; then
1837 eerror "You should not use the -lib argument to eant because it will fail"
1838 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1839 eerror "or ant properties to make dependencies available."
1840 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1841 eerror "split ant (>=dev-java/ant-core-1.7)."
1842 die "eant -lib is deprecated/forbidden"
1843 else
1844 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1845 echo "more info."
1846 fi
1197 fi 1847 fi
1198 1848 done
1849
1850 # parse WANT_ANT_TASKS for atoms
1851 local want_ant_tasks
1852 for i in ${WANT_ANT_TASKS}; do
1853 if [[ ${i} = */*:* ]]; then
1854 i=${i#*/}
1855 i=${i%:0}
1856 want_ant_tasks+="${i/:/-} "
1857 else
1858 want_ant_tasks+="${i} "
1859 fi
1860 done
1861 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1862 ANT_TASKS="${ANT_TASKS:-${want_ant_tasks% }}"
1863
1864 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1865 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1866
1867 # if ant-tasks is not set by ebuild or forced, use none
1868 ANT_TASKS="${ANT_TASKS:-none}"
1869
1870 # at this point, ANT_TASKS should be "all", "none" or explicit list
1871 if [[ "${ANT_TASKS}" == "all" ]]; then
1872 einfo "Using all available ANT_TASKS"
1873 elif [[ "${ANT_TASKS}" == "none" ]]; then
1874 einfo "Disabling all optional ANT_TASKS"
1875 else
1876 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1877 fi
1878
1879 export ANT_TASKS
1880
1881 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1882 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1883
1884 local gcp="${EANT_GENTOO_CLASSPATH}"
1885 local getjarsarg=""
1886
1887 if [[ ${EBUILD_PHASE} = "test" ]]; then
1888 antflags="${antflags} -DJunit.present=true"
1889 [[ ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1890 getjarsarg="--with-dependencies"
1891 fi
1892
1893 local cp
1894
1895 for atom in ${gcp}; do
1896 cp="${cp}:$(java-pkg_getjars ${getjarsarg} ${atom})"
1897 done
1898
1899 [[ -n "${EANT_NEEDS_TOOLS}" ]] && cp="${cp}:$(java-config --tools)"
1900
1901 if [[ ${cp} ]]; then
1902 # It seems ant does not like single quotes around ${cp}
1903 cp=${cp#:}
1904 [[ ${EANT_GENTOO_CLASSPATH_EXTRA} ]] && \
1905 cp="${cp}:${EANT_GENTOO_CLASSPATH_EXTRA}"
1906 antflags="${antflags} -Dgentoo.classpath=\"${cp}\""
1907 fi
1908
1199 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1909 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1910 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
1200 ant ${antflags} "${@}" || die "eant failed" 1911 ant ${antflags} "${@}" || die "eant failed"
1201
1202} 1912}
1203 1913
1204# ------------------------------------------------------------------------------ 1914# ------------------------------------------------------------------------------
1205# @ebuild-function ejavac 1915# @ebuild-function ejavac
1206# 1916#
1207# Javac wrapper function. Will use the appropriate compiler, based on 1917# Javac wrapper function. Will use the appropriate compiler, based on
1208# /etc/java-config/compilers.conf 1918# /etc/java-config/compilers.conf
1209# 1919#
1210# @param $@ - Arguments to be passed to the compiler 1920# @param $@ - Arguments to be passed to the compiler
1211# ------------------------------------------------------------------------------ 1921# ------------------------------------------------------------------------------
1212ejavac() { 1922ejavac() {
1213 debug-print-function ${FUNCNAME} $* 1923 debug-print-function ${FUNCNAME} $*
1214 1924
1925 java-pkg_init-compiler_
1926
1927 local compiler_executable
1215 local compiler_executable=$(java-pkg_get-javac) 1928 compiler_executable=$(java-pkg_get-javac)
1929 if [[ ${?} != 0 ]]; then
1930 eerror "There was a problem determining compiler: ${compiler_executable}"
1931 die "get-javac failed"
1932 fi
1216 1933
1934 local javac_args
1935 javac_args="$(java-pkg_javac-args)"
1936 if [[ ${?} != 0 ]]; then
1937 eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
1938 die "java-pkg_javac-args failed"
1939 fi
1940
1217 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 1941 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1218 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 1942 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1219} 1943}
1220 1944
1221# ------------------------------------------------------------------------------ 1945# ------------------------------------------------------------------------------
1222# @ebuild-function java-pkg_filter-compiler 1946# @ebuild-function java-pkg_filter-compiler
1223# 1947#
1224# Used to prevent the use of some compilers. Should be used in src_compile. 1948# Used to prevent the use of some compilers. Should be used in src_compile.
1225# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER 1949# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
1226# 1950#
1227# @param $@ - compilers to filter 1951# @param $@ - compilers to filter
1228# ------------------------------------------------------------------------------ 1952# ------------------------------------------------------------------------------
1229java-pkg_filter-compiler() { 1953java-pkg_filter-compiler() {
1230 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@" 1954 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@"
1231} 1955}
1232 1956
1233# ------------------------------------------------------------------------------ 1957# ------------------------------------------------------------------------------
1958# @ebuild-function java-pkg_force-compiler
1959#
1960# Used to force the use of particular compilers. Should be used in src_compile.
1961# A common use of this would be to force ecj-3.1 to be used on amd64, to avoid
1962# OutOfMemoryErrors that may come up.
1963#
1964# @param $@ - compilers to force
1965# ------------------------------------------------------------------------------
1966java-pkg_force-compiler() {
1967 JAVA_PKG_FORCE_COMPILER="$@"
1968}
1969
1970# ------------------------------------------------------------------------------
1234# @ebuild-function use_doc 1971# @ebuild-function use_doc
1235# 1972#
1236# Helper function for getting ant to build javadocs. If the user has USE=doc, 1973# 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. 1974# then 'javadoc' or the argument are returned. Otherwise, there is no return.
1238# 1975#
1239# The output of this should be passed to ant. 1976# The output of this should be passed to ant.
1240# 1977#
1241# Example: build javadocs by calling 'javadoc' target 1978# Example: build javadocs by calling 'javadoc' target
1242# eant $(use_doc) 1979# eant $(use_doc)
1243# Example: build javadocs by calling 'apidoc' target 1980# Example: build javadocs by calling 'apidoc' target
1248# ------------------------------------------------------------------------------ 1985# ------------------------------------------------------------------------------
1249use_doc() { 1986use_doc() {
1250 use doc && echo ${@:-javadoc} 1987 use doc && echo ${@:-javadoc}
1251} 1988}
1252 1989
1990
1253# ------------------------------------------------------------------------------ 1991# ------------------------------------------------------------------------------
1254# @section-end build 1992# @section-end build
1255# ------------------------------------------------------------------------------ 1993# ------------------------------------------------------------------------------
1256 1994
1257# ------------------------------------------------------------------------------ 1995# ------------------------------------------------------------------------------
1258# @section-begin internal 1996# @section-begin internal
1259# @section-summary Internal functions 1997# @section-summary Internal functions
1260# 1998#
1261# Do __NOT__ use any of these from an ebuild! These are only to be used from 1999# Do __NOT__ use any of these from an ebuild! These are only to be used from
1262# within the java eclasses. 2000# within the java eclasses.
1263# ------------------------------------------------------------------------------ 2001# ------------------------------------------------------------------------------
1264 2002
1265# ----------------------------------------------------------------------------- 2003# -----------------------------------------------------------------------------
1266# @function-internal java-pkg_init 2004# @function-internal java-pkg_init
1267# 2005#
1268# The purpose of this function, as the name might imply, is to initialize the 2006# 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 2007# 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 2008# that'll muss things up. It initializes some variables, which are used
1271# internally. And most importantly, it'll switch the VM if necessary. 2009# internally. And most importantly, it'll switch the VM if necessary.
1272# 2010#
1273# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will 2011# 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. 2012# call it during each of the phases of the merge process.
1275# 2013#
1276# ----------------------------------------------------------------------------- 2014# -----------------------------------------------------------------------------
1277java-pkg_init() { 2015java-pkg_init() {
2016 debug-print-function ${FUNCNAME} $*
1278 unset JAVAC 2017 unset JAVAC
1279 unset JAVA_HOME 2018 unset JAVA_HOME
2019
2020 java-config --help >/dev/null || {
2021 eerror ""
2022 eerror "Can't run java-config --help"
2023 eerror "Have you upgraded python recently but haven't"
2024 eerror "run python-updater yet?"
2025 die "Can't run java-config --help"
2026 }
2027
2028 # People do all kinds of weird things.
2029 # http://forums.gentoo.org/viewtopic-p-3943166.html
2030 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
2031 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
2032 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
2033 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
2034 ewarn "sun-jdk vms and and as such break configure scripts that"
2035 ewarn "use it (for example app-office/openoffice) so we filter it out."
2036 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
2037 ewarn "make.conf for example) to silence this warning or"
2038 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
2039 fi
2040
2041 if [[ -z ${accept} ]]; then
2042 # export _JAVA_OPTIONS= doesn't work because it will show up in java
2043 # -version output
2044 unset _JAVA_OPTIONS
2045 # phase hooks make this run many times without this
2046 I_WANT_GLOBAL_JAVA_OPTIONS="true"
2047 fi
2048
2049 if java-pkg_func-exists ant_src_unpack; then
2050 java-pkg_announce-qa-violation "Using old ant_src_unpack. Should be src_unpack"
2051 fi
2052
1280 java-pkg_init_paths_ 2053 java-pkg_init_paths_
1281 java-pkg_switch-vm 2054 java-pkg_switch-vm
1282 PATH=${JAVA_HOME}/bin:${PATH} 2055 PATH=${JAVA_HOME}/bin:${PATH}
1283 2056
1284 # TODO we will probably want to set JAVAC and JAVACFLAGS 2057 # TODO we will probably want to set JAVAC and JAVACFLAGS
1285 2058
1286 # Do some QA checks 2059 # Do some QA checks
1287 java-pkg_check-jikes 2060 java-pkg_check-jikes
1288 2061
2062 # Can't use unset here because Portage does not save the unset
2063 # see https://bugs.gentoo.org/show_bug.cgi?id=189417#c11
2064
1289 # When users have crazy classpaths some packages can fail to compile. 2065 # When users have crazy classpaths some packages can fail to compile.
1290 # and everything should work with empty CLASSPATH. 2066 # and everything should work with empty CLASSPATH.
1291 # This also helps prevent unexpected dependencies on random things 2067 # This also helps prevent unexpected dependencies on random things
1292 # from the CLASSPATH. 2068 # from the CLASSPATH.
1293 unset CLASSPATH 2069 export CLASSPATH=
2070
2071 # Unset external ANT_ stuff
2072 export ANT_TASKS=
2073 export ANT_OPTS=
2074 export ANT_RESPECT_JAVA_HOME=
1294} 2075}
1295 2076
1296# ------------------------------------------------------------------------------ 2077# ------------------------------------------------------------------------------
1297# @function-internal java-pkg-init-compiler_ 2078# @function-internal java-pkg-init-compiler_
1298# 2079#
1299# This function attempts to figure out what compiler should be used. It does 2080# 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 2081# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
1301# COMPILERS variable defined there. 2082# COMPILERS variable defined there.
1302# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER 2083# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
1303# 2084#
1304# It will go through the list of compilers, and verify that it supports the 2085# 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 2086# 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 2087# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
1307# isn't done. 2088# isn't done.
1308# 2089#
1330 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 2111 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1331 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})" 2112 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
1332 else 2113 else
1333 compilers=${JAVA_PKG_FORCE_COMPILER} 2114 compilers=${JAVA_PKG_FORCE_COMPILER}
1334 fi 2115 fi
1335 2116
1336 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}" 2117 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
1337 2118
1338 # Figure out if we should announce what compiler we're using 2119 # Figure out if we should announce what compiler we're using
1339 local compiler 2120 local compiler
1340 for compiler in ${compilers}; do 2121 for compiler in ${compilers}; do
1343 if [[ ${compiler} = "javac" ]]; then 2124 if [[ ${compiler} = "javac" ]]; then
1344 debug-print "Found javac... breaking" 2125 debug-print "Found javac... breaking"
1345 export GENTOO_COMPILER="javac" 2126 export GENTOO_COMPILER="javac"
1346 break 2127 break
1347 fi 2128 fi
1348 2129
1349 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then 2130 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
1350 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 2131 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1351 einfo "Filtering ${compiler}" 2132 einfo "Filtering ${compiler}"
1352 continue 2133 continue
1353 fi 2134 fi
1354 fi 2135 fi
1355 2136
1356 # for non-javac, we need to make sure it supports the right target and 2137 # for non-javac, we need to make sure it supports the right target and
1357 # source 2138 # source
1358 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 2139 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1359 if [[ -f ${compiler_env} ]]; then 2140 if [[ -f ${compiler_env} ]]; then
1360 local desired_target="$(java-pkg_get-target)" 2141 local desired_target="$(java-pkg_get-target)"
1389 done 2170 done
1390 2171
1391 # If it hasn't been defined already, default to javac 2172 # If it hasn't been defined already, default to javac
1392 if [[ -z ${GENTOO_COMPILER} ]]; then 2173 if [[ -z ${GENTOO_COMPILER} ]]; then
1393 if [[ -n ${compilers} ]]; then 2174 if [[ -n ${compilers} ]]; then
1394 einfo "No suitable compiler found: defaulting javac for compilation" 2175 einfo "No suitable compiler found: defaulting to JDK default for compilation"
1395 else 2176 else
1396 # probably don't need to notify users about the default. 2177 # probably don't need to notify users about the default.
1397 :;#einfo "Defaulting to javac for compilation" 2178 :;#einfo "Defaulting to javac for compilation"
1398 fi 2179 fi
2180 if java-config -g GENTOO_COMPILER 2> /dev/null; then
2181 export GENTOO_COMPILER=$(java-config -g GENTOO_COMPILER)
2182 else
1399 export GENTOO_COMPILER=javac 2183 export GENTOO_COMPILER=javac
2184 fi
1400 else 2185 else
1401 einfo "Using ${GENTOO_COMPILER} for compilation" 2186 einfo "Using ${GENTOO_COMPILER} for compilation"
1402 fi 2187 fi
1403 2188
1404} 2189}
1420 fi 2205 fi
1421 2206
1422 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}" 2207 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}"
1423 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/" 2208 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/"
1424 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env" 2209 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env"
2210 JAVA_PKG_VIRTUALS_PATH="${DESTTREE}/share/java-config-2/virtuals"
2211 JAVA_PKG_VIRTUAL_PROVIDER="${D}/${JAVA_PKG_VIRTUALS_PATH}/${JAVA_PKG_NAME}"
1425 2212
1426 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib" 2213 [[ -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}" 2214 [[ -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" 2215 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps"
1429 2216
1442# Writes the package.env out to disk. 2229# Writes the package.env out to disk.
1443# 2230#
1444# ------------------------------------------------------------------------------ 2231# ------------------------------------------------------------------------------
1445# TODO change to do-write, to match everything else 2232# TODO change to do-write, to match everything else
1446java-pkg_do_write_() { 2233java-pkg_do_write_() {
2234 debug-print-function ${FUNCNAME} $*
2235 java-pkg_init_paths_
1447 # Create directory for package.env 2236 # Create directory for package.env
1448 dodir "${JAVA_PKG_SHAREPATH}" 2237 dodir "${JAVA_PKG_SHAREPATH}"
1449 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 2238 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f \
2239 "${JAVA_PKG_DEPEND_FILE}" || -f \
2240 "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]]; then
1450 # Create package.env 2241 # Create package.env
1451 ( 2242 (
1452 echo "DESCRIPTION=\"${DESCRIPTION}\"" 2243 echo "DESCRIPTION=\"${DESCRIPTION}\""
1453 echo "GENERATION=\"2\"" 2244 echo "GENERATION=\"2\""
2245 echo "SLOT=\"${SLOT}\""
1454 2246
1455 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\"" 2247 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
1456 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 2248 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1457 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 2249 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1458 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 2250 [[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
2251 && echo "DEPEND=\"$(cat "${JAVA_PKG_DEPEND_FILE}" | uniq | tr '\n' ':')\""
2252 [[ -f "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]] \
2253 && 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 ! 2254 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1460 ) > "${JAVA_PKG_ENV}" 2255 ) > "${JAVA_PKG_ENV}"
1461 2256
1462 # register target/source 2257 # register target/source
1463 local target="$(java-pkg_get-target)" 2258 local target="$(java-pkg_get-target)"
1464 local source="$(java-pkg_get-source)" 2259 local source="$(java-pkg_get-source)"
1465 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}" 2260 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
1466 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}" 2261 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
1474 2269
1475 2270
1476 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}" 2271 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
1477 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}" 2272 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
1478 2273
2274 # extra env variables
2275 if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
2276 cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}" || die
2277 # nested echo to remove leading/trailing spaces
2278 echo "ENV_VARS=\"$(echo ${JAVA_PKG_EXTRA_ENV_VARS})\"" \
2279 >> "${JAVA_PKG_ENV}" || die
2280 fi
2281
1479 # Strip unnecessary leading and trailing colons 2282 # Strip unnecessary leading and trailing colons
1480 # TODO try to cleanup if possible 2283 # TODO try to cleanup if possible
1481 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 2284 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
2285 else
2286 debug-print "JAVA_PKG_CLASSPATH, JAVA_PKG_LIBRARY, JAVA_PKG_DEPEND_FILE"
2287 debug-print "or JAVA_PKG_OPTIONAL_DEPEND_FILE not defined so can't"
2288 debug-print "write package.env."
1482 fi 2289 fi
1483} 2290}
1484
1485 2291
1486# ------------------------------------------------------------------------------ 2292# ------------------------------------------------------------------------------
1487# @internal-function java-pkg_record-jar_ 2293# @internal-function java-pkg_record-jar_
1488# 2294#
1489# Record a dependency to the package.env 2295# Record an (optional) dependency to the package.env
1490# 2296# @param --optional - record dependency as optional
2297# @param $1 - package to record
2298# @param $2 - (optional) jar of package to record
1491# ------------------------------------------------------------------------------ 2299# ------------------------------------------------------------------------------
1492JAVA_PKG_DEPEND="${T}/java-pkg-depend" 2300JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2301JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
1493 2302
1494java-pkg_record-jar_() { 2303java-pkg_record-jar_() {
1495 debug-print-function ${FUNCNAME} $* 2304 debug-print-function ${FUNCNAME} $*
2305
2306 local depend_file="${JAVA_PKG_DEPEND_FILE}"
2307 if [[ "${1}" == "--optional" ]]; then
2308 depend_file="${JAVA_PKG_OPTIONAL_DEPEND_FILE}"
2309 shift
2310 fi
1496 2311
1497 local pkg=${1} jar=${2} append 2312 local pkg=${1} jar=${2} append
1498 if [[ -z "${jar}" ]]; then 2313 if [[ -z "${jar}" ]]; then
1499 append="${pkg}" 2314 append="${pkg}"
1500 else 2315 else
1501 append="$(basename ${jar})@${pkg}" 2316 append="$(basename ${jar})@${pkg}"
1502 fi 2317 fi
1503 2318
1504 echo ${append} >> ${JAVA_PKG_DEPEND} 2319 echo "${append}" >> "${depend_file}"
1505} 2320}
1506 2321
1507# ------------------------------------------------------------------------------ 2322# ------------------------------------------------------------------------------
1508# @internal-function java-pkg_append_ 2323# @internal-function java-pkg_append_
1509# 2324#
1533 fi 2348 fi
1534} 2349}
1535 2350
1536# ------------------------------------------------------------------------------ 2351# ------------------------------------------------------------------------------
1537# @internal-function java-pkg_expand_dir_ 2352# @internal-function java-pkg_expand_dir_
1538# 2353#
1539# Gets the full path of the file/directory's parent. 2354# Gets the full path of the file/directory's parent.
1540# @param $1 - file/directory to find parent directory for 2355# @param $1 - file/directory to find parent directory for
1541# @return - path to $1's parent directory 2356# @return - path to $1's parent directory
1542# ------------------------------------------------------------------------------ 2357# ------------------------------------------------------------------------------
1543java-pkg_expand_dir_() { 2358java-pkg_expand_dir_() {
1553# 2368#
1554# @return 0 - function is declared 2369# @return 0 - function is declared
1555# @return 1 - function is undeclared 2370# @return 1 - function is undeclared
1556# ------------------------------------------------------------------------------ 2371# ------------------------------------------------------------------------------
1557java-pkg_func-exists() { 2372java-pkg_func-exists() {
1558 if [[ -n "$(declare -f ${1})" ]]; then 2373 declare -F ${1} > /dev/null
1559 return 0
1560 else
1561 return 1
1562 fi
1563} 2374}
1564 2375
1565# ------------------------------------------------------------------------------ 2376# ------------------------------------------------------------------------------
1566# @internal-function java-pkg_setup-vm 2377# @internal-function java-pkg_setup-vm
1567# 2378#
1569# 2380#
1570# ------------------------------------------------------------------------------ 2381# ------------------------------------------------------------------------------
1571java-pkg_setup-vm() { 2382java-pkg_setup-vm() {
1572 debug-print-function ${FUNCNAME} $* 2383 debug-print-function ${FUNCNAME} $*
1573 2384
2385 export LANG="C" LC_ALL="C"
2386
1574 local vendor="$(java-pkg_get-vm-vendor)" 2387 local vendor="$(java-pkg_get-vm-vendor)"
1575 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge 1 5; then 2388 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1576 addpredict "/dev/random" 2389 addpredict "/dev/random"
1577 elif [[ "${vendor}" == "ibm" ]]; then 2390 elif [[ "${vendor}" == "ibm" ]]; then
1578 addpredict "/proc/self/maps" 2391 addpredict "/proc/self/maps"
1579 addpredict "/proc/cpuinfo" 2392 addpredict "/proc/cpuinfo"
1580 export LANG="C" LC_ALL="C"
1581 elif [[ "${vendor}" == "jrockit" ]]; then 2393 elif [[ "${vendor}" == "jrockit" ]]; then
1582 addpredict "/proc/cpuinfo" 2394 addpredict "/proc/cpuinfo"
1583 fi 2395 fi
1584} 2396}
1585 2397
1629# @return - The version of the current VM 2441# @return - The version of the current VM
1630# ------------------------------------------------------------------------------ 2442# ------------------------------------------------------------------------------
1631java-pkg_get-vm-version() { 2443java-pkg_get-vm-version() {
1632 debug-print-function ${FUNCNAME} $* 2444 debug-print-function ${FUNCNAME} $*
1633 2445
1634 java-pkg_get-current-vm | sed -e "s/.*-\([0-9.]\+\).*/\1/" 2446 java-config -g PROVIDES_VERSION
1635} 2447}
1636 2448
1637# ------------------------------------------------------------------------------ 2449# ------------------------------------------------------------------------------
1638# @internal-function java-pkg_switch-vm 2450# @internal-function java-pkg_switch-vm
1639# 2451#
1640# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 2452# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1641# verify that the current VM is sufficient. 2453# verify that the current VM is sufficient.
1642# Setup the environment for the VM being used. 2454# Setup the environment for the VM being used.
1643# ------------------------------------------------------------------------------ 2455# ------------------------------------------------------------------------------
1644java-pkg_switch-vm() { 2456java-pkg_switch-vm() {
2457 debug-print-function ${FUNCNAME} $*
2458
1645 if java-pkg_needs-vm; then 2459 if java-pkg_needs-vm; then
1646 # Use the VM specified by JAVA_PKG_FORCE_VM 2460 # Use the VM specified by JAVA_PKG_FORCE_VM
1647 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then 2461 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1648 # If you're forcing the VM, I hope you know what your doing... 2462 # If you're forcing the VM, I hope you know what your doing...
2463 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1649 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 2464 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1650 # if we're allowed to switch the vm... 2465 # if we're allowed to switch the vm...
1651 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 2466 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}" 2467 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
1653 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}}")" 2468 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
2469 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
2470 eerror "Unable to determine VM for building from dependencies:"
2471 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
2472 die "Failed to determine VM for building."
1655 else 2473 else
1656 export GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2474 export GENTOO_VM
1657 fi 2475 fi
1658 # otherwise just make sure the current VM is sufficient 2476 # otherwise just make sure the current VM is sufficient
1659 else 2477 else
1660 java-pkg_ensure-vm-version-sufficient 2478 java-pkg_ensure-vm-version-sufficient
1661 fi 2479 fi
1662 debug-print "Using: $(java-config -f)" 2480 debug-print "Using: $(java-config -f)"
1663 2481
1664 java-pkg_setup-vm 2482 java-pkg_setup-vm
1665 2483
1666 export JAVA=$(java-config -java) 2484 export JAVA=$(java-config --java)
1667 export JAVAC=$(java-config -javac) 2485 export JAVAC=$(java-config --javac)
1668 export JAVACFLAGS="$(java-pkg_javac-args)" 2486 JAVACFLAGS="$(java-pkg_javac-args)"
2487 if [[ ${?} != 0 ]]; then
2488 eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
2489 die "java-pkg_javac-args failed"
2490 fi
1669 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 2491 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
2492 export JAVACFLAGS
1670 2493
1671 export JAVA_HOME="$(java-config -g JAVA_HOME)" 2494 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1672 export JDK_HOME=${JAVA_HOME} 2495 export JDK_HOME=${JAVA_HOME}
1673 2496
1674 #TODO If you know a better solution let us know. 2497 #TODO If you know a better solution let us know.
1675 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 2498 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1676 2499
1677 local tann="${T}/announced-vm" 2500 local tann="${T}/announced-vm"
2501 # With the hooks we should only get here once from pkg_setup but better safe than sorry
2502 # if people have for example modified eclasses some where
1678 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 2503 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)" 2504 einfo "Using: $(java-config -f)"
1684 [[ ! -f "${tann}" ]] && touch "${tann}" 2505 [[ ! -f "${tann}" ]] && touch "${tann}"
1685 fi
1686 fi 2506 fi
1687 2507
1688 else 2508 else
1689 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!" 2509 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!"
1690 fi 2510 fi
1706 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2 2526 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2
1707 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2 2527 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2
1708 echo "and of course, the output of emerge --info" >&2 2528 echo "and of course, the output of emerge --info" >&2
1709} 2529}
1710 2530
2531
2532# TODO document
2533# List jars in the source directory, ${S}
2534java-pkg_jar-list() {
2535 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
2536 einfo "Linked Jars"
2537 find "${S}" -type l -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2538 einfo "Jars"
2539 find "${S}" -type f -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2540 einfo "Classes"
2541 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2542 fi
2543}
2544
2545# ------------------------------------------------------------------------------
2546# @internal-function java-pkg_verify-classes
2547#
2548# Verify that the classes were compiled for the right source / target. Dies if
2549# not.
2550# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2551# ------------------------------------------------------------------------------
2552java-pkg_verify-classes() {
2553 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
2554
2555 local version_verify="/usr/bin/class-version-verify.py"
2556
2557 if [[ ! -x "${version_verify}" ]]; then
2558 version_verify="/usr/$(get_libdir)/javatoolkit/bin/class-version-verify.py"
2559 fi
2560
2561 if [[ ! -x "${version_verify}" ]]; then
2562 ewarn "Unable to perform class version checks as"
2563 ewarn "class-version-verify.py is unavailable"
2564 ewarn "Please install dev-java/javatoolkit."
2565 return
2566 fi
2567
2568 local target=$(java-pkg_get-target)
2569 local result
2570 local log="${T}/class-version-verify.log"
2571 if [[ -n "${1}" ]]; then
2572 ${version_verify} -v -t ${target} "${1}" > "${log}"
2573 result=$?
2574 else
2575 ebegin "Verifying java class versions (target: ${target})"
2576 ${version_verify} -v -t ${target} -r "${D}" > "${log}"
2577 result=$?
2578 eend ${result}
2579 fi
2580 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2581 if [[ ${result} != 0 ]]; then
2582 eerror "Incorrect bytecode version found"
2583 [[ -n "${1}" ]] && eerror "in file: ${1}"
2584 eerror "See ${log} for more details."
2585 die "Incorrect bytecode found"
2586 fi
2587}
2588
2589# ----------------------------------------------------------------------------
2590# @internal-function java-pkg_ensure-dep
2591# Check that a package being used in jarfrom, getjars and getjar is contained
2592# within DEPEND or RDEPEND.
2593# @param $1 - empty - check both vars; "runtime" or "build" - check only
2594# RDEPEND, resp. DEPEND
2595# @param $2 - Package name and slot.
2596
2597java-pkg_ensure-dep() {
2598 debug-print-function ${FUNCNAME} $*
2599
2600 local limit_to="${1}"
2601 local target_pkg="${2}"
2602 local dev_error=""
2603
2604 local stripped_pkg=$(echo "${target_pkg}" | sed \
2605 's/-[0-9]*\(\.[0-9]\)*$//')
2606
2607 debug-print "Matching against: ${stripped_pkg}"
2608
2609 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2610 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2611 dev_error="${dev_error} declared in DEPEND."
2612 if is-java-strict; then
2613 eerror "${dev_error}"
2614 die "${dev_error}"
2615 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2616 eerror "${dev_error}"
2617 elog "Because you have this package installed the package will"
2618 elog "build without problems, but please report this to"
2619 elog "http://bugs.gentoo.org"
2620 fi
2621 fi
2622
2623 if [[ ${limit_to} != build ]]; then
2624 if [[ ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2625 if [[ ! ( ${PDEPEND} =~ "${stripped_pkg}" ) ]]; then
2626 dev_error="The ebuild is attempting to use ${target_pkg},"
2627 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND"
2628 dev_error="${dev_error} or PDEPEND."
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 "The package will build without problems, but may fail to run"
2635 elog "if you don't have ${target_pkg} installed, so please report"
2636 elog "this to http://bugs.gentoo.org"
2637 fi
2638 fi
2639 fi
2640 fi
2641}
2642
1711# ------------------------------------------------------------------------------ 2643# ------------------------------------------------------------------------------
1712# @section-end internal 2644# @section-end internal
1713# ------------------------------------------------------------------------------ 2645# ------------------------------------------------------------------------------
1714 2646
1715java-pkg_check-phase() { 2647java-pkg_check-phase() {
1716 local phase=${1} 2648 local phase=${1}
1717 local funcname=${2} 2649 local funcname=${FUNCNAME[1]}
1718 # TODO add check for java-stricter
1719 if [[ ${EBUILD_PHASE} != ${phase} ]]; then 2650 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
1720 java-pkg_announce-qa-violation \
1721 "${funcname} used outside of src_${phase}" 2651 local msg="${funcname} used outside of src_${phase}"
2652 java-pkg_announce-qa-violation "${msg}"
1722 fi 2653 fi
1723} 2654}
1724 2655
1725java-pkg_check-versioned-jar() { 2656java-pkg_check-versioned-jar() {
1726 local jar=${1} 2657 local jar=${1}
1735 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2666 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1736 fi 2667 fi
1737} 2668}
1738 2669
1739java-pkg_announce-qa-violation() { 2670java-pkg_announce-qa-violation() {
1740 if hasq java-strict ${FEATURES}; then 2671 local nodie
2672 if [[ ${1} == "--nodie" ]]; then
2673 nodie="true"
2674 shift
2675 fi
1741 echo "Java QA Notice: $@" >&2 2676 echo "Java QA Notice: $@" >&2
1742 increment-qa-violations 2677 increment-qa-violations
1743 fi 2678 [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
1744} 2679}
1745 2680
1746increment-qa-violations() { 2681increment-qa-violations() {
1747 let "JAVA_PKG_QA_VIOLATIONS+=1" 2682 let "JAVA_PKG_QA_VIOLATIONS+=1"
1748 export JAVA_PKG_QA_VIOLATIONS 2683 export JAVA_PKG_QA_VIOLATIONS
1749} 2684}
1750 2685
2686is-java-strict() {
2687 [[ -n ${JAVA_PKG_STRICT} ]]
2688 return $?
2689}
2690
2691
1751# ------------------------------------------------------------------------------ 2692# ------------------------------------------------------------------------------
1752# @eclass-end 2693# @eclass-end
1753# ------------------------------------------------------------------------------ 2694# ------------------------------------------------------------------------------

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

  ViewVC Help
Powered by ViewVC 1.1.20