/[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.34 - (hide annotations) (download)
Fri Dec 8 12:12:04 2006 UTC (8 years ago) by betelgeuse
Branch: MAIN
Changes since 1.33: +4 -3 lines
Make java-pkg-2.eclass die on pkg_setup if FEATURES has test, IUSE has test and use test is true.

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

  ViewVC Help
Powered by ViewVC 1.1.20