/[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.30 - (show annotations) (download)
Sun Dec 3 17:42:53 2006 UTC (7 years, 11 months ago) by betelgeuse
Branch: MAIN
Changes since 1.29: +37 -24 lines
Rewrote java-pkg_getjars to only accept two arguments (--build-only and java-config --classpath-argument). The previous handling for multiple packages was broken. Also documented java-pkg_dojavadoc.

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

  ViewVC Help
Powered by ViewVC 1.1.20