/[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.33 - (show annotations) (download)
Thu Dec 7 02:27:22 2006 UTC (8 years, 7 months ago) by flameeyes
Branch: MAIN
Changes since 1.32: +7 -3 lines
Use the proper platform include directory for jni (for FreeBSD and Linux at least).

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

  ViewVC Help
Powered by ViewVC 1.1.20