/[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.61 - (hide annotations) (download)
Sat Mar 3 16:27:31 2007 UTC (7 years, 7 months ago) by betelgeuse
Branch: MAIN
Changes since 1.60: +4 -2 lines
Don't use which to determine where depend-java-query is installed but hardcode /usr/bin because the which was causing endless loops for some people

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

  ViewVC Help
Powered by ViewVC 1.1.20