/[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.27 - (hide annotations) (download)
Sat Dec 2 21:19:27 2006 UTC (7 years, 7 months ago) by betelgeuse
Branch: MAIN
Changes since 1.26: +2 -1 lines
Calling java-pkg_init_paths in java-pkg_do_write_ to ensure that he variables are correctly setup.

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