/[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.49 - (show annotations) (download)
Thu Jan 25 11:46:22 2007 UTC (7 years, 6 months ago) by caster
Branch: MAIN
Changes since 1.48: +59 -27 lines
Improve handling --* options order in jar-from, getjar{s}. Fix situation when they are called in
src_test without --build-only (no param shift). Adds --into $dir parameter to jar-from().

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

  ViewVC Help
Powered by ViewVC 1.1.20