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

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

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

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

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

  ViewVC Help
Powered by ViewVC 1.1.20