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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.41 - (show annotations) (download)
Fri Jan 12 16:12:15 2007 UTC (7 years, 11 months ago) by betelgeuse
Branch: MAIN
Changes since 1.40: +13 -1 lines
Moving EANT_GENTOO_CLASSPATH handling to eant implementation so that it can be used automatically in both src_compile and src_test.

1 # Base eclass for Java packages
2 #
3 # Copyright (c) 2004-2005, Thomas Matthijs <axxo@gentoo.org>
4 # Copyright (c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
5 # Copyright (c) 2004-2005, Gentoo Foundation
6 #
7 # Licensed under the GNU General Public License, v2
8 #
9 # $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.40 2007/01/10 09:52:51 betelgeuse Exp $
10
11
12 # -----------------------------------------------------------------------------
13 # @eclass-begin
14 # @eclass-shortdesc Java Utility eclass
15 # @eclass-maintainer java@gentoo.org
16 #
17 # This eclass provides functionality which is used by
18 # java-pkg.eclass and java-pkg-opt.eclass as well as from ebuilds.
19 #
20 # @warning
21 # You probably don't want to inherit this directly from an ebuild. Instead,
22 # you should inherit java-ant for Ant-based Java packages, java-pkg for other
23 # Java packages, or java-pkg-opt for packages that have optional Java support.
24 #
25 # -----------------------------------------------------------------------------
26
27 inherit eutils versionator multilib
28
29 IUSE="elibc_FreeBSD"
30
31 # -----------------------------------------------------------------------------
32 # @section-begin variables
33 # @section-title Variables
34 #
35 # Summary of variables which control the behavior of building Java packges.
36 # -----------------------------------------------------------------------------
37
38 # Make sure we use java-config-2
39 export WANT_JAVA_CONFIG="2"
40
41 # TODO document
42 JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1"
43
44 # -----------------------------------------------------------------------------
45 # @variable-internal JAVA_PKG_E_DEPEND
46 #
47 # This is a convience variable to be used from the other java eclasses. This is
48 # the version of java-config we want to use. We also need a recent version
49 # portage, that includes phase hooks.
50 # -----------------------------------------------------------------------------
51 JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 ${JAVA_PKG_PORTAGE_DEP}"
52
53 # -----------------------------------------------------------------------------
54 # @variable-external JAVA_PKG_ALLOW_VM_CHANGE
55 # @variable-default yes
56 #
57 # Allow this eclass to change the active VM?
58 # If your system VM isn't sufficient for the package, the build will fail.
59 # @note This is useful for testing specific VMs.
60 # -----------------------------------------------------------------------------
61 JAVA_PKG_ALLOW_VM_CHANGE=${JAVA_PKG_ALLOW_VM_CHANGE:="yes"}
62
63 # -----------------------------------------------------------------------------
64 # @variable-external JAVA_PKG_FORCE_VM
65 #
66 # Explicitly set a particular VM to use. If its not valid, it'll fall back to
67 # whatever /etc/java-config-2/build/jdk.conf would elect to use.
68 #
69 # Should only be used for testing and debugging.
70 #
71 # @example Use sun-jdk-1.5 to emerge foo
72 # JAVA_PKG_FORCE_VM=sun-jdk-1.5 emerge foo
73 #
74 # -----------------------------------------------------------------------------
75
76 # -----------------------------------------------------------------------------
77 # @variable-external JAVA_PKG_WANT_SOURCE
78 #
79 # Specify a specific VM version to compile for to use for -source.
80 # Normally this is determined from DEPEND.
81 # See java-pkg_get-source function below.
82 #
83 # Should only be used for testing and debugging.
84 #
85 # @seealso java-pkg_get-source
86 #
87 # @example Use 1.4 source to emerge baz
88 # JAVA_PKG_WANT_SOURCE=1.4 emerge baz
89 # -----------------------------------------------------------------------------
90
91 # -----------------------------------------------------------------------------
92 # @variable-external JAVA_PKG_WANT_TARGET
93 #
94 # Same as JAVA_PKG_WANT_SOURCE above but for -target.
95 # See java-pkg_get-target function below.
96 #
97 # Should only be used for testing and debugging.
98 #
99 # @seealso java-pkg_get-target
100 #
101 # @example emerge bar to be compatible with 1.3
102 # JAVA_PKG_WANT_TARGET=1.3 emerge bar
103 # -----------------------------------------------------------------------------
104
105 # -----------------------------------------------------------------------------
106 # @variable-internal JAVA_PKG_COMPILER_DIR
107 # @default /usr/share/java-config-2/compiler
108 #
109 # Directory where compiler settings are saved, without trailing slash.
110 # Probably shouldn't touch this variable.
111 # -----------------------------------------------------------------------------
112 JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"}
113
114
115 # -----------------------------------------------------------------------------
116 # @variable-internal JAVA_PKG_COMPILERS_CONF
117 # @variable-default /etc/java-config-2/build/compilers.conf
118 #
119 # Path to file containing information about which compiler to use.
120 # Can be overloaded, but it should be overloaded for testing.
121 # -----------------------------------------------------------------------------
122 JAVA_PKG_COMPILERS_CONF=${JAVA_PKG_COMPILERS_CONF:="/etc/java-config-2/build/compilers.conf"}
123
124 # -----------------------------------------------------------------------------
125 # @variable-external JAVA_PKG_FORCE_COMPILER
126 #
127 # Explicitly set a list of compilers to use. This is normally read from
128 # JAVA_PKG_COMPILERS_CONF.
129 #
130 # @note This should only be used internally or for testing.
131 # @example Use jikes and javac, in that order
132 # JAVA_PKG_FORCE_COMPILER="jikes javac"
133 # -----------------------------------------------------------------------------
134
135 # TODO document me
136 JAVA_PKG_QA_VIOLATIONS=0
137
138 # -----------------------------------------------------------------------------
139 # @section-end variables
140 # -----------------------------------------------------------------------------
141
142
143 # -----------------------------------------------------------------------------
144 # @section-begin install
145 # @section-summary Install functions
146 #
147 # These are used to install Java-related things, such as jars, Javadocs, JNI
148 # libraries, etc.
149 # -----------------------------------------------------------------------------
150
151
152 # -----------------------------------------------------------------------------
153 # @ebuild-function java-pkg_dojar
154 #
155 # Installs any number of jars.
156 # Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default.
157 # You can use java-pkg_jarinto to change this path.
158 # You should never install a jar with a package version in the filename.
159 # Instead, use java-pkg_newjar defined below.
160 #
161 # @example
162 # java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar
163 #
164 # @param $* - list of jars to install
165 # ------------------------------------------------------------------------------
166 java-pkg_dojar() {
167 debug-print-function ${FUNCNAME} $*
168
169 [[ ${#} -lt 1 ]] && die "At least one argument needed"
170
171 java-pkg_check-phase install
172 java-pkg_init_paths_
173
174 # Create JARDEST if it doesn't exist
175 dodir ${JAVA_PKG_JARDEST}
176
177 local jar
178 # for each jar
179 for jar in ${@}; do
180 local jar_basename=$(basename "${jar}")
181
182 java-pkg_check-versioned-jar ${jar_basename}
183
184 # check if it exists
185 if [[ -e "${jar}" ]] ; then
186 # install it into JARDEST if it's a non-symlink
187 if [[ ! -L "${jar}" ]] ; then
188 INSDESTTREE="${JAVA_PKG_JARDEST}" \
189 doins "${jar}" || die "failed to install ${jar}"
190 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
191 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}"
192 # make a symlink to the original jar if it's symlink
193 else
194 # TODO use dosym, once we find something that could use it
195 # -nichoj
196 ln -s "$(readlink "${jar}")" "${D}${JAVA_PKG_JARDEST}/${jar_basename}"
197 debug-print "${jar} is a symlink, linking accordingly"
198 fi
199 else
200 die "${jar} does not exist"
201 fi
202 done
203
204 java-pkg_do_write_
205 }
206
207
208 # ------------------------------------------------------------------------------
209 # @internal-function depend-java-query
210 #
211 # Wrapper for the depend-java-query binary to enable passing USE in env.
212 # Using env variables keeps this eclass working with java-config versions that
213 # do not handle use flags.
214 # ------------------------------------------------------------------------------
215
216 depend-java-query() {
217 USE="${USE}" $(which depend-java-query) "${@}"
218 }
219
220 # ------------------------------------------------------------------------------
221 # @ebuild-function java-pkg_regjar
222 #
223 # Records an already installed jar in the package.env
224 # This would mostly be used if the package has make or a custom script to
225 # install things.
226 #
227 # Example:
228 # java-pkg_regjar ${D}/opt/foo/lib/foo.jar
229 #
230 # WARNING:
231 # if you want to use shell expansion, you have to use ${D}/... as the for in
232 # this function will not be able to expand the path, here's an example:
233 #
234 # java-pkg_regjar /opt/my-java/lib/*.jar
235 #
236 # will not work, because:
237 # * the `for jar in "$@"` can't expand the path to jar file names, as they
238 # don't exist yet
239 # * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar'
240 # doesn't exist
241 #
242 # you have to use it as:
243 #
244 # java-pkg_regjar ${D}/opt/my-java/lib/*.jar
245 #
246 # @param $@ - jars to record
247 # ------------------------------------------------------------------------------
248 # TODO should we be making sure the jar is present on ${D} or wherever?
249 java-pkg_regjar() {
250 debug-print-function ${FUNCNAME} $*
251
252 java-pkg_check-phase install
253
254 [[ ${#} -lt 1 ]] && die "at least one argument needed"
255
256 java-pkg_init_paths_
257
258 local jar jar_dir jar_file
259 for jar in ${@}; do
260 # TODO use java-pkg_check-versioned-jar
261 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
262 [[ -d "${jar}" || -d "${D}${jar}" ]] \
263 && die "Called ${FUNCNAME} on a directory $*"
264 # nelchael: we should strip ${D} in this case too, here's why:
265 # imagine such call:
266 # java-pkg_regjar ${D}/opt/java/*.jar
267 # such call will fall into this case (-e ${jar}) and will
268 # record paths with ${D} in package.env
269 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
270 else
271 die "${jar} does not exist"
272 fi
273 done
274
275 java-pkg_do_write_
276 }
277
278 # ------------------------------------------------------------------------------
279 # @ebuild-function java-pkg_newjar
280 #
281 # Installs a jar with a new name
282 #
283 # @example: install a versioned jar without the version
284 # java-pkg_newjar dist/${P}.jar ${PN}.jar
285 #
286 # @param $1 - jar to install
287 # @param $2 - new name for jar - defaults to ${PN}.jar if not specified
288 # ------------------------------------------------------------------------------
289 java-pkg_newjar() {
290 debug-print-function ${FUNCNAME} $*
291
292 local original_jar="${1}"
293 local new_jar="${2:-${PN}.jar}"
294 local new_jar_dest="${T}/${new_jar}"
295
296 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
297 [[ ! -f ${original_jar} ]] && die "${original_jar} does not exist!"
298
299 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
300 cp "${original_jar}" "${new_jar_dest}" \
301 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
302 java-pkg_dojar "${new_jar_dest}"
303 }
304
305 # ------------------------------------------------------------------------------
306 # @ebuild-function java-pkg_addcp
307 #
308 # Add something to the package's classpath. For jars, you should use dojar,
309 # newjar, or regjar. This is typically used to add directories to the classpath.
310 #
311 # TODO add example
312 # @param $@ - value to append to JAVA_PKG_CLASSPATH
313 # ------------------------------------------------------------------------------
314 java-pkg_addcp() {
315 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
316 java-pkg_do_write_
317 }
318
319 # ------------------------------------------------------------------------------
320 # @ebuild-function java-pkg_doso
321 #
322 # Installs any number of JNI libraries
323 # They will be installed into /usr/lib by default, but java-pkg_sointo
324 # can be used change this path
325 #
326 # Example:
327 # java-pkg_doso *.so
328 #
329 # @param $@ - JNI libraries to install
330 # ------------------------------------------------------------------------------
331 java-pkg_doso() {
332 debug-print-function ${FUNCNAME} $*
333
334 [[ ${#} -lt 1 ]] && "At least one argument required for ${FUNCNAME}"
335 java-pkg_check-phase install
336
337 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
338
339 java-pkg_init_paths_
340
341 local lib
342 # for each lib
343 for lib in "$@" ; do
344 # if the lib exists...
345 if [[ -e "${lib}" ]] ; then
346 # install if it isn't a symlink
347 if [[ ! -L "${lib}" ]] ; then
348 INSDESTTREE="${JAVA_PKG_LIBDEST}" \
349 INSOPTIONS="${LIBOPTIONS}" \
350 doins "${lib}" || "failed to install ${lib}"
351 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
352 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
353 # otherwise make a symlink to the symlink's origin
354 else
355 # TODO use dosym
356 ln -s "$(readlink "${lib}")" "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")"
357 debug-print "${lib} is a symlink, linking accordanly"
358 fi
359 # otherwise die
360 else
361 die "${lib} does not exist"
362 fi
363 done
364
365 java-pkg_do_write_
366 }
367
368 # ------------------------------------------------------------------------------
369 # @ebuild-function java-pkg_regso
370 #
371 # Registers an already JNI library in package.env.
372 #
373 # Example:
374 # java-pkg_regso *.so /path/*.so
375 #
376 # @param $@ - JNI libraries to register
377 # ------------------------------------------------------------------------------
378 java-pkg_regso() {
379 debug-print-function ${FUNCNAME} $*
380
381 java-pkg_check-phase install
382
383 [[ ${#} -lt 1 ]] && "at least one argument needed"
384
385 java-pkg_init_paths_
386
387 local lib target_dir
388 for lib in "$@" ; do
389 # Check the absolute path of the lib
390 if [[ -e "${lib}" ]] ; then
391 target_dir="$(java-pkg_expand_dir_ ${lib})"
392 java-pkg_append_ JAVA_PKG_LIBRARY "/${target_dir#${D}}"
393 # Check the path of the lib relative to ${D}
394 elif [[ -e "${D}${lib}" ]]; then
395 target_dir="$(java-pkg_expand_dir_ ${D}${lib})"
396 java-pkg_append_ JAVA_PKG_LIBRARY "${target_dir}"
397 else
398 die "${lib} does not exist"
399 fi
400 done
401
402 java-pkg_do_write_
403 }
404
405 # ------------------------------------------------------------------------------
406 # @ebuild-function java-pkg_jarinto
407 #
408 # Changes the path jars are installed into
409 #
410 # @param $1 - new location to install jars into.
411 # -----------------------------------------------------------------------------
412 java-pkg_jarinto() {
413 debug-print-function ${FUNCNAME} $*
414
415 JAVA_PKG_JARDEST="${1}"
416 }
417
418 # ------------------------------------------------------------------------------
419 # @ebuild-function java-pkg_sointo
420 #
421 # Changes the path that JNI libraries are installed into.
422 #
423 # @param $1 - new location to install JNI libraries into.
424 # ------------------------------------------------------------------------------
425 java-pkg_sointo() {
426 debug-print-function ${FUNCNAME} $*
427
428 JAVA_PKG_LIBDEST="${1}"
429 }
430
431 # ------------------------------------------------------------------------------
432 # @ebuild-function java-pkg_dohtml
433 #
434 # Install Javadoc HTML documentation
435 #
436 # @example
437 # java-pkg_dohtml dist/docs/
438 #
439 # ------------------------------------------------------------------------------
440 java-pkg_dohtml() {
441 debug-print-function ${FUNCNAME} $*
442
443 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
444
445 # from /usr/lib/portage/bin/dohtml -h
446 # -f Set list of allowed extensionless file names.
447 dohtml -f package-list "$@"
448
449 # this probably shouldn't be here but it provides
450 # a reasonable way to catch # docs for all of the
451 # old ebuilds.
452 java-pkg_recordjavadoc
453 }
454
455 # ------------------------------------------------------------------------------
456 # @ebuild-function java-pkg_dojavadoc
457 #
458 # Installs javadoc documentation. This should be controlled by the doc use flag.
459 #
460 # @param $1: - The javadoc root directory.
461 #
462 # @example:
463 # java-pkg_dojavadoc docs/api
464 #
465 # ------------------------------------------------------------------------------
466 java-pkg_dojavadoc() {
467 local dir="$1"
468
469 java-pkg_check-phase install
470
471 [[ -z "${dir}" ]] && die "Must specify a directory!"
472 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!"
473
474 local dir_to_install="${dir}"
475 if [[ "$(basename "${dir}")" != "api" ]]; then
476 dir_to_install="${T}/api"
477 # TODO use doins
478 cp -r "${dir}" "${dir_to_install}" || die "cp failed"
479 fi
480
481 java-pkg_dohtml -r ${dir_to_install}
482 }
483
484 # ------------------------------------------------------------------------------
485 # @ebuild-function java-pkg_dosrc
486 #
487 # Installs a zip containing the source for a package, so it can used in
488 # from IDEs like eclipse and netbeans.
489 #
490 # Ebuild needs to DEPEND on app-arch/zip to use this.
491 #
492 # It also should be controlled by USE=source.
493 #
494 # @example:
495 # java-pkg_dosrc src/*
496 #
497 # ------------------------------------------------------------------------------
498 # TODO change so it the arguments it takes are the base directories containing
499 # source -nichoj
500 # TODO should we be able to handle multiple calls to dosrc? -nichoj
501 # TODO maybe we can take an existing zip/jar? -nichoj
502 # FIXME apparently this fails if you give it an empty directories
503 java-pkg_dosrc() {
504 debug-print-function ${FUNCNAME} $*
505
506 [ ${#} -lt 1 ] && die "At least one argument needed"
507 if ! hasq source ${IUSE}; then
508 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
509 fi
510
511 java-pkg_check-phase install
512
513 [[ ${#} -lt 1 ]] && die "At least one argument needed"
514
515 java-pkg_init_paths_
516
517 local zip_name="${PN}-src.zip"
518 local zip_path="${T}/${zip_name}"
519 local dir
520 for dir in ${@}; do
521 local dir_parent=$(dirname "${dir}")
522 local dir_name=$(basename "${dir}")
523 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
524 zip -q -r ${zip_path} ${dir_name} -i '*.java'
525 local result=$?
526 # 12 means zip has nothing to do
527 if [[ ${result} != 12 && ${result} != 0 ]]; then
528 die "failed to zip ${dir_name}"
529 fi
530 popd >/dev/null
531 done
532
533 # Install the zip
534 INSDESTTREE=${JAVA_PKG_SOURCESPATH} \
535 doins ${zip_path} || die "Failed to install source"
536
537 JAVA_SOURCES="${JAVA_PKG_SOURCESPATH}/${zip_name}"
538 java-pkg_do_write_
539 }
540
541 # ------------------------------------------------------------------------------
542 # @ebuild-function java-pkg_dolauncher
543 #
544 # Make a wrapper script to lauch/start this package
545 # If necessary, the wrapper will switch to the appropriate VM.
546 #
547 # Can be called without parameters if the package installs only one jar
548 # that has the Main-class attribute set. The wrapper will be named ${PN}.
549 #
550 # @param $1 - filename of launcher to create
551 # @param $2 - options, as follows:
552 # --main the.main.class.too.start
553 # --jar /the/jar/too/launch.jar or just <name>.jar
554 # --java_args 'Extra arguments to pass to java'
555 # --pkg_args 'Extra arguments too pass to the package'
556 # --pwd
557 # -into
558 # -pre
559 # ------------------------------------------------------------------------------
560 java-pkg_dolauncher() {
561 debug-print-function ${FUNCNAME} $*
562
563 java-pkg_check-phase install
564 java-pkg_init_paths_
565
566 if [[ ${#} = 0 ]]; then
567 local name="${PN}"
568 else
569 local name="${1}"
570 shift
571 fi
572
573 # TODO rename to launcher
574 local target="${T}/${name}"
575 local var_tmp="${T}/launcher_variables_tmp"
576 local target_dir pre
577
578 # Process the other the rest of the arguments
579 while [[ -n "${1}" && -n "${2}" ]]; do
580 local var="${1}" value="${2}"
581 if [[ "${var:0:2}" == "--" ]]; then
582 local var=${var:2}
583 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
584 local gjl_${var}="${value}"
585 elif [[ "${var}" == "-into" ]]; then
586 target_dir="${value}"
587 elif [[ "${var}" == "-pre" ]]; then
588 pre="${value}"
589 fi
590 shift 2
591 done
592
593 # Test if no --jar and --main arguments were given and
594 # in that case check if the package only installs one jar
595 # and use that jar.
596 if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
597 local cp="${JAVA_PKG_CLASSPATH}"
598 if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
599 echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
600 else
601 local msg="Not enough information to create a launcher given."
602 msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
603 die "${msg}"
604 fi
605 fi
606
607 # Write the actual script
608 echo "#!/bin/bash" > "${target}"
609 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}"
610 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
611 cat "${var_tmp}" >> "${target}"
612 rm -f "${var_tmp}"
613 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
614
615 if [[ -n "${target_dir}" ]]; then
616 DESTTREE="${target_dir}" dobin "${target}"
617 local ret=$?
618 return ${ret}
619 else
620 dobin "${target}"
621 fi
622 }
623
624 # ------------------------------------------------------------------------------
625 # Install war files.
626 # TODO document
627 # ------------------------------------------------------------------------------
628 java-pkg_dowar() {
629 debug-print-function ${FUNCNAME} $*
630
631 # Check for arguments
632 [[ ${#} -lt 1 ]] && die "At least one argument needed"
633 java-pkg_check-phase install
634
635 java-pkg_init_paths_
636
637 local war
638 for war in $* ; do
639 local warpath
640 # TODO evaluate if we want to handle symlinks differently -nichoj
641 # Check for symlink
642 if [[ -L "${war}" ]] ; then
643 cp "${war}" "${T}"
644 warpath="${T}$(basename "${war}")"
645 # Check for directory
646 # TODO evaluate if we want to handle directories differently -nichoj
647 elif [[ -d "${war}" ]] ; then
648 echo "dowar: warning, skipping directory ${war}"
649 continue
650 else
651 warpath="${war}"
652 fi
653
654 # Install those files like you mean it
655 INSOPTIONS="-m 0644" \
656 INSDESTTREE=${JAVA_PKG_WARDEST} \
657 doins ${warpath}
658 done
659 }
660
661 # ------------------------------------------------------------------------------
662 # @internal-function java-pkg_recordjavadoc
663 # Scan for JavaDocs, and record their existence in the package.env file
664 #
665 # TODO make sure this in the proper section
666 # ------------------------------------------------------------------------------
667 java-pkg_recordjavadoc()
668 {
669 debug-print-function ${FUNCNAME} $*
670 # the find statement is important
671 # as some packages include multiple trees of javadoc
672 JAVADOC_PATH="$(find ${D}/usr/share/doc/ -name allclasses-frame.html -printf '%h:')"
673 # remove $D - TODO: check this is ok with all cases of the above
674 JAVADOC_PATH="${JAVADOC_PATH//${D}}"
675 if [[ -n "${JAVADOC_PATH}" ]] ; then
676 debug-print "javadocs found in ${JAVADOC_PATH%:}"
677 java-pkg_do_write_
678 else
679 debug-print "No javadocs found"
680 fi
681 }
682
683 # ------------------------------------------------------------------------------
684 # @section-end install
685 # ------------------------------------------------------------------------------
686
687 # ------------------------------------------------------------------------------
688 # @begin-section query
689 # Use these to build the classpath for building a package.
690 # ------------------------------------------------------------------------------
691
692 # ------------------------------------------------------------------------------
693 # @ebuild-function java-pkg_jar-from
694 #
695 # Makes a symlink to a jar from a certain package
696 # A lot of java packages include dependencies in a lib/ directory
697 # You can use this function to replace these bundled dependencies.
698 # The dependency is recorded into package.env DEPEND line, unless "--build-only"
699 # is passed as the very first argument, for jars that have to be present only
700 # at build time and are not needed on runtime (junit testing etc).
701 #
702 # Example: get all jars from xerces slot 2
703 # java-pkg_jar-from xerces-2
704 # Example: get a specific jar from xerces slot 2
705 # java-pkg_jar-from xerces-2 xml-apis.jar
706 # Example: get a specific jar from xerces slot 2, and name it diffrently
707 # java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
708 # Example: get junit.jar which is needed only for building
709 # java-pkg_jar-from --build-only junit junit.jar
710 #
711 # @param $1 - (optional) "--build-only" makes the jar(s) not added into
712 # package.env DEPEND line.
713 # @param $1 - Package to get jars from.
714 # @param $2 - jar from package. If not specified, all jars will be used.
715 # @param $3 - When a single jar is specified, destination filename of the
716 # symlink. Defaults to the name of the jar.
717 # ------------------------------------------------------------------------------
718 # TODO could probably be cleaned up a little
719 java-pkg_jar-from() {
720 debug-print-function ${FUNCNAME} $*
721
722 local build_only=""
723
724 if [[ "${1}" = "--build-only" ]]; then
725 build_only="true"
726 shift
727 fi
728
729 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
730
731 [[ -z ${target_pkg} ]] && die "Must specify a package"
732
733 # default destjar to the target jar
734 [[ -z "${destjar}" ]] && destjar="${target_jar}"
735
736 local error_msg="There was a problem getting the classpath for ${target_pkg}."
737 local classpath
738 classpath="$(java-config --classpath=${target_pkg})"
739 [[ $? != 0 ]] && die ${error_msg}
740
741 local jar
742 for jar in ${classpath//:/ }; do
743 local jar_name=$(basename "${jar}")
744 if [[ ! -f "${jar}" ]] ; then
745 debug-print "${jar} from ${target_pkg} does not exist"
746 die "Installation problems with jars in ${target_pkg} - is it installed?"
747 fi
748 # If no specific target jar was indicated, link it
749 if [[ -z "${target_jar}" ]] ; then
750 [[ -f "${target_jar}" ]] && rm "${target_jar}"
751 ln -snf "${jar}" \
752 || die "Failed to make symlink from ${jar} to ${jar_name}"
753 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
754 # otherwise, if the current jar is the target jar, link it
755 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
756 [[ -f "${destjar}" ]] && rm "${destjar}"
757 ln -snf "${jar}" "${destjar}" \
758 || die "Failed to make symlink from ${jar} to ${destjar}"
759 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
760 return 0
761 fi
762 done
763 # if no target was specified, we're ok
764 if [[ -z "${target_jar}" ]] ; then
765 return 0
766 # otherwise, die bitterly
767 else
768 die "Failed to find ${target_jar:-jar} in ${target_pkg}"
769 fi
770 }
771
772 # ------------------------------------------------------------------------------
773 # @ebuild-function java-pkg_jarfrom
774 #
775 # See java-pkg_jar-from
776 # ------------------------------------------------------------------------------
777 java-pkg_jarfrom() {
778 java-pkg_jar-from "$@"
779 }
780
781 # ------------------------------------------------------------------------------
782 # @ebuild-function java-pkg_getjars
783 #
784 # Get the classpath provided by any number of packages
785 # Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
786 # The providing packages are recorded as dependencies into package.env DEPEND
787 # line, unless "--build-only" is passed as the very first argument, for jars
788 # that have to be present only at build time and are not needed on runtime
789 # (junit testing etc).
790 #
791 # Example: Get the classpath for xerces-2 and xalan,
792 # java-pkg_getjars xerces-2,xalan
793 # Example Return:
794 # /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
795 #
796 # @param $1 - (optional) "--build-only" makes the jar(s) not added into
797 # package.env DEPEND line.
798 # @param $2 - list of packages to get jars from
799 # (passed to java-config --classpath)
800 # ------------------------------------------------------------------------------
801 java-pkg_getjars() {
802 debug-print-function ${FUNCNAME} $*
803
804 if [[ "${1}" = "--build-only" ]]; then
805 local build_only="true"
806 shift
807 fi
808
809 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --build-only"
810
811 local classpath pkgs="${1}"
812 jars="$(java-config --classpath=${pkgs})"
813 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed"
814 debug-print "${pkgs}:${jars}"
815
816 if [[ -z "${classpath}" ]]; then
817 classpath="${jars}"
818 else
819 classpath="${classpath}:${jars}"
820 fi
821
822 # Only record jars that aren't build-only
823 if [[ -z "${build_only}" ]]; then
824 oldifs="${IFS}"
825 IFS=","
826 for pkg in ${pkgs}; do
827 java-pkg_record-jar_ "${pkg}"
828 done
829 IFS="${oldifs}"
830 fi
831
832 echo "${classpath}"
833 }
834
835 # ------------------------------------------------------------------------------
836 # @ebuild-function java-pkg_getjar
837 #
838 # Get the filename of a single jar from a package
839 # The providing package is recorded as runtime dependency into package.env
840 # DEPEND line, unless "--build-only" is passed as the very first argument, for
841 # jars that have to be present only at build time and are not needed on runtime
842 # (junit testing etc).
843 #
844 # @example
845 # java-pkg_getjar xerces-2 xml-apis.jar
846 # @example-return
847 # /usr/share/xerces-2/lib/xml-apis.jar
848 #
849 # @param $1 - (optional) "--build-only" makes the jar not added into
850 # package.env DEPEND line.
851 # @param $1 - package to use
852 # @param $2 - jar to get
853 # ------------------------------------------------------------------------------
854 java-pkg_getjar() {
855 debug-print-function ${FUNCNAME} $*
856
857 local build_only=""
858
859 if [[ "${1}" = "--build-only" ]]; then
860 build_only="true"
861 shift
862 fi
863
864 local pkg="${1}" target_jar="${2}" jar
865 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
866 [[ -z ${target_jar} ]] && die "Must specify jar to get"
867
868 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
869 local classpath
870 classpath=$(java-config --classpath=${pkg})
871 [[ $? != 0 ]] && die ${error_msg}
872
873 for jar in ${classpath//:/ }; do
874 if [[ ! -f "${jar}" ]] ; then
875 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
876 fi
877
878 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
879 # Only record jars that aren't build-only
880 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" "${jar}"
881 echo "${jar}"
882 return 0
883 fi
884 done
885
886 die "Could not find ${target_jar} in ${pkg}"
887 return 1
888 }
889
890 # This function reads stdin, and based on that input, figures out how to
891 # populate jars from the filesystem.
892 # Need to figure out a good way of making use of this, ie be able to use a
893 # string that was built instead of stdin
894 # NOTE: this isn't quite ready for primetime.
895 #java-pkg_populate-jars() {
896 # local line
897 #
898 # read line
899 # while [[ -n "${line}" ]]; do
900 # # Ignore comments
901 # [[ ${line%%#*} == "" ]] && continue
902 #
903 # # get rid of any spaces
904 # line="${line// /}"
905 #
906 # # format: path=jarinfo
907 # local path=${line%%=*}
908 # local jarinfo=${line##*=}
909 #
910 # # format: jar@package
911 # local jar=${jarinfo%%@*}.jar
912 # local package=${jarinfo##*@}
913 # if [[ -n ${replace_only} ]]; then
914 # [[ ! -f $path ]] && die "No jar exists at ${path}"
915 # fi
916 # if [[ -n ${create_parent} ]]; then
917 # local parent=$(dirname ${path})
918 # mkdir -p "${parent}"
919 # fi
920 # java-pkg_jar-from "${package}" "${jar}" "${path}"
921 #
922 # read line
923 # done
924 #}
925
926 # ------------------------------------------------------------------------------
927 # @section-end query
928 # ------------------------------------------------------------------------------
929
930 # ------------------------------------------------------------------------------
931 # @section-begin helper
932 # @section-summary Helper functions
933 #
934 # Various other functions to use from an ebuild
935 # ------------------------------------------------------------------------------
936
937 # ------------------------------------------------------------------------------
938 # @ebuild-function java-pkg_need
939 #
940 # Adds virtual dependencies, which can optionally be controlled by a USE flag.
941 # Currently supported virtuals are:
942 # javamail
943 # jdbc-stdext
944 # jaf
945 # jdbc-rowset
946 # jms
947 #
948 # @param $1 - Optionally indicate that the dependencies are controlled by
949 # a use flag by specifying '--use' Requires $2.
950 # @param $2 - USE flag which will enable the dependencies.
951 # @param $@ - virtual packages to add depenedencies for
952 # ------------------------------------------------------------------------------
953 # TODO rewrite to parse a line based declaration file instead -- karltk
954 #java-pkg_need() {
955 # debug-print-function ${FUNCNAME} $*
956 # local useflag
957 # if [[ ${1} == "--use" ]]; then
958 # useflag="${2}"
959 # shift 2
960 # fi
961 #
962 # if [[ -z ${1} ]]; then
963 # die "Must specify at least one virtual package."
964 # fi
965 #
966 # local depstr newdepstr
967 #
968 # for virtual in ${@}; do
969 # if has ${virtual} ${JAVA_PKG_VNEED}; then
970 # debug-print "Already registered virtual ${virtual}"
971 # continue
972 # fi
973 # case ${virtual} in
974 # javamail)
975 # debug-print "java-pkg_need: adding javamail dependencies"
976 # newdepstr="|| ( dev-java/gnu-javamail dev-java/sun-javamail-bin )"
977 # ;;
978 # jdbc-stdext)
979 # debug-print "java-pkg_need: adding jdbc-stdext dependencies"
980 # newdepstr="|| ( >=virtual/jdk-1.4 dev-java/jdbc2-stdext )"
981 # ;;
982 # jaf)
983 # debug-print "java-pkg_need: adding jaf dependencies"
984 # newdepstr="|| ( dev-java/gnu-jaf dev-java/sun-jaf-bin )"
985 # ;;
986 # jdbc-rowset)
987 # debug-print "java-pkg_need: adding jdbc-rowset dependencies"
988 # newdepstr="|| ( >=virtual/jdk-1.5 dev-java/sun-jdbc-rowset )"
989 # ;;
990 # jms)
991 # debug-print "java-pkg_need: adding jms dependencies"
992 # newdepstr="|| ( dev-java/sun-jms dev-java/openjms )"
993 # ;;
994 # *)
995 # die "Invalid virtual: ${virtual}"
996 # esac
997 #
998 # export JAVA_PKG_VNEED="${JAVA_PKG_VNEED} ${virtual}"
999 #
1000 # if [[ -n ${useflag} ]]; then
1001 # depstr="${depstr} ${useflag}? ( ${newdepstr} )"
1002 # else
1003 # depstr="${depstr} ${newdepstr}"
1004 # fi
1005 # done
1006 #
1007 # [[ -z ${JAVA_PKG_NV_DEPEND} ]] && export JAVA_PKG_NV_DEPEND="${DEPEND}"
1008 # [[ -z ${JAVA_PKG_NV_RDEPEND} ]] && export JAVA_PKG_NV_RDEPEND="${RDEPEND}"
1009 #
1010 # export DEPEND="${DEPEND} ${depstr}"
1011 # export RDEPEND="${RDEPEND} ${depstr}"
1012 #}
1013
1014 # ------------------------------------------------------------------------------
1015 # @ebuild-function java-pkg_find-normal-jars
1016 #
1017 # Find the files with suffix .jar file in the given directory or $WORKDIR
1018 #
1019 # @param $1 - The directory to search for jar files (default: ${WORKDIR})
1020 # ------------------------------------------------------------------------------
1021 java-pkg_find-normal-jars() {
1022 local dir=$1
1023 [[ "${dir}" ]] || dir="${WORKDIR}"
1024 local found
1025 for jar in $(find "${dir}" -name "*.jar" -type f); do
1026 echo "${jar}"
1027 found="true"
1028 done
1029 [[ "${found}" ]]
1030 return $?
1031 }
1032
1033 # ------------------------------------------------------------------------------
1034 # @ebuild-function java-pkg_ensure-no-bundled-jars
1035 #
1036 # Try to locate bundled jar files in ${WORKDIR} and die if found.
1037 # This function should be called after WORKDIR has been populated with symlink
1038 # to system jar files or bundled jars removed.
1039 # ------------------------------------------------------------------------------
1040 java-pkg_ensure-no-bundled-jars() {
1041 debug-print-function ${FUNCNAME} $*
1042
1043 local bundled_jars=$(java-pkg_find-normal-jars)
1044 if [[ -n ${bundled_jars} ]]; then
1045 echo "Bundled jars found:"
1046 local jar
1047 for jar in ${bundled_jars}; do
1048 echo $(pwd)${jar/./}
1049 done
1050 die "Bundled jars found!"
1051 fi
1052 }
1053
1054 # ------------------------------------------------------------------------------
1055 # @internal-function java-pkg_ensure-vm-version-sufficient
1056 #
1057 # Checks if we have a sufficient VM and dies if we don't.
1058 #
1059 # ------------------------------------------------------------------------------
1060 java-pkg_ensure-vm-version-sufficient() {
1061 debug-print-function ${FUNCNAME} $*
1062
1063 if ! java-pkg_is-vm-version-sufficient; then
1064 debug-print "VM is not suffient"
1065 eerror "Current Java VM cannot build this package"
1066 einfo "Please use java-config -S to set the correct one"
1067 die "Active Java VM cannot build this package"
1068 fi
1069 }
1070
1071 # ------------------------------------------------------------------------------
1072 # @internal-function java-pkg_is-vm-version-sufficient
1073 #
1074 # @return zero - VM is sufficient
1075 # @return non-zero - VM is not sufficient
1076 # ------------------------------------------------------------------------------
1077 java-pkg_is-vm-version-sufficient() {
1078 debug-print-function ${FUNCNAME} $*
1079
1080 depend-java-query --is-sufficient "${DEPEND}" > /dev/null
1081 return $?
1082 }
1083
1084 # ------------------------------------------------------------------------------
1085 # @internal-function java-pkg_ensure-vm-version-eq
1086 #
1087 # Die if the current VM is not equal to the argument passed.
1088 #
1089 # @param $@ - Desired VM version to ensure
1090 # ------------------------------------------------------------------------------
1091 java-pkg_ensure-vm-version-eq() {
1092 debug-print-function ${FUNCNAME} $*
1093
1094 if ! java-pkg_is-vm-version-eq $@ ; then
1095 debug-print "VM is not suffient"
1096 eerror "This package requires a Java VM version = $@"
1097 einfo "Please use java-config -S to set the correct one"
1098 die "Active Java VM too old"
1099 fi
1100 }
1101
1102 # ------------------------------------------------------------------------------
1103 # @internal-function java-pkg_is-vm-version-eq
1104 #
1105 # @param $@ - VM version to compare current VM to
1106 # @return zero - VM versions are equal
1107 # @return non-zero - VM version are not equal
1108 # ------------------------------------------------------------------------------
1109 java-pkg_is-vm-version-eq() {
1110 debug-print-function ${FUNCNAME} $*
1111
1112 local needed_version="$@"
1113
1114 [[ -z "${needed_version}" ]] && die "need an argument"
1115
1116 local vm_version="$(java-pkg_get-vm-version)"
1117
1118 vm_version="$(get_version_component_range 1-2 "${vm_version}")"
1119 needed_version="$(get_version_component_range 1-2 "${needed_version}")"
1120
1121 if [[ -z "${vm_version}" ]]; then
1122 debug-print "Could not get JDK version from DEPEND"
1123 return 1
1124 else
1125 if [[ "${vm_version}" == "${needed_version}" ]]; then
1126 debug-print "Detected a JDK(${vm_version}) = ${needed_version}"
1127 return 0
1128 else
1129 debug-print "Detected a JDK(${vm_version}) != ${needed_version}"
1130 return 1
1131 fi
1132 fi
1133 }
1134
1135 # ------------------------------------------------------------------------------
1136 # @internal-function java-pkg_ensure-vm-version-ge
1137 #
1138 # Die if the current VM is not greater than the desired version
1139 #
1140 # @param $@ - VM version to compare current to
1141 # ------------------------------------------------------------------------------
1142 java-pkg_ensure-vm-version-ge() {
1143 debug-print-function ${FUNCNAME} $*
1144
1145 if ! java-pkg_is-vm-version-ge "$@" ; then
1146 debug-print "vm is not suffient"
1147 eerror "This package requires a Java VM version >= $@"
1148 einfo "Please use java-config -S to set the correct one"
1149 die "Active Java VM too old"
1150 fi
1151 }
1152
1153 # ------------------------------------------------------------------------------
1154 # @internal-function java-pkg_is-vm-version-ge
1155 #
1156 # @param $@ - VM version to compare current VM to
1157 # @return zero - current VM version is greater than checked version
1158 # @return non-zero - current VM version is not greater than checked version
1159 # ------------------------------------------------------------------------------
1160 java-pkg_is-vm-version-ge() {
1161 debug-print-function ${FUNCNAME} $*
1162
1163 local needed_version=$@
1164 local vm_version=$(java-pkg_get-vm-version)
1165 if [[ -z "${vm_version}" ]]; then
1166 debug-print "Could not get JDK version from DEPEND"
1167 return 1
1168 else
1169 if version_is_at_least "${needed_version}" "${vm_version}"; then
1170 debug-print "Detected a JDK(${vm_version}) >= ${needed_version}"
1171 return 0
1172 else
1173 debug-print "Detected a JDK(${vm_version}) < ${needed_version}"
1174 return 1
1175 fi
1176 fi
1177 }
1178
1179 java-pkg_set-current-vm() {
1180 export GENTOO_VM=${1}
1181 }
1182
1183 java-pkg_get-current-vm() {
1184 echo ${GENTOO_VM}
1185 }
1186
1187 java-pkg_current-vm-matches() {
1188 hasq $(java-pkg_get-current-vm) ${@}
1189 return $?
1190 }
1191
1192 # ------------------------------------------------------------------------------
1193 # @ebuild-function java-pkg_get-source
1194 #
1195 # Determines what source version should be used, for passing to -source.
1196 # Unless you want to break things you probably shouldn't set _WANT_SOURCE
1197 #
1198 # @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1199 # ------------------------------------------------------------------------------
1200 java-pkg_get-source() {
1201 echo ${JAVA_PKG_WANT_SOURCE:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1202 }
1203
1204 # ------------------------------------------------------------------------------
1205 # @ebuild-function java-pkg_get-target
1206 #
1207 # Determines what target version should be used, for passing to -target.
1208 # If you don't care about lower versions, you can set _WANT_TARGET to the
1209 # version of your JDK.
1210 #
1211 # @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1212 # ------------------------------------------------------------------------------
1213 java-pkg_get-target() {
1214 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1215 }
1216
1217 java-pkg_get-javac() {
1218 debug-print-function ${FUNCNAME} $*
1219
1220
1221 local compiler="${GENTOO_COMPILER}"
1222
1223 local compiler_executable
1224 if [[ "${compiler}" = "javac" ]]; then
1225 # nothing fancy needs to be done for javac
1226 compiler_executable="javac"
1227 else
1228 # for everything else, try to determine from an env file
1229
1230 local compiler_env="/usr/share/java-config-2/compiler/${compiler}"
1231 if [[ -f ${compiler_env} ]]; then
1232 local old_javac=${JAVAC}
1233 unset JAVAC
1234 # try to get value of JAVAC
1235 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1236 export JAVAC=${old_javac}
1237
1238 if [[ -z ${compiler_executable} ]]; then
1239 echo "JAVAC is empty or undefined in ${compiler_env}"
1240 return 1
1241 fi
1242
1243 # check that it's executable
1244 if [[ ! -x ${compiler_executable} ]]; then
1245 echo "${compiler_executable} doesn't exist, or isn't executable"
1246 return 1
1247 fi
1248 else
1249 echo "Could not find environment file for ${compiler}"
1250 return 1
1251 fi
1252 fi
1253 echo ${compiler_executable}
1254 }
1255
1256 # ------------------------------------------------------------------------------
1257 # @ebuild-function java-pkg_javac-args
1258 #
1259 # If an ebuild uses javac directly, instead of using ejavac, it should call this
1260 # to know what -source/-target to use.
1261 #
1262 # @return string - arguments to pass to javac, complete with -target and -source
1263 # ------------------------------------------------------------------------------
1264 java-pkg_javac-args() {
1265 debug-print-function ${FUNCNAME} $*
1266
1267 local want_source="$(java-pkg_get-source)"
1268 local want_target="$(java-pkg_get-target)"
1269
1270 local source_str="-source ${want_source}"
1271 local target_str="-target ${want_target}"
1272
1273 debug-print "want source: ${want_source}"
1274 debug-print "want target: ${want_target}"
1275
1276 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1277 debug-print "could not find valid -source/-target values for javac"
1278 echo "Could not find valid -source/-target values for javac"
1279 return 1
1280 else
1281 if java-pkg_is-vm-version-ge "1.4"; then
1282 echo "${source_str} ${target_str}"
1283 else
1284 echo "${target_str}"
1285 fi
1286 fi
1287 }
1288
1289 # TODO document
1290 java-pkg_get-jni-cflags() {
1291 local flags="-I${JAVA_HOME}/include"
1292
1293 local platform="linux"
1294 use elibc_FreeBSD && platform="freebsd"
1295
1296 # TODO do a check that the directories are valid
1297 flags="${flags} -I${JAVA_HOME}/include/${platform}"
1298
1299 echo ${flags}
1300 }
1301
1302 java-pkg_ensure-gcj() {
1303 if ! built_with_use sys-devel/gcc gcj ; then
1304 ewarn
1305 ewarn "You must build gcc with the gcj support to build with gcj"
1306 ewarn
1307 ebeep 5
1308 die "No GCJ support found!"
1309 fi
1310 }
1311
1312 java-pkg_ensure-test() {
1313 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \
1314 && hasq test ${IUSE} && ! use test;
1315 then
1316 eerror "You specified FEATURES=test, but USE=test is needed"
1317 eerror "to pull in the additional dependencies for testing"
1318 die "Need USE=test enabled"
1319 fi
1320 }
1321
1322 # ------------------------------------------------------------------------------
1323 # @section-end helper
1324 # ------------------------------------------------------------------------------
1325
1326 # ------------------------------------------------------------------------------
1327 # @section-begin build
1328 # @section-summary Build functions
1329 #
1330 # These are some functions for building a package. In particular, it consists of
1331 # wrappers for javac and ant.
1332 # ------------------------------------------------------------------------------
1333
1334 # ------------------------------------------------------------------------------
1335 # @ebuild-function eant
1336 #
1337 # Ant wrapper function. Will use the appropriate compiler, based on user-defined
1338 # compiler.
1339 # variables:
1340 # EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1341 # gentoo.classpath property. Be sure to call
1342 # java-ant_rewrite-classpath in src_unpack.
1343 #
1344 # ------------------------------------------------------------------------------
1345 eant() {
1346 debug-print-function ${FUNCNAME} $*
1347
1348 # FIXME get this working
1349 # if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then
1350 # java-pkg_announce-qa-violation \
1351 # "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1352 # fi
1353
1354 local antflags="-Dnoget=true"
1355 java-pkg_init-compiler_
1356 local compiler="${GENTOO_COMPILER}"
1357
1358 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1359
1360 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})"
1361 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1362 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1363 fi
1364
1365 if [[ ${compiler} != "javac" ]]; then
1366 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1367 # Figure out any extra stuff to put on the classpath for compilers aside
1368 # from javac
1369 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1370 # java-config -p
1371 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})"
1372 if [[ -n ${build_compiler_deps} ]]; then
1373 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1374 fi
1375 fi
1376
1377 if is-java-strict; then
1378 einfo "Disabling system classpath for ant"
1379 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1380 fi
1381
1382 if [[ -n ${JAVA_PKG_DEBUG} ]]; then
1383 antflags="${antflags} -debug"
1384 fi
1385
1386 local gcp="${EANT_GENTOO_CLASSPATH}"
1387
1388 if [[ "${gcp}" ]]; then
1389 local cp="$(java-pkg_getjars ${gcp})"
1390 # It seems ant does not like single quotes around ${cp}
1391 antflags="${antflags} -Dgentoo.classpath=\"${cp}\""
1392 fi
1393
1394 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1395 ant ${antflags} "${@}" || die "eant failed"
1396
1397 }
1398
1399 # ------------------------------------------------------------------------------
1400 # @ebuild-function ejavac
1401 #
1402 # Javac wrapper function. Will use the appropriate compiler, based on
1403 # /etc/java-config/compilers.conf
1404 #
1405 # @param $@ - Arguments to be passed to the compiler
1406 # ------------------------------------------------------------------------------
1407 ejavac() {
1408 debug-print-function ${FUNCNAME} $*
1409
1410 java-pkg_init-compiler_
1411
1412 local compiler_executable
1413 compiler_executable=$(java-pkg_get-javac)
1414 if [[ ${?} != 0 ]]; then
1415 eerror "There was a problem determining compiler: ${compiler_executable}"
1416 die "get-javac failed"
1417 fi
1418
1419 local javac_args
1420 javac_args="$(java-pkg_javac-args)"
1421 if [[ ${?} != 0 ]]; then
1422 eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
1423 die "java-pkg_javac-args failed"
1424 fi
1425
1426 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1427 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1428 }
1429
1430 # ------------------------------------------------------------------------------
1431 # @ebuild-function java-pkg_filter-compiler
1432 #
1433 # Used to prevent the use of some compilers. Should be used in src_compile.
1434 # Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
1435 #
1436 # @param $@ - compilers to filter
1437 # ------------------------------------------------------------------------------
1438 java-pkg_filter-compiler() {
1439 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@"
1440 }
1441
1442 # ------------------------------------------------------------------------------
1443 # @ebuild-function java-pkg_force-compiler
1444 #
1445 # Used to force the use of particular compilers. Should be used in src_compile.
1446 # A common use of this would be to force ecj-3.1 to be used on amd64, to avoid
1447 # OutOfMemoryErrors that may come up.
1448 #
1449 # @param $@ - compilers to force
1450 # ------------------------------------------------------------------------------
1451 java-pkg_force-compiler() {
1452 JAVA_PKG_FORCE_COMPILER="$@"
1453 }
1454
1455 # ------------------------------------------------------------------------------
1456 # @ebuild-function use_doc
1457 #
1458 # Helper function for getting ant to build javadocs. If the user has USE=doc,
1459 # then 'javadoc' or the argument are returned. Otherwise, there is no return.
1460 #
1461 # The output of this should be passed to ant.
1462 #
1463 # Example: build javadocs by calling 'javadoc' target
1464 # eant $(use_doc)
1465 # Example: build javadocs by calling 'apidoc' target
1466 # eant $(use_doc apidoc)
1467 #
1468 # @param $@ - Option value to return. Defaults to 'javadoc'
1469 # @return string - Name of the target to create javadocs
1470 # ------------------------------------------------------------------------------
1471 use_doc() {
1472 use doc && echo ${@:-javadoc}
1473 }
1474
1475
1476 # ------------------------------------------------------------------------------
1477 # @section-end build
1478 # ------------------------------------------------------------------------------
1479
1480 # ------------------------------------------------------------------------------
1481 # @section-begin internal
1482 # @section-summary Internal functions
1483 #
1484 # Do __NOT__ use any of these from an ebuild! These are only to be used from
1485 # within the java eclasses.
1486 # ------------------------------------------------------------------------------
1487
1488 # -----------------------------------------------------------------------------
1489 # @function-internal java-pkg_init
1490 #
1491 # The purpose of this function, as the name might imply, is to initialize the
1492 # Java environment. It ensures that that there aren't any environment variables
1493 # that'll muss things up. It initializes some variables, which are used
1494 # internally. And most importantly, it'll switch the VM if necessary.
1495 #
1496 # This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will
1497 # call it during each of the phases of the merge process.
1498 #
1499 # -----------------------------------------------------------------------------
1500 java-pkg_init() {
1501 unset JAVAC
1502 unset JAVA_HOME
1503 java-pkg_init_paths_
1504 java-pkg_switch-vm
1505 PATH=${JAVA_HOME}/bin:${PATH}
1506
1507 # TODO we will probably want to set JAVAC and JAVACFLAGS
1508
1509 # Do some QA checks
1510 java-pkg_check-jikes
1511
1512 # When users have crazy classpaths some packages can fail to compile.
1513 # and everything should work with empty CLASSPATH.
1514 # This also helps prevent unexpected dependencies on random things
1515 # from the CLASSPATH.
1516 unset CLASSPATH
1517 }
1518
1519 # ------------------------------------------------------------------------------
1520 # @function-internal java-pkg-init-compiler_
1521 #
1522 # This function attempts to figure out what compiler should be used. It does
1523 # this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
1524 # COMPILERS variable defined there.
1525 # This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
1526 #
1527 # It will go through the list of compilers, and verify that it supports the
1528 # target and source that are needed. If it is not suitable, then the next
1529 # compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
1530 # isn't done.
1531 #
1532 # Once the which compiler to use has been figured out, it is set to
1533 # GENTOO_COMPILER.
1534 #
1535 # If you hadn't guessed, JAVA_PKG_FORCE_COMPILER is for testing only.
1536 #
1537 # If the user doesn't defined anything in JAVA_PKG_COMPILERS_CONF, or no
1538 # suitable compiler was found there, then the default is to use javac provided
1539 # by the current VM.
1540 #
1541 #
1542 # @return name of the compiler to use
1543 # ------------------------------------------------------------------------------
1544 java-pkg_init-compiler_() {
1545 debug-print-function ${FUNCNAME} $*
1546
1547 if [[ -n ${GENTOO_COMPILER} ]]; then
1548 debug-print "GENTOO_COMPILER already set"
1549 return
1550 fi
1551
1552 local compilers;
1553 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1554 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
1555 else
1556 compilers=${JAVA_PKG_FORCE_COMPILER}
1557 fi
1558
1559 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
1560
1561 # Figure out if we should announce what compiler we're using
1562 local compiler
1563 for compiler in ${compilers}; do
1564 debug-print "Checking ${compiler}..."
1565 # javac should always be alright
1566 if [[ ${compiler} = "javac" ]]; then
1567 debug-print "Found javac... breaking"
1568 export GENTOO_COMPILER="javac"
1569 break
1570 fi
1571
1572 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
1573 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1574 einfo "Filtering ${compiler}"
1575 continue
1576 fi
1577 fi
1578
1579 # for non-javac, we need to make sure it supports the right target and
1580 # source
1581 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1582 if [[ -f ${compiler_env} ]]; then
1583 local desired_target="$(java-pkg_get-target)"
1584 local desired_source="$(java-pkg_get-source)"
1585
1586
1587 # Verify that the compiler supports target
1588 local supported_target=$(source ${compiler_env} 1>/dev/null 2>&1; echo ${SUPPORTED_TARGET})
1589 if ! has ${desired_target} ${supported_target}; then
1590 ewarn "${compiler} does not support -target ${desired_target}, skipping"
1591 continue
1592 fi
1593
1594 # -source was introduced in 1.3, so only check 1.3 and on
1595 if version_is_at_least "${desired_soure}" "1.3"; then
1596 # Verify that the compiler supports source
1597 local supported_source=$(source ${compiler_env} 1>/dev/null 2>&1; echo ${SUPPORTED_SOURCE})
1598 if ! has ${desired_source} ${supported_source}; then
1599 ewarn "${compiler} does not support -source ${desired_source}, skipping"
1600 continue
1601 fi
1602 fi
1603
1604 # if you get here, then the compiler should be good to go
1605 export GENTOO_COMPILER="${compiler}"
1606 break
1607 else
1608 ewarn "Could not find configuration for ${compiler}, skipping"
1609 ewarn "Perhaps it is not installed?"
1610 continue
1611 fi
1612 done
1613
1614 # If it hasn't been defined already, default to javac
1615 if [[ -z ${GENTOO_COMPILER} ]]; then
1616 if [[ -n ${compilers} ]]; then
1617 einfo "No suitable compiler found: defaulting javac for compilation"
1618 else
1619 # probably don't need to notify users about the default.
1620 :;#einfo "Defaulting to javac for compilation"
1621 fi
1622 export GENTOO_COMPILER=javac
1623 else
1624 einfo "Using ${GENTOO_COMPILER} for compilation"
1625 fi
1626
1627 }
1628
1629 # ------------------------------------------------------------------------------
1630 # @internal-function init_paths_
1631 #
1632 # Initializes some variables that will be used. These variables are mostly used
1633 # to determine where things will eventually get installed.
1634 # ------------------------------------------------------------------------------
1635 java-pkg_init_paths_() {
1636 debug-print-function ${FUNCNAME} $*
1637
1638 local pkg_name
1639 if [[ "$SLOT" == "0" ]] ; then
1640 JAVA_PKG_NAME="${PN}"
1641 else
1642 JAVA_PKG_NAME="${PN}-${SLOT}"
1643 fi
1644
1645 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}"
1646 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/"
1647 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env"
1648
1649 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib"
1650 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}"
1651 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps"
1652
1653
1654 # TODO maybe only print once?
1655 debug-print "JAVA_PKG_SHAREPATH: ${JAVA_PKG_SHAREPATH}"
1656 debug-print "JAVA_PKG_ENV: ${JAVA_PKG_ENV}"
1657 debug-print "JAVA_PKG_JARDEST: ${JAVA_PKG_JARDEST}"
1658 debug-print "JAVA_PKG_LIBDEST: ${JAVA_PKG_LIBDEST}"
1659 debug-print "JAVA_PKG_WARDEST: ${JAVA_PKG_WARDEST}"
1660 }
1661
1662 # ------------------------------------------------------------------------------
1663 # @internal-function java-pkg_do_write_
1664 #
1665 # Writes the package.env out to disk.
1666 #
1667 # ------------------------------------------------------------------------------
1668 # TODO change to do-write, to match everything else
1669 java-pkg_do_write_() {
1670 java-pkg_init_paths_
1671 # Create directory for package.env
1672 dodir "${JAVA_PKG_SHAREPATH}"
1673 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then
1674 # Create package.env
1675 (
1676 echo "DESCRIPTION=\"${DESCRIPTION}\""
1677 echo "GENERATION=\"2\""
1678
1679 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
1680 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1681 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1682 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\""
1683 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1684 ) > "${JAVA_PKG_ENV}"
1685
1686 # register target/source
1687 local target="$(java-pkg_get-target)"
1688 local source="$(java-pkg_get-source)"
1689 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
1690 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
1691
1692 # register javadoc info
1693 [[ -n ${JAVADOC_PATH} ]] && echo "JAVADOC_PATH=\"${JAVADOC_PATH}\"" \
1694 >> ${JAVA_PKG_ENV}
1695 # register source archives
1696 [[ -n ${JAVA_SOURCES} ]] && echo "JAVA_SOURCES=\"${JAVA_SOURCES}\"" \
1697 >> ${JAVA_PKG_ENV}
1698
1699
1700 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
1701 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
1702
1703 # Strip unnecessary leading and trailing colons
1704 # TODO try to cleanup if possible
1705 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
1706 fi
1707 }
1708
1709 # ------------------------------------------------------------------------------
1710 # @internal-function java-pkg_record-jar_
1711 #
1712 # Record a dependency to the package.env
1713 #
1714 # ------------------------------------------------------------------------------
1715 JAVA_PKG_DEPEND="${T}/java-pkg-depend"
1716
1717 java-pkg_record-jar_() {
1718 debug-print-function ${FUNCNAME} $*
1719
1720 local pkg=${1} jar=${2} append
1721 if [[ -z "${jar}" ]]; then
1722 append="${pkg}"
1723 else
1724 append="$(basename ${jar})@${pkg}"
1725 fi
1726
1727 echo ${append} >> ${JAVA_PKG_DEPEND}
1728 }
1729
1730 # ------------------------------------------------------------------------------
1731 # @internal-function java-pkg_append_
1732 #
1733 # Appends a value to a variable
1734 #
1735 # Example: java-pkg_append_ CLASSPATH foo.jar
1736 # @param $1 variable name to modify
1737 # @param $2 value to append
1738 # ------------------------------------------------------------------------------
1739 java-pkg_append_() {
1740 debug-print-function ${FUNCNAME} $*
1741
1742 local var="${1}" value="${2}"
1743 if [[ -z "${!var}" ]] ; then
1744 export ${var}="${value}"
1745 else
1746 local oldIFS=${IFS} cur haveit
1747 IFS=':'
1748 for cur in ${!var}; do
1749 if [[ ${cur} == ${value} ]]; then
1750 haveit="yes"
1751 break
1752 fi
1753 done
1754 [[ -z ${haveit} ]] && export ${var}="${!var}:${value}"
1755 IFS=${oldIFS}
1756 fi
1757 }
1758
1759 # ------------------------------------------------------------------------------
1760 # @internal-function java-pkg_expand_dir_
1761 #
1762 # Gets the full path of the file/directory's parent.
1763 # @param $1 - file/directory to find parent directory for
1764 # @return - path to $1's parent directory
1765 # ------------------------------------------------------------------------------
1766 java-pkg_expand_dir_() {
1767 pushd "$(dirname "${1}")" >/dev/null 2>&1
1768 pwd
1769 popd >/dev/null 2>&1
1770 }
1771
1772 # ------------------------------------------------------------------------------
1773 # @internal-function java-pkg_func-exists
1774 #
1775 # Does the indicated function exist?
1776 #
1777 # @return 0 - function is declared
1778 # @return 1 - function is undeclared
1779 # ------------------------------------------------------------------------------
1780 java-pkg_func-exists() {
1781 if [[ -n "$(declare -f ${1})" ]]; then
1782 return 0
1783 else
1784 return 1
1785 fi
1786 }
1787
1788 # ------------------------------------------------------------------------------
1789 # @internal-function java-pkg_setup-vm
1790 #
1791 # Sets up the environment for a specific VM
1792 #
1793 # ------------------------------------------------------------------------------
1794 java-pkg_setup-vm() {
1795 debug-print-function ${FUNCNAME} $*
1796
1797 local vendor="$(java-pkg_get-vm-vendor)"
1798 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1799 addpredict "/dev/random"
1800 elif [[ "${vendor}" == "ibm" ]]; then
1801 addpredict "/proc/self/maps"
1802 addpredict "/proc/cpuinfo"
1803 export LANG="C" LC_ALL="C"
1804 elif [[ "${vendor}" == "jrockit" ]]; then
1805 addpredict "/proc/cpuinfo"
1806 fi
1807 }
1808
1809 # ------------------------------------------------------------------------------
1810 # @internal-function java-pkg_needs-vm
1811 #
1812 # Does the current package depend on virtual/jdk?
1813 #
1814 # @return 0 - Package depends on virtual/jdk
1815 # @return 1 - Package does not depend on virtual/jdk
1816 # ------------------------------------------------------------------------------
1817 java-pkg_needs-vm() {
1818 debug-print-function ${FUNCNAME} $*
1819
1820 if [[ -n "$(echo ${DEPEND} | sed -e '\:virtual/jdk:!d')" ]]; then
1821 return 0
1822 fi
1823
1824 return 1
1825 }
1826
1827 # ------------------------------------------------------------------------------
1828 # @internal-function java-pkg_get-current-vm
1829 #
1830 # @return - The current VM being used
1831 # ------------------------------------------------------------------------------
1832 java-pkg_get-current-vm() {
1833 java-config -f
1834 }
1835
1836 # ------------------------------------------------------------------------------
1837 # @internal-function java-pkg_get-vm-vendor
1838 #
1839 # @return - The vendor of the current VM
1840 # ------------------------------------------------------------------------------
1841 java-pkg_get-vm-vendor() {
1842 debug-print-function ${FUNCNAME} $*
1843
1844 local vm="$(java-pkg_get-current-vm)"
1845 vm="${vm/-*/}"
1846 echo "${vm}"
1847 }
1848
1849 # ------------------------------------------------------------------------------
1850 # @internal-function java-pkg_get-vm-version
1851 #
1852 # @return - The version of the current VM
1853 # ------------------------------------------------------------------------------
1854 java-pkg_get-vm-version() {
1855 debug-print-function ${FUNCNAME} $*
1856
1857 java-config -g PROVIDES_VERSION
1858 }
1859
1860 # ------------------------------------------------------------------------------
1861 # @internal-function java-pkg_switch-vm
1862 #
1863 # Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1864 # verify that the current VM is sufficient.
1865 # Setup the environment for the VM being used.
1866 # ------------------------------------------------------------------------------
1867 java-pkg_switch-vm() {
1868 debug-print-function ${FUNCNAME} $*
1869
1870 if java-pkg_needs-vm; then
1871 # Use the VM specified by JAVA_PKG_FORCE_VM
1872 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1873 # If you're forcing the VM, I hope you know what your doing...
1874 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1875 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1876 # if we're allowed to switch the vm...
1877 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1878 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1879 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1880 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1881 else
1882 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1883 fi
1884 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
1885 eerror "Unable to determine VM for building from dependencies:"
1886 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
1887 echo "VNEED: ${JAVA_PKG_VNEED}"
1888 die "Failed to determine VM for building."
1889 else
1890 export GENTOO_VM
1891 fi
1892 # otherwise just make sure the current VM is sufficient
1893 else
1894 java-pkg_ensure-vm-version-sufficient
1895 fi
1896 debug-print "Using: $(java-config -f)"
1897
1898 java-pkg_setup-vm
1899
1900 export JAVA=$(java-config --java)
1901 export JAVAC=$(java-config --javac)
1902 JAVACFLAGS="$(java-pkg_javac-args)"
1903 if [[ ${?} != 0 ]]; then
1904 eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
1905 die "java-pkg_javac-args failed"
1906 fi
1907 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
1908 export JAVACFLAGS
1909
1910 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1911 export JDK_HOME=${JAVA_HOME}
1912
1913 #TODO If you know a better solution let us know.
1914 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1915
1916 local tann="${T}/announced-vm"
1917 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1918 # Add a check for setup/preinst phase... to avoid duplicate outputs
1919 # for when FEATURES=buildpkg
1920 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1921 then
1922 einfo "Using: $(java-config -f)"
1923 [[ ! -f "${tann}" ]] && touch "${tann}"
1924 fi
1925 fi
1926
1927 else
1928 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!"
1929 fi
1930 }
1931
1932 # ------------------------------------------------------------------------------
1933 # @internal-function java-pkg_die
1934 #
1935 # Enhanced die for Java packages, which displays some information that may be
1936 # useful for debugging bugs on bugzilla.
1937 # ------------------------------------------------------------------------------
1938 #register_die_hook java-pkg_die
1939 if ! hasq java-pkg_die ${EBUILD_DEATH_HOOKS}; then
1940 EBUILD_DEATH_HOOKS="${EBUILD_DEATH_HOOKS} java-pkg_die"
1941 fi
1942
1943 java-pkg_die() {
1944 echo "!!! When you file a bug report, please include the following information:" >&2
1945 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2
1946 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2
1947 echo "and of course, the output of emerge --info" >&2
1948 }
1949
1950
1951 # TODO document
1952 # List jars in the source directory, ${S}
1953 java-pkg_jar-list() {
1954 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
1955 einfo "Linked Jars"
1956 find "${S}" -type l -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1957 einfo "Jars"
1958 find "${S}" -type f -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1959 einfo "Classes"
1960 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1961 fi
1962 }
1963
1964 # TODO document
1965 # Verify that the classes were compiled for the right source / target
1966 java-pkg_verify-classes() {
1967 ebegin "Verifying java class versions"
1968 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1969 class-version-verify.py -t $(java-pkg_get-target) -r ${D}
1970 result=$?
1971 eend ${result}
1972 if [[ ${result} == 0 ]]; then
1973 einfo "All good"
1974 else
1975 ewarn "Possible problem"
1976 die "Bad class files found"
1977 fi
1978 }
1979
1980 # ------------------------------------------------------------------------------
1981 # @section-end internal
1982 # ------------------------------------------------------------------------------
1983
1984 java-pkg_check-phase() {
1985 local phase=${1}
1986 local funcname=${2}
1987 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then
1988 java-pkg_announce-qa-violation \
1989 "${funcname} used outside of src_${phase}"
1990 fi
1991 }
1992
1993 java-pkg_check-versioned-jar() {
1994 local jar=${1}
1995
1996 if [[ ${jar} =~ ${PV} ]]; then
1997 java-pkg_announce-qa-violation "installing versioned jar '${jar}'"
1998 fi
1999 }
2000
2001 java-pkg_check-jikes() {
2002 if hasq jikes ${IUSE}; then
2003 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
2004 fi
2005 }
2006
2007 java-pkg_announce-qa-violation() {
2008 if is-java-strict; then
2009 echo "Java QA Notice: $@" >&2
2010 increment-qa-violations
2011 fi
2012 }
2013
2014 increment-qa-violations() {
2015 let "JAVA_PKG_QA_VIOLATIONS+=1"
2016 export JAVA_PKG_QA_VIOLATIONS
2017 }
2018
2019 is-java-strict() {
2020 [[ -n ${JAVA_PKG_STRICT} ]]
2021 return $?
2022 }
2023
2024 # ------------------------------------------------------------------------------
2025 # @eclass-end
2026 # ------------------------------------------------------------------------------

  ViewVC Help
Powered by ViewVC 1.1.20