/[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.52 - (hide annotations) (download)
Sun Jan 28 20:58:29 2007 UTC (7 years, 7 months ago) by betelgeuse
Branch: MAIN
Changes since 1.51: +19 -3 lines
eant -lib is deprecated and should not be used

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

  ViewVC Help
Powered by ViewVC 1.1.20