/[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.32 - (hide annotations) (download)
Thu Dec 7 02:14:46 2006 UTC (7 years, 9 months ago) by caster
Branch: MAIN
Changes since 1.31: +3 -2 lines
Call die if unable to determine VM from deps.

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

  ViewVC Help
Powered by ViewVC 1.1.20