/[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.44 - (hide annotations) (download)
Sat Jan 20 11:14:31 2007 UTC (7 years, 6 months ago) by betelgeuse
Branch: MAIN
Changes since 1.43: +4 -2 lines
Improve debug output

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

  ViewVC Help
Powered by ViewVC 1.1.20