/[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.38 - (hide annotations) (download)
Sun Dec 31 19:30:54 2006 UTC (7 years, 3 months ago) by betelgeuse
Branch: MAIN
Changes since 1.37: +12 -8 lines
Made java-pkg_regjar die if called on a directory and improved debugging information.

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.38 # $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.37 2006/12/31 01:39:38 caster 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 betelgeuse 1.38 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
262     [[ -d "${jar}" || -d "${D}${jar}" ]] \
263     && die "Called ${FUNCNAME} on a directory $*"
264 nelchael 1.5 # nelchael: we should strip ${D} in this case too, here's why:
265     # imagine such call:
266     # java-pkg_regjar ${D}/opt/java/*.jar
267     # such call will fall into this case (-e ${jar}) and will
268     # record paths with ${D} in package.env
269     java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
270 nichoj 1.1 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 betelgeuse 1.38 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 nichoj 1.16 if [[ "${1}" = "--build-only" ]]; then
805 betelgeuse 1.30 local build_only="true"
806 nichoj 1.16 shift
807     fi
808    
809 betelgeuse 1.38 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --build-only"
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 #
1190     # @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1191     # ------------------------------------------------------------------------------
1192     java-pkg_get-target() {
1193 caster 1.37 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1194 nichoj 1.1 }
1195    
1196     java-pkg_get-javac() {
1197     debug-print-function ${FUNCNAME} $*
1198    
1199 caster 1.24
1200 nichoj 1.1 local compiler="${GENTOO_COMPILER}"
1201    
1202     local compiler_executable
1203     if [[ "${compiler}" = "javac" ]]; then
1204     # nothing fancy needs to be done for javac
1205     compiler_executable="javac"
1206     else
1207     # for everything else, try to determine from an env file
1208    
1209     local compiler_env="/usr/share/java-config-2/compiler/${compiler}"
1210     if [[ -f ${compiler_env} ]]; then
1211     local old_javac=${JAVAC}
1212     unset JAVAC
1213     # try to get value of JAVAC
1214     compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1215     export JAVAC=${old_javac}
1216    
1217 caster 1.24 if [[ -z ${compiler_executable} ]]; then
1218     echo "JAVAC is empty or undefined in ${compiler_env}"
1219     return 1
1220     fi
1221 betelgeuse 1.19
1222 nichoj 1.1 # check that it's executable
1223     if [[ ! -x ${compiler_executable} ]]; then
1224 caster 1.24 echo "${compiler_executable} doesn't exist, or isn't executable"
1225     return 1
1226 nichoj 1.1 fi
1227     else
1228 caster 1.24 echo "Could not find environment file for ${compiler}"
1229     return 1
1230 nichoj 1.1 fi
1231     fi
1232     echo ${compiler_executable}
1233     }
1234    
1235     # ------------------------------------------------------------------------------
1236 betelgeuse 1.19 # @ebuild-function java-pkg_javac-args
1237 nichoj 1.1 #
1238     # If an ebuild uses javac directly, instead of using ejavac, it should call this
1239     # to know what -source/-target to use.
1240     #
1241     # @return string - arguments to pass to javac, complete with -target and -source
1242     # ------------------------------------------------------------------------------
1243     java-pkg_javac-args() {
1244     debug-print-function ${FUNCNAME} $*
1245    
1246     local want_source="$(java-pkg_get-source)"
1247     local want_target="$(java-pkg_get-target)"
1248    
1249 betelgeuse 1.19 local source_str="-source ${want_source}"
1250 nichoj 1.1 local target_str="-target ${want_target}"
1251    
1252     debug-print "want source: ${want_source}"
1253     debug-print "want target: ${want_target}"
1254    
1255     if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1256 caster 1.24 debug-print "could not find valid -source/-target values for javac"
1257     echo "Could not find valid -source/-target values for javac"
1258     return 1
1259 nichoj 1.1 else
1260     if java-pkg_is-vm-version-ge "1.4"; then
1261     echo "${source_str} ${target_str}"
1262     else
1263     echo "${target_str}"
1264     fi
1265     fi
1266     }
1267    
1268     # TODO document
1269     java-pkg_get-jni-cflags() {
1270     local flags="-I${JAVA_HOME}/include"
1271    
1272 flameeyes 1.33 local platform="linux"
1273     use elibc_FreeBSD && platform="freebsd"
1274    
1275 nichoj 1.10 # TODO do a check that the directories are valid
1276 flameeyes 1.33 flags="${flags} -I${JAVA_HOME}/include/${platform}"
1277 nichoj 1.1
1278     echo ${flags}
1279     }
1280    
1281 nichoj 1.10 java-pkg_ensure-gcj() {
1282     if ! built_with_use sys-devel/gcc gcj ; then
1283     ewarn
1284     ewarn "You must build gcc with the gcj support to build with gcj"
1285     ewarn
1286     ebeep 5
1287     die "No GCJ support found!"
1288     fi
1289     }
1290    
1291 nichoj 1.13 java-pkg_ensure-test() {
1292 betelgeuse 1.34 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \
1293     && hasq test ${IUSE} && ! use test;
1294     then
1295 nichoj 1.13 eerror "You specified FEATURES=test, but USE=test is needed"
1296     eerror "to pull in the additional dependencies for testing"
1297     die "Need USE=test enabled"
1298     fi
1299     }
1300    
1301 nichoj 1.1 # ------------------------------------------------------------------------------
1302     # @section-end helper
1303     # ------------------------------------------------------------------------------
1304    
1305     # ------------------------------------------------------------------------------
1306     # @section-begin build
1307     # @section-summary Build functions
1308     #
1309     # These are some functions for building a package. In particular, it consists of
1310     # wrappers for javac and ant.
1311     # ------------------------------------------------------------------------------
1312    
1313     # ------------------------------------------------------------------------------
1314     # @ebuild-function eant
1315     #
1316     # Ant wrapper function. Will use the appropriate compiler, based on user-defined
1317     # compiler.
1318     #
1319     # ------------------------------------------------------------------------------
1320     eant() {
1321     debug-print-function ${FUNCNAME} $*
1322    
1323 nichoj 1.12 # FIXME get this working
1324     # if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then
1325     # java-pkg_announce-qa-violation \
1326     # "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1327     # fi
1328    
1329 caster 1.36 local antflags="-Dnoget=true"
1330 nichoj 1.1 java-pkg_init-compiler_
1331     local compiler="${GENTOO_COMPILER}"
1332    
1333     local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1334    
1335     local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})"
1336     if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1337     die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1338     fi
1339    
1340     if [[ ${compiler} != "javac" ]]; then
1341 caster 1.36 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1342 nichoj 1.1 # Figure out any extra stuff to put on the classpath for compilers aside
1343     # from javac
1344     # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1345     # java-config -p
1346     local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})"
1347     if [[ -n ${build_compiler_deps} ]]; then
1348     antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1349     fi
1350     fi
1351 nichoj 1.9
1352     if is-java-strict; then
1353     einfo "Disabling system classpath for ant"
1354     antflags="${antflags} -Dbuild.sysclasspath=ignore"
1355     fi
1356 betelgeuse 1.19
1357 nichoj 1.1 if [[ -n ${JAVA_PKG_DEBUG} ]]; then
1358     antflags="${antflags} -debug"
1359     fi
1360 betelgeuse 1.19
1361 nichoj 1.1 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1362     ant ${antflags} "${@}" || die "eant failed"
1363    
1364     }
1365    
1366     # ------------------------------------------------------------------------------
1367     # @ebuild-function ejavac
1368     #
1369 betelgeuse 1.19 # Javac wrapper function. Will use the appropriate compiler, based on
1370 nichoj 1.1 # /etc/java-config/compilers.conf
1371     #
1372     # @param $@ - Arguments to be passed to the compiler
1373     # ------------------------------------------------------------------------------
1374     ejavac() {
1375     debug-print-function ${FUNCNAME} $*
1376    
1377 caster 1.24 java-pkg_init-compiler_
1378 nichoj 1.1
1379 caster 1.24 local compiler_executable
1380     compiler_executable=$(java-pkg_get-javac)
1381     if [[ ${?} != 0 ]]; then
1382     eerror "There was a problem determining compiler: ${compiler_executable}"
1383     die "get-javac failed"
1384     fi
1385    
1386     local javac_args
1387     javac_args="$(java-pkg_javac-args)"
1388     if [[ ${?} != 0 ]]; then
1389     eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
1390     die "java-pkg_javac-args failed"
1391     fi
1392    
1393     [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1394     ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1395 nichoj 1.1 }
1396    
1397     # ------------------------------------------------------------------------------
1398     # @ebuild-function java-pkg_filter-compiler
1399 betelgeuse 1.19 #
1400 nichoj 1.1 # Used to prevent the use of some compilers. Should be used in src_compile.
1401     # Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
1402     #
1403     # @param $@ - compilers to filter
1404     # ------------------------------------------------------------------------------
1405     java-pkg_filter-compiler() {
1406     JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@"
1407     }
1408    
1409     # ------------------------------------------------------------------------------
1410 nichoj 1.8 # @ebuild-function java-pkg_force-compiler
1411     #
1412     # Used to force the use of particular compilers. Should be used in src_compile.
1413     # A common use of this would be to force ecj-3.1 to be used on amd64, to avoid
1414     # OutOfMemoryErrors that may come up.
1415     #
1416     # @param $@ - compilers to force
1417     # ------------------------------------------------------------------------------
1418     java-pkg_force-compiler() {
1419     JAVA_PKG_FORCE_COMPILER="$@"
1420     }
1421    
1422     # ------------------------------------------------------------------------------
1423 nichoj 1.1 # @ebuild-function use_doc
1424     #
1425     # Helper function for getting ant to build javadocs. If the user has USE=doc,
1426     # then 'javadoc' or the argument are returned. Otherwise, there is no return.
1427 betelgeuse 1.19 #
1428 nichoj 1.1 # The output of this should be passed to ant.
1429     #
1430     # Example: build javadocs by calling 'javadoc' target
1431     # eant $(use_doc)
1432     # Example: build javadocs by calling 'apidoc' target
1433     # eant $(use_doc apidoc)
1434     #
1435     # @param $@ - Option value to return. Defaults to 'javadoc'
1436     # @return string - Name of the target to create javadocs
1437     # ------------------------------------------------------------------------------
1438     use_doc() {
1439     use doc && echo ${@:-javadoc}
1440     }
1441    
1442 betelgeuse 1.38
1443 nichoj 1.1 # ------------------------------------------------------------------------------
1444     # @section-end build
1445     # ------------------------------------------------------------------------------
1446 betelgeuse 1.19
1447 nichoj 1.1 # ------------------------------------------------------------------------------
1448     # @section-begin internal
1449 betelgeuse 1.19 # @section-summary Internal functions
1450 nichoj 1.1 #
1451     # Do __NOT__ use any of these from an ebuild! These are only to be used from
1452     # within the java eclasses.
1453     # ------------------------------------------------------------------------------
1454    
1455     # -----------------------------------------------------------------------------
1456     # @function-internal java-pkg_init
1457 betelgeuse 1.19 #
1458 nichoj 1.1 # The purpose of this function, as the name might imply, is to initialize the
1459     # Java environment. It ensures that that there aren't any environment variables
1460     # that'll muss things up. It initializes some variables, which are used
1461     # internally. And most importantly, it'll switch the VM if necessary.
1462     #
1463     # This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will
1464     # call it during each of the phases of the merge process.
1465     #
1466     # -----------------------------------------------------------------------------
1467     java-pkg_init() {
1468     unset JAVAC
1469     unset JAVA_HOME
1470     java-pkg_init_paths_
1471     java-pkg_switch-vm
1472     PATH=${JAVA_HOME}/bin:${PATH}
1473    
1474     # TODO we will probably want to set JAVAC and JAVACFLAGS
1475    
1476     # Do some QA checks
1477     java-pkg_check-jikes
1478    
1479 betelgeuse 1.19 # When users have crazy classpaths some packages can fail to compile.
1480 nichoj 1.1 # and everything should work with empty CLASSPATH.
1481     # This also helps prevent unexpected dependencies on random things
1482     # from the CLASSPATH.
1483 betelgeuse 1.19 unset CLASSPATH
1484 nichoj 1.1 }
1485    
1486     # ------------------------------------------------------------------------------
1487     # @function-internal java-pkg-init-compiler_
1488     #
1489     # This function attempts to figure out what compiler should be used. It does
1490 betelgeuse 1.19 # this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
1491 nichoj 1.1 # COMPILERS variable defined there.
1492     # This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
1493 betelgeuse 1.19 #
1494 nichoj 1.1 # It will go through the list of compilers, and verify that it supports the
1495     # target and source that are needed. If it is not suitable, then the next
1496     # compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
1497     # isn't done.
1498     #
1499     # Once the which compiler to use has been figured out, it is set to
1500     # GENTOO_COMPILER.
1501     #
1502     # If you hadn't guessed, JAVA_PKG_FORCE_COMPILER is for testing only.
1503     #
1504     # If the user doesn't defined anything in JAVA_PKG_COMPILERS_CONF, or no
1505     # suitable compiler was found there, then the default is to use javac provided
1506     # by the current VM.
1507     #
1508     #
1509     # @return name of the compiler to use
1510     # ------------------------------------------------------------------------------
1511     java-pkg_init-compiler_() {
1512     debug-print-function ${FUNCNAME} $*
1513    
1514     if [[ -n ${GENTOO_COMPILER} ]]; then
1515     debug-print "GENTOO_COMPILER already set"
1516     return
1517     fi
1518    
1519 nichoj 1.3 local compilers;
1520     if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1521     compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
1522     else
1523     compilers=${JAVA_PKG_FORCE_COMPILER}
1524     fi
1525 betelgeuse 1.19
1526 nichoj 1.1 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
1527    
1528     # Figure out if we should announce what compiler we're using
1529     local compiler
1530     for compiler in ${compilers}; do
1531     debug-print "Checking ${compiler}..."
1532     # javac should always be alright
1533     if [[ ${compiler} = "javac" ]]; then
1534     debug-print "Found javac... breaking"
1535     export GENTOO_COMPILER="javac"
1536     break
1537     fi
1538 betelgeuse 1.19
1539 nichoj 1.1 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
1540     if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1541     einfo "Filtering ${compiler}"
1542     continue
1543     fi
1544     fi
1545 betelgeuse 1.19
1546 nichoj 1.1 # for non-javac, we need to make sure it supports the right target and
1547     # source
1548     local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1549     if [[ -f ${compiler_env} ]]; then
1550     local desired_target="$(java-pkg_get-target)"
1551     local desired_source="$(java-pkg_get-source)"
1552    
1553    
1554     # Verify that the compiler supports target
1555     local supported_target=$(source ${compiler_env} 1>/dev/null 2>&1; echo ${SUPPORTED_TARGET})
1556     if ! has ${desired_target} ${supported_target}; then
1557     ewarn "${compiler} does not support -target ${desired_target}, skipping"
1558     continue
1559     fi
1560    
1561     # -source was introduced in 1.3, so only check 1.3 and on
1562     if version_is_at_least "${desired_soure}" "1.3"; then
1563     # Verify that the compiler supports source
1564     local supported_source=$(source ${compiler_env} 1>/dev/null 2>&1; echo ${SUPPORTED_SOURCE})
1565     if ! has ${desired_source} ${supported_source}; then
1566     ewarn "${compiler} does not support -source ${desired_source}, skipping"
1567     continue
1568     fi
1569     fi
1570    
1571     # if you get here, then the compiler should be good to go
1572     export GENTOO_COMPILER="${compiler}"
1573     break
1574     else
1575     ewarn "Could not find configuration for ${compiler}, skipping"
1576     ewarn "Perhaps it is not installed?"
1577     continue
1578     fi
1579     done
1580    
1581     # If it hasn't been defined already, default to javac
1582     if [[ -z ${GENTOO_COMPILER} ]]; then
1583     if [[ -n ${compilers} ]]; then
1584     einfo "No suitable compiler found: defaulting javac for compilation"
1585     else
1586     # probably don't need to notify users about the default.
1587     :;#einfo "Defaulting to javac for compilation"
1588     fi
1589     export GENTOO_COMPILER=javac
1590     else
1591     einfo "Using ${GENTOO_COMPILER} for compilation"
1592     fi
1593    
1594     }
1595    
1596     # ------------------------------------------------------------------------------
1597     # @internal-function init_paths_
1598     #
1599     # Initializes some variables that will be used. These variables are mostly used
1600     # to determine where things will eventually get installed.
1601     # ------------------------------------------------------------------------------
1602     java-pkg_init_paths_() {
1603     debug-print-function ${FUNCNAME} $*
1604    
1605     local pkg_name
1606     if [[ "$SLOT" == "0" ]] ; then
1607     JAVA_PKG_NAME="${PN}"
1608     else
1609     JAVA_PKG_NAME="${PN}-${SLOT}"
1610     fi
1611    
1612     JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}"
1613     JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/"
1614     JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env"
1615    
1616     [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib"
1617     [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}"
1618     [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps"
1619    
1620    
1621     # TODO maybe only print once?
1622     debug-print "JAVA_PKG_SHAREPATH: ${JAVA_PKG_SHAREPATH}"
1623     debug-print "JAVA_PKG_ENV: ${JAVA_PKG_ENV}"
1624     debug-print "JAVA_PKG_JARDEST: ${JAVA_PKG_JARDEST}"
1625     debug-print "JAVA_PKG_LIBDEST: ${JAVA_PKG_LIBDEST}"
1626     debug-print "JAVA_PKG_WARDEST: ${JAVA_PKG_WARDEST}"
1627     }
1628    
1629     # ------------------------------------------------------------------------------
1630     # @internal-function java-pkg_do_write_
1631     #
1632     # Writes the package.env out to disk.
1633     #
1634     # ------------------------------------------------------------------------------
1635     # TODO change to do-write, to match everything else
1636     java-pkg_do_write_() {
1637 betelgeuse 1.28 java-pkg_init_paths_
1638 nichoj 1.1 # Create directory for package.env
1639     dodir "${JAVA_PKG_SHAREPATH}"
1640     if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then
1641     # Create package.env
1642     (
1643     echo "DESCRIPTION=\"${DESCRIPTION}\""
1644     echo "GENERATION=\"2\""
1645    
1646     [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
1647     [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1648     [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1649     [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\""
1650     echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1651     ) > "${JAVA_PKG_ENV}"
1652 betelgeuse 1.19
1653 nichoj 1.1 # register target/source
1654     local target="$(java-pkg_get-target)"
1655     local source="$(java-pkg_get-source)"
1656     [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
1657     [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
1658    
1659     # register javadoc info
1660     [[ -n ${JAVADOC_PATH} ]] && echo "JAVADOC_PATH=\"${JAVADOC_PATH}\"" \
1661     >> ${JAVA_PKG_ENV}
1662     # register source archives
1663     [[ -n ${JAVA_SOURCES} ]] && echo "JAVA_SOURCES=\"${JAVA_SOURCES}\"" \
1664     >> ${JAVA_PKG_ENV}
1665    
1666    
1667     echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
1668     [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
1669    
1670     # Strip unnecessary leading and trailing colons
1671     # TODO try to cleanup if possible
1672     sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
1673     fi
1674     }
1675    
1676     # ------------------------------------------------------------------------------
1677     # @internal-function java-pkg_record-jar_
1678     #
1679     # Record a dependency to the package.env
1680     #
1681     # ------------------------------------------------------------------------------
1682     JAVA_PKG_DEPEND="${T}/java-pkg-depend"
1683    
1684     java-pkg_record-jar_() {
1685     debug-print-function ${FUNCNAME} $*
1686    
1687     local pkg=${1} jar=${2} append
1688     if [[ -z "${jar}" ]]; then
1689     append="${pkg}"
1690     else
1691     append="$(basename ${jar})@${pkg}"
1692     fi
1693    
1694     echo ${append} >> ${JAVA_PKG_DEPEND}
1695     }
1696    
1697     # ------------------------------------------------------------------------------
1698     # @internal-function java-pkg_append_
1699     #
1700     # Appends a value to a variable
1701     #
1702     # Example: java-pkg_append_ CLASSPATH foo.jar
1703     # @param $1 variable name to modify
1704     # @param $2 value to append
1705     # ------------------------------------------------------------------------------
1706     java-pkg_append_() {
1707     debug-print-function ${FUNCNAME} $*
1708    
1709     local var="${1}" value="${2}"
1710     if [[ -z "${!var}" ]] ; then
1711     export ${var}="${value}"
1712     else
1713     local oldIFS=${IFS} cur haveit
1714     IFS=':'
1715     for cur in ${!var}; do
1716     if [[ ${cur} == ${value} ]]; then
1717     haveit="yes"
1718     break
1719     fi
1720     done
1721     [[ -z ${haveit} ]] && export ${var}="${!var}:${value}"
1722     IFS=${oldIFS}
1723     fi
1724     }
1725    
1726     # ------------------------------------------------------------------------------
1727     # @internal-function java-pkg_expand_dir_
1728 betelgeuse 1.19 #
1729 nichoj 1.1 # Gets the full path of the file/directory's parent.
1730     # @param $1 - file/directory to find parent directory for
1731     # @return - path to $1's parent directory
1732     # ------------------------------------------------------------------------------
1733     java-pkg_expand_dir_() {
1734     pushd "$(dirname "${1}")" >/dev/null 2>&1
1735     pwd
1736     popd >/dev/null 2>&1
1737     }
1738    
1739     # ------------------------------------------------------------------------------
1740     # @internal-function java-pkg_func-exists
1741     #
1742     # Does the indicated function exist?
1743     #
1744     # @return 0 - function is declared
1745     # @return 1 - function is undeclared
1746     # ------------------------------------------------------------------------------
1747     java-pkg_func-exists() {
1748     if [[ -n "$(declare -f ${1})" ]]; then
1749     return 0
1750     else
1751     return 1
1752     fi
1753     }
1754    
1755     # ------------------------------------------------------------------------------
1756     # @internal-function java-pkg_setup-vm
1757     #
1758     # Sets up the environment for a specific VM
1759     #
1760     # ------------------------------------------------------------------------------
1761     java-pkg_setup-vm() {
1762     debug-print-function ${FUNCNAME} $*
1763    
1764     local vendor="$(java-pkg_get-vm-vendor)"
1765 caster 1.23 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1766 nichoj 1.1 addpredict "/dev/random"
1767     elif [[ "${vendor}" == "ibm" ]]; then
1768     addpredict "/proc/self/maps"
1769     addpredict "/proc/cpuinfo"
1770     export LANG="C" LC_ALL="C"
1771     elif [[ "${vendor}" == "jrockit" ]]; then
1772     addpredict "/proc/cpuinfo"
1773     fi
1774     }
1775    
1776     # ------------------------------------------------------------------------------
1777     # @internal-function java-pkg_needs-vm
1778     #
1779     # Does the current package depend on virtual/jdk?
1780     #
1781     # @return 0 - Package depends on virtual/jdk
1782     # @return 1 - Package does not depend on virtual/jdk
1783     # ------------------------------------------------------------------------------
1784     java-pkg_needs-vm() {
1785     debug-print-function ${FUNCNAME} $*
1786    
1787     if [[ -n "$(echo ${DEPEND} | sed -e '\:virtual/jdk:!d')" ]]; then
1788     return 0
1789     fi
1790    
1791     return 1
1792     }
1793    
1794     # ------------------------------------------------------------------------------
1795     # @internal-function java-pkg_get-current-vm
1796     #
1797     # @return - The current VM being used
1798     # ------------------------------------------------------------------------------
1799     java-pkg_get-current-vm() {
1800     java-config -f
1801     }
1802    
1803     # ------------------------------------------------------------------------------
1804     # @internal-function java-pkg_get-vm-vendor
1805     #
1806     # @return - The vendor of the current VM
1807     # ------------------------------------------------------------------------------
1808     java-pkg_get-vm-vendor() {
1809     debug-print-function ${FUNCNAME} $*
1810    
1811     local vm="$(java-pkg_get-current-vm)"
1812     vm="${vm/-*/}"
1813     echo "${vm}"
1814     }
1815    
1816     # ------------------------------------------------------------------------------
1817     # @internal-function java-pkg_get-vm-version
1818     #
1819     # @return - The version of the current VM
1820     # ------------------------------------------------------------------------------
1821     java-pkg_get-vm-version() {
1822     debug-print-function ${FUNCNAME} $*
1823    
1824 caster 1.22 java-config -g PROVIDES_VERSION
1825 nichoj 1.1 }
1826    
1827     # ------------------------------------------------------------------------------
1828     # @internal-function java-pkg_switch-vm
1829     #
1830 betelgeuse 1.19 # Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1831 nichoj 1.1 # verify that the current VM is sufficient.
1832     # Setup the environment for the VM being used.
1833     # ------------------------------------------------------------------------------
1834     java-pkg_switch-vm() {
1835 betelgeuse 1.38 debug-print-function ${FUNCNAME} $*
1836    
1837 nichoj 1.1 if java-pkg_needs-vm; then
1838     # Use the VM specified by JAVA_PKG_FORCE_VM
1839 betelgeuse 1.38 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1840 nichoj 1.1 # If you're forcing the VM, I hope you know what your doing...
1841 betelgeuse 1.38 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1842 nichoj 1.1 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1843     # if we're allowed to switch the vm...
1844     elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1845     debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1846     if [[ -n ${JAVA_PKG_VNEED} ]]; then
1847 caster 1.24 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1848 nichoj 1.1 else
1849 caster 1.24 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1850     fi
1851     if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
1852 caster 1.32 eerror "Unable to determine VM for building from dependencies:"
1853 caster 1.24 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
1854     echo "VNEED: ${JAVA_PKG_VNEED}"
1855 caster 1.32 die "Failed to determine VM for building."
1856 caster 1.24 else
1857     export GENTOO_VM
1858 nichoj 1.1 fi
1859     # otherwise just make sure the current VM is sufficient
1860     else
1861     java-pkg_ensure-vm-version-sufficient
1862     fi
1863     debug-print "Using: $(java-config -f)"
1864 betelgeuse 1.19
1865 nichoj 1.1 java-pkg_setup-vm
1866    
1867 nichoj 1.4 export JAVA=$(java-config --java)
1868     export JAVAC=$(java-config --javac)
1869 caster 1.24 JAVACFLAGS="$(java-pkg_javac-args)"
1870     if [[ ${?} != 0 ]]; then
1871     eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
1872     die "java-pkg_javac-args failed"
1873     fi
1874     [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
1875     export JAVACFLAGS
1876 nichoj 1.1
1877     export JAVA_HOME="$(java-config -g JAVA_HOME)"
1878     export JDK_HOME=${JAVA_HOME}
1879    
1880     #TODO If you know a better solution let us know.
1881     java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1882 betelgeuse 1.19
1883 nichoj 1.1 local tann="${T}/announced-vm"
1884     if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1885     # Add a check for setup/preinst phase... to avoid duplicate outputs
1886     # for when FEATURES=buildpkg
1887     if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1888     then
1889     einfo "Using: $(java-config -f)"
1890     [[ ! -f "${tann}" ]] && touch "${tann}"
1891     fi
1892     fi
1893    
1894     else
1895     [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!"
1896     fi
1897     }
1898    
1899     # ------------------------------------------------------------------------------
1900     # @internal-function java-pkg_die
1901     #
1902     # Enhanced die for Java packages, which displays some information that may be
1903     # useful for debugging bugs on bugzilla.
1904     # ------------------------------------------------------------------------------
1905     #register_die_hook java-pkg_die
1906     if ! hasq java-pkg_die ${EBUILD_DEATH_HOOKS}; then
1907     EBUILD_DEATH_HOOKS="${EBUILD_DEATH_HOOKS} java-pkg_die"
1908     fi
1909    
1910     java-pkg_die() {
1911     echo "!!! When you file a bug report, please include the following information:" >&2
1912     echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2
1913     echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2
1914     echo "and of course, the output of emerge --info" >&2
1915     }
1916    
1917 nichoj 1.7
1918     # TODO document
1919     # List jars in the source directory, ${S}
1920     java-pkg_jar-list() {
1921     if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
1922     einfo "Linked Jars"
1923     find "${S}" -type l -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1924     einfo "Jars"
1925     find "${S}" -type f -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1926     einfo "Classes"
1927     find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1928     fi
1929     }
1930    
1931     # TODO document
1932     # Verify that the classes were compiled for the right source / target
1933     java-pkg_verify-classes() {
1934     ebegin "Verifying java class versions"
1935     #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1936 betelgeuse 1.19 class-version-verify.py -t $(java-pkg_get-target) -r ${D}
1937 nichoj 1.7 result=$?
1938     eend ${result}
1939     if [[ ${result} == 0 ]]; then
1940     einfo "All good"
1941     else
1942     ewarn "Possible problem"
1943     die "Bad class files found"
1944     fi
1945     }
1946    
1947 nichoj 1.1 # ------------------------------------------------------------------------------
1948     # @section-end internal
1949     # ------------------------------------------------------------------------------
1950    
1951     java-pkg_check-phase() {
1952     local phase=${1}
1953     local funcname=${2}
1954 nichoj 1.9 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then
1955 nichoj 1.1 java-pkg_announce-qa-violation \
1956     "${funcname} used outside of src_${phase}"
1957     fi
1958     }
1959    
1960     java-pkg_check-versioned-jar() {
1961     local jar=${1}
1962    
1963     if [[ ${jar} =~ ${PV} ]]; then
1964     java-pkg_announce-qa-violation "installing versioned jar '${jar}'"
1965     fi
1966     }
1967    
1968     java-pkg_check-jikes() {
1969     if hasq jikes ${IUSE}; then
1970     java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1971     fi
1972     }
1973    
1974     java-pkg_announce-qa-violation() {
1975 nichoj 1.9 if is-java-strict; then
1976 nichoj 1.1 echo "Java QA Notice: $@" >&2
1977     increment-qa-violations
1978     fi
1979     }
1980    
1981     increment-qa-violations() {
1982     let "JAVA_PKG_QA_VIOLATIONS+=1"
1983     export JAVA_PKG_QA_VIOLATIONS
1984     }
1985    
1986 nichoj 1.9 is-java-strict() {
1987 nichoj 1.14 [[ -n ${JAVA_PKG_STRICT} ]]
1988 nichoj 1.9 return $?
1989     }
1990    
1991 nichoj 1.1 # ------------------------------------------------------------------------------
1992     # @eclass-end
1993     # ------------------------------------------------------------------------------

  ViewVC Help
Powered by ViewVC 1.1.20