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

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.116

  ViewVC Help
Powered by ViewVC 1.1.20