/[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.42 - (hide annotations) (download)
Mon Jan 15 00:01:21 2007 UTC (7 years, 11 months ago) by caster
Branch: MAIN
Changes since 1.41: +12 -6 lines
Make dolauncher die if -pre specifies non-existing file.
----------------------------------------------------------------------

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

  ViewVC Help
Powered by ViewVC 1.1.20