/[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.67 - (show annotations) (download)
Thu Mar 22 03:11:19 2007 UTC (7 years, 3 months ago) by nichoj
Branch: MAIN
Changes since 1.66: +2 -1 lines
Added missing separator for edoc.

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

  ViewVC Help
Powered by ViewVC 1.1.20