/[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.29 - (hide annotations) (download)
Sun Dec 3 13:05:06 2006 UTC (8 years ago) by betelgeuse
Branch: MAIN
Changes since 1.28: +1 -0 lines
Added CVS Headers after a request from grobian.

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

  ViewVC Help
Powered by ViewVC 1.1.20