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

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

  ViewVC Help
Powered by ViewVC 1.1.20