/[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.46 - (hide annotations) (download)
Sun Jan 21 01:20:21 2007 UTC (7 years, 11 months ago) by caster
Branch: MAIN
Changes since 1.45: +172 -5 lines
Add split-ant functionality to relevant eclasses.
----------------------------------------------------------------------

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

  ViewVC Help
Powered by ViewVC 1.1.20