/[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.2 - (show annotations) (download)
Sun Jun 25 23:39:53 2006 UTC (8 years ago) by nichoj
Branch: MAIN
Changes since 1.1: +0 -2 lines
Minor tweak to eant

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

  ViewVC Help
Powered by ViewVC 1.1.20