/[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.54 - (show annotations) (download)
Mon Jan 29 18:37:24 2007 UTC (7 years, 10 months ago) by betelgeuse
Branch: MAIN
Changes since 1.53: +2 -1 lines
Fix java-pkg_jar-from that Caster broke with his last --into addition.

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

  ViewVC Help
Powered by ViewVC 1.1.20