/[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.87 - (show annotations) (download)
Sun May 27 11:09:11 2007 UTC (7 years, 1 month ago) by betelgeuse
Branch: MAIN
Changes since 1.86: +26 -10 lines
Make ejunit pull in the full deptree to classpath.

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

  ViewVC Help
Powered by ViewVC 1.1.20