/[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.57 - (hide annotations) (download)
Tue Feb 13 19:52:51 2007 UTC (7 years, 8 months ago) by betelgeuse
Branch: MAIN
Changes since 1.56: +17 -5 lines
* Automatically add Junit.present=true to ant properties when in the test phase
* Allow multiple atoms in EANT_GENTOO_CLASSPATH
* Automatically add junit to gentoo.classpath when EANT_GENTOO_CLASSPATH is
  defined, ant-junit is in ANT_TASKS and we are in the test phase.

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

  ViewVC Help
Powered by ViewVC 1.1.20