/[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.5 - (show annotations) (download)
Sat Jul 8 14:20:43 2006 UTC (8 years, 4 months ago) by nelchael
Branch: MAIN
Changes since 1.4: +23 -2 lines
Fixed installing registering multiple jar files.

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

  ViewVC Help
Powered by ViewVC 1.1.20