/[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.43 - (show annotations) (download)
Mon Jan 15 21:03:24 2007 UTC (7 years, 3 months ago) by betelgeuse
Branch: MAIN
Changes since 1.42: +20 -3 lines
Added --with-dependencies option to jar-from and getjars and made dojar warn when overwriting an existing destination jar.

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

  ViewVC Help
Powered by ViewVC 1.1.20