/[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.1 - (show annotations) (download)
Sat Jun 24 18:36:59 2006 UTC (8 years, 5 months ago) by nichoj
Branch: MAIN
Adding new Java eclasses, and updating old ones.

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 antflags="${antflags} -nouserlib -noclasspath"
1196
1197 if [[ -n ${JAVA_PKG_DEBUG} ]]; then
1198 antflags="${antflags} -debug"
1199 fi
1200
1201 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1202 ant ${antflags} "${@}" || die "eant failed"
1203
1204 }
1205
1206 # ------------------------------------------------------------------------------
1207 # @ebuild-function ejavac
1208 #
1209 # Javac wrapper function. Will use the appropriate compiler, based on
1210 # /etc/java-config/compilers.conf
1211 #
1212 # @param $@ - Arguments to be passed to the compiler
1213 # ------------------------------------------------------------------------------
1214 ejavac() {
1215 debug-print-function ${FUNCNAME} $*
1216
1217 local compiler_executable=$(java-pkg_get-javac)
1218
1219 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}"
1220 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed"
1221 }
1222
1223 # ------------------------------------------------------------------------------
1224 # @ebuild-function java-pkg_filter-compiler
1225 #
1226 # Used to prevent the use of some compilers. Should be used in src_compile.
1227 # Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
1228 #
1229 # @param $@ - compilers to filter
1230 # ------------------------------------------------------------------------------
1231 java-pkg_filter-compiler() {
1232 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@"
1233 }
1234
1235 # ------------------------------------------------------------------------------
1236 # @ebuild-function use_doc
1237 #
1238 # Helper function for getting ant to build javadocs. If the user has USE=doc,
1239 # then 'javadoc' or the argument are returned. Otherwise, there is no return.
1240 #
1241 # The output of this should be passed to ant.
1242 #
1243 # Example: build javadocs by calling 'javadoc' target
1244 # eant $(use_doc)
1245 # Example: build javadocs by calling 'apidoc' target
1246 # eant $(use_doc apidoc)
1247 #
1248 # @param $@ - Option value to return. Defaults to 'javadoc'
1249 # @return string - Name of the target to create javadocs
1250 # ------------------------------------------------------------------------------
1251 use_doc() {
1252 use doc && echo ${@:-javadoc}
1253 }
1254
1255 # ------------------------------------------------------------------------------
1256 # @section-end build
1257 # ------------------------------------------------------------------------------
1258
1259 # ------------------------------------------------------------------------------
1260 # @section-begin internal
1261 # @section-summary Internal functions
1262 #
1263 # Do __NOT__ use any of these from an ebuild! These are only to be used from
1264 # within the java eclasses.
1265 # ------------------------------------------------------------------------------
1266
1267 # -----------------------------------------------------------------------------
1268 # @function-internal java-pkg_init
1269 #
1270 # The purpose of this function, as the name might imply, is to initialize the
1271 # Java environment. It ensures that that there aren't any environment variables
1272 # that'll muss things up. It initializes some variables, which are used
1273 # internally. And most importantly, it'll switch the VM if necessary.
1274 #
1275 # This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will
1276 # call it during each of the phases of the merge process.
1277 #
1278 # -----------------------------------------------------------------------------
1279 java-pkg_init() {
1280 unset JAVAC
1281 unset JAVA_HOME
1282 java-pkg_init_paths_
1283 java-pkg_switch-vm
1284 PATH=${JAVA_HOME}/bin:${PATH}
1285
1286 # TODO we will probably want to set JAVAC and JAVACFLAGS
1287
1288 # Do some QA checks
1289 java-pkg_check-jikes
1290
1291 # When users have crazy classpaths some packages can fail to compile.
1292 # and everything should work with empty CLASSPATH.
1293 # This also helps prevent unexpected dependencies on random things
1294 # from the CLASSPATH.
1295 unset CLASSPATH
1296 }
1297
1298 # ------------------------------------------------------------------------------
1299 # @function-internal java-pkg-init-compiler_
1300 #
1301 # This function attempts to figure out what compiler should be used. It does
1302 # this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
1303 # COMPILERS variable defined there.
1304 # This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
1305 #
1306 # It will go through the list of compilers, and verify that it supports the
1307 # target and source that are needed. If it is not suitable, then the next
1308 # compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
1309 # isn't done.
1310 #
1311 # Once the which compiler to use has been figured out, it is set to
1312 # GENTOO_COMPILER.
1313 #
1314 # If you hadn't guessed, JAVA_PKG_FORCE_COMPILER is for testing only.
1315 #
1316 # If the user doesn't defined anything in JAVA_PKG_COMPILERS_CONF, or no
1317 # suitable compiler was found there, then the default is to use javac provided
1318 # by the current VM.
1319 #
1320 #
1321 # @return name of the compiler to use
1322 # ------------------------------------------------------------------------------
1323 java-pkg_init-compiler_() {
1324 debug-print-function ${FUNCNAME} $*
1325
1326 if [[ -n ${GENTOO_COMPILER} ]]; then
1327 debug-print "GENTOO_COMPILER already set"
1328 return
1329 fi
1330
1331 local compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
1332 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
1333
1334 # Figure out if we should announce what compiler we're using
1335 local compiler
1336 for compiler in ${compilers}; do
1337 debug-print "Checking ${compiler}..."
1338 # javac should always be alright
1339 if [[ ${compiler} = "javac" ]]; then
1340 debug-print "Found javac... breaking"
1341 export GENTOO_COMPILER="javac"
1342 break
1343 fi
1344
1345 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
1346 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1347 einfo "Filtering ${compiler}"
1348 continue
1349 fi
1350 fi
1351
1352 # for non-javac, we need to make sure it supports the right target and
1353 # source
1354 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1355 if [[ -f ${compiler_env} ]]; then
1356 local desired_target="$(java-pkg_get-target)"
1357 local desired_source="$(java-pkg_get-source)"
1358
1359
1360 # Verify that the compiler supports target
1361 local supported_target=$(source ${compiler_env} 1>/dev/null 2>&1; echo ${SUPPORTED_TARGET})
1362 if ! has ${desired_target} ${supported_target}; then
1363 ewarn "${compiler} does not support -target ${desired_target}, skipping"
1364 continue
1365 fi
1366
1367 # -source was introduced in 1.3, so only check 1.3 and on
1368 if version_is_at_least "${desired_soure}" "1.3"; then
1369 # Verify that the compiler supports source
1370 local supported_source=$(source ${compiler_env} 1>/dev/null 2>&1; echo ${SUPPORTED_SOURCE})
1371 if ! has ${desired_source} ${supported_source}; then
1372 ewarn "${compiler} does not support -source ${desired_source}, skipping"
1373 continue
1374 fi
1375 fi
1376
1377 # if you get here, then the compiler should be good to go
1378 export GENTOO_COMPILER="${compiler}"
1379 break
1380 else
1381 ewarn "Could not find configuration for ${compiler}, skipping"
1382 ewarn "Perhaps it is not installed?"
1383 continue
1384 fi
1385 done
1386
1387 # If it hasn't been defined already, default to javac
1388 if [[ -z ${GENTOO_COMPILER} ]]; then
1389 if [[ -n ${compilers} ]]; then
1390 einfo "No suitable compiler found: defaulting javac for compilation"
1391 else
1392 # probably don't need to notify users about the default.
1393 :;#einfo "Defaulting to javac for compilation"
1394 fi
1395 export GENTOO_COMPILER=javac
1396 else
1397 einfo "Using ${GENTOO_COMPILER} for compilation"
1398 fi
1399
1400 }
1401
1402 # ------------------------------------------------------------------------------
1403 # @internal-function init_paths_
1404 #
1405 # Initializes some variables that will be used. These variables are mostly used
1406 # to determine where things will eventually get installed.
1407 # ------------------------------------------------------------------------------
1408 java-pkg_init_paths_() {
1409 debug-print-function ${FUNCNAME} $*
1410
1411 local pkg_name
1412 if [[ "$SLOT" == "0" ]] ; then
1413 JAVA_PKG_NAME="${PN}"
1414 else
1415 JAVA_PKG_NAME="${PN}-${SLOT}"
1416 fi
1417
1418 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}"
1419 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/"
1420 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env"
1421
1422 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib"
1423 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}"
1424 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps"
1425
1426
1427 # TODO maybe only print once?
1428 debug-print "JAVA_PKG_SHAREPATH: ${JAVA_PKG_SHAREPATH}"
1429 debug-print "JAVA_PKG_ENV: ${JAVA_PKG_ENV}"
1430 debug-print "JAVA_PKG_JARDEST: ${JAVA_PKG_JARDEST}"
1431 debug-print "JAVA_PKG_LIBDEST: ${JAVA_PKG_LIBDEST}"
1432 debug-print "JAVA_PKG_WARDEST: ${JAVA_PKG_WARDEST}"
1433 }
1434
1435 # ------------------------------------------------------------------------------
1436 # @internal-function java-pkg_do_write_
1437 #
1438 # Writes the package.env out to disk.
1439 #
1440 # ------------------------------------------------------------------------------
1441 # TODO change to do-write, to match everything else
1442 java-pkg_do_write_() {
1443 # Create directory for package.env
1444 dodir "${JAVA_PKG_SHAREPATH}"
1445 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then
1446 # Create package.env
1447 (
1448 echo "DESCRIPTION=\"${DESCRIPTION}\""
1449 echo "GENERATION=\"2\""
1450
1451 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
1452 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1453 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1454 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\""
1455 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1456 ) > "${JAVA_PKG_ENV}"
1457
1458 # register target/source
1459 local target="$(java-pkg_get-target)"
1460 local source="$(java-pkg_get-source)"
1461 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
1462 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
1463
1464 # register javadoc info
1465 [[ -n ${JAVADOC_PATH} ]] && echo "JAVADOC_PATH=\"${JAVADOC_PATH}\"" \
1466 >> ${JAVA_PKG_ENV}
1467 # register source archives
1468 [[ -n ${JAVA_SOURCES} ]] && echo "JAVA_SOURCES=\"${JAVA_SOURCES}\"" \
1469 >> ${JAVA_PKG_ENV}
1470
1471
1472 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
1473 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
1474
1475 # Strip unnecessary leading and trailing colons
1476 # TODO try to cleanup if possible
1477 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
1478 fi
1479 }
1480
1481
1482 # ------------------------------------------------------------------------------
1483 # @internal-function java-pkg_record-jar_
1484 #
1485 # Record a dependency to the package.env
1486 #
1487 # ------------------------------------------------------------------------------
1488 JAVA_PKG_DEPEND="${T}/java-pkg-depend"
1489
1490 java-pkg_record-jar_() {
1491 debug-print-function ${FUNCNAME} $*
1492
1493 local pkg=${1} jar=${2} append
1494 if [[ -z "${jar}" ]]; then
1495 append="${pkg}"
1496 else
1497 append="$(basename ${jar})@${pkg}"
1498 fi
1499
1500 echo ${append} >> ${JAVA_PKG_DEPEND}
1501 }
1502
1503 # ------------------------------------------------------------------------------
1504 # @internal-function java-pkg_append_
1505 #
1506 # Appends a value to a variable
1507 #
1508 # Example: java-pkg_append_ CLASSPATH foo.jar
1509 # @param $1 variable name to modify
1510 # @param $2 value to append
1511 # ------------------------------------------------------------------------------
1512 java-pkg_append_() {
1513 debug-print-function ${FUNCNAME} $*
1514
1515 local var="${1}" value="${2}"
1516 if [[ -z "${!var}" ]] ; then
1517 export ${var}="${value}"
1518 else
1519 local oldIFS=${IFS} cur haveit
1520 IFS=':'
1521 for cur in ${!var}; do
1522 if [[ ${cur} == ${value} ]]; then
1523 haveit="yes"
1524 break
1525 fi
1526 done
1527 [[ -z ${haveit} ]] && export ${var}="${!var}:${value}"
1528 IFS=${oldIFS}
1529 fi
1530 }
1531
1532 # ------------------------------------------------------------------------------
1533 # @internal-function java-pkg_expand_dir_
1534 #
1535 # Gets the full path of the file/directory's parent.
1536 # @param $1 - file/directory to find parent directory for
1537 # @return - path to $1's parent directory
1538 # ------------------------------------------------------------------------------
1539 java-pkg_expand_dir_() {
1540 pushd "$(dirname "${1}")" >/dev/null 2>&1
1541 pwd
1542 popd >/dev/null 2>&1
1543 }
1544
1545 # ------------------------------------------------------------------------------
1546 # @internal-function java-pkg_func-exists
1547 #
1548 # Does the indicated function exist?
1549 #
1550 # @return 0 - function is declared
1551 # @return 1 - function is undeclared
1552 # ------------------------------------------------------------------------------
1553 java-pkg_func-exists() {
1554 if [[ -n "$(declare -f ${1})" ]]; then
1555 return 0
1556 else
1557 return 1
1558 fi
1559 }
1560
1561 # ------------------------------------------------------------------------------
1562 # @internal-function java-pkg_setup-vm
1563 #
1564 # Sets up the environment for a specific VM
1565 #
1566 # ------------------------------------------------------------------------------
1567 java-pkg_setup-vm() {
1568 debug-print-function ${FUNCNAME} $*
1569
1570 local vendor="$(java-pkg_get-vm-vendor)"
1571 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge 1 5; then
1572 addpredict "/dev/random"
1573 elif [[ "${vendor}" == "ibm" ]]; then
1574 addpredict "/proc/self/maps"
1575 addpredict "/proc/cpuinfo"
1576 export LANG="C" LC_ALL="C"
1577 elif [[ "${vendor}" == "jrockit" ]]; then
1578 addpredict "/proc/cpuinfo"
1579 fi
1580 }
1581
1582 # ------------------------------------------------------------------------------
1583 # @internal-function java-pkg_needs-vm
1584 #
1585 # Does the current package depend on virtual/jdk?
1586 #
1587 # @return 0 - Package depends on virtual/jdk
1588 # @return 1 - Package does not depend on virtual/jdk
1589 # ------------------------------------------------------------------------------
1590 java-pkg_needs-vm() {
1591 debug-print-function ${FUNCNAME} $*
1592
1593 if [[ -n "$(echo ${DEPEND} | sed -e '\:virtual/jdk:!d')" ]]; then
1594 return 0
1595 fi
1596
1597 return 1
1598 }
1599
1600 # ------------------------------------------------------------------------------
1601 # @internal-function java-pkg_get-current-vm
1602 #
1603 # @return - The current VM being used
1604 # ------------------------------------------------------------------------------
1605 java-pkg_get-current-vm() {
1606 java-config -f
1607 }
1608
1609 # ------------------------------------------------------------------------------
1610 # @internal-function java-pkg_get-vm-vendor
1611 #
1612 # @return - The vendor of the current VM
1613 # ------------------------------------------------------------------------------
1614 java-pkg_get-vm-vendor() {
1615 debug-print-function ${FUNCNAME} $*
1616
1617 local vm="$(java-pkg_get-current-vm)"
1618 vm="${vm/-*/}"
1619 echo "${vm}"
1620 }
1621
1622 # ------------------------------------------------------------------------------
1623 # @internal-function java-pkg_get-vm-version
1624 #
1625 # @return - The version of the current VM
1626 # ------------------------------------------------------------------------------
1627 java-pkg_get-vm-version() {
1628 debug-print-function ${FUNCNAME} $*
1629
1630 java-pkg_get-current-vm | sed -e "s/.*-\([0-9.]\+\).*/\1/"
1631 }
1632
1633 # ------------------------------------------------------------------------------
1634 # @internal-function java-pkg_switch-vm
1635 #
1636 # Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1637 # verify that the current VM is sufficient.
1638 # Setup the environment for the VM being used.
1639 # ------------------------------------------------------------------------------
1640 java-pkg_switch-vm() {
1641 if java-pkg_needs-vm; then
1642 # Use the VM specified by JAVA_PKG_FORCE_VM
1643 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then
1644 # If you're forcing the VM, I hope you know what your doing...
1645 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1646 # if we're allowed to switch the vm...
1647 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1648 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1649 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1650 export GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1651 else
1652 export GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1653 fi
1654 # otherwise just make sure the current VM is sufficient
1655 else
1656 java-pkg_ensure-vm-version-sufficient
1657 fi
1658 debug-print "Using: $(java-config -f)"
1659
1660 java-pkg_setup-vm
1661
1662 export JAVACFLAGS="$(java-pkg_javac-args)"
1663 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
1664
1665 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1666 export JDK_HOME=${JAVA_HOME}
1667
1668 #TODO If you know a better solution let us know.
1669 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1670
1671 local tann="${T}/announced-vm"
1672 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1673 # Add a check for setup/preinst phase... to avoid duplicate outputs
1674 # for when FEATURES=buildpkg
1675 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1676 then
1677 einfo "Using: $(java-config -f)"
1678 [[ ! -f "${tann}" ]] && touch "${tann}"
1679 fi
1680 fi
1681
1682 else
1683 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!"
1684 fi
1685 }
1686
1687 # ------------------------------------------------------------------------------
1688 # @internal-function java-pkg_die
1689 #
1690 # Enhanced die for Java packages, which displays some information that may be
1691 # useful for debugging bugs on bugzilla.
1692 # ------------------------------------------------------------------------------
1693 #register_die_hook java-pkg_die
1694 if ! hasq java-pkg_die ${EBUILD_DEATH_HOOKS}; then
1695 EBUILD_DEATH_HOOKS="${EBUILD_DEATH_HOOKS} java-pkg_die"
1696 fi
1697
1698 java-pkg_die() {
1699 echo "!!! When you file a bug report, please include the following information:" >&2
1700 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2
1701 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2
1702 echo "and of course, the output of emerge --info" >&2
1703 }
1704
1705 # ------------------------------------------------------------------------------
1706 # @section-end internal
1707 # ------------------------------------------------------------------------------
1708
1709 java-pkg_check-phase() {
1710 local phase=${1}
1711 local funcname=${2}
1712 # TODO add check for java-stricter
1713 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
1714 java-pkg_announce-qa-violation \
1715 "${funcname} used outside of src_${phase}"
1716 fi
1717 }
1718
1719 java-pkg_check-versioned-jar() {
1720 local jar=${1}
1721
1722 if [[ ${jar} =~ ${PV} ]]; then
1723 java-pkg_announce-qa-violation "installing versioned jar '${jar}'"
1724 fi
1725 }
1726
1727 java-pkg_check-jikes() {
1728 if hasq jikes ${IUSE}; then
1729 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1730 fi
1731 }
1732
1733 java-pkg_announce-qa-violation() {
1734 if hasq java-strict ${FEATURES}; then
1735 echo "Java QA Notice: $@" >&2
1736 increment-qa-violations
1737 fi
1738 }
1739
1740 increment-qa-violations() {
1741 let "JAVA_PKG_QA_VIOLATIONS+=1"
1742 export JAVA_PKG_QA_VIOLATIONS
1743 }
1744
1745 # ------------------------------------------------------------------------------
1746 # @eclass-end
1747 # ------------------------------------------------------------------------------

  ViewVC Help
Powered by ViewVC 1.1.20