/[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.35 - (hide annotations) (download)
Sun Dec 17 14:48:33 2006 UTC (7 years, 9 months ago) by betelgeuse
Branch: MAIN
Changes since 1.34: +12 -1 lines
Added wrapper for depend-java-query to pass USE flags. This and java-config-2.0.31 will fix bug #156228. This eclass should be changed to depend on 2.0.31 when it is stable.

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

  ViewVC Help
Powered by ViewVC 1.1.20