/[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.60 - (show annotations) (download)
Thu Mar 1 13:15:14 2007 UTC (7 years, 5 months ago) by betelgeuse
Branch: MAIN
Changes since 1.59: +10 -1 lines
Fix recording of dependencies to package.env when java-pkg_jar-from is called for multiple packages using commas.

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

  ViewVC Help
Powered by ViewVC 1.1.20