/[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.127 - (hide annotations) (download)
Tue May 19 21:23:32 2009 UTC (5 years, 5 months ago) by caster
Branch: MAIN
Changes since 1.126: +5 -8 lines
Use dosym in java_pkg-doso and fix few debug prints. Patch by Davide Pesavento <davidepesa@gmail.com> in bug #251500.

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

  ViewVC Help
Powered by ViewVC 1.1.20