/[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.56 - (hide annotations) (download)
Tue Jan 30 14:12:34 2007 UTC (7 years, 8 months ago) by caster
Branch: MAIN
Changes since 1.55: +21 -12 lines
Improve output and comments for java-pkg_verify-classes().

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

  ViewVC Help
Powered by ViewVC 1.1.20