/[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.122 - (hide annotations) (download)
Thu Feb 19 05:10:37 2009 UTC (5 years, 4 months ago) by serkan
Branch: MAIN
Changes since 1.121: +28 -1 lines
Move pkg_preinst to java-utils-2 and add it to java-pkg-opt-2.

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

  ViewVC Help
Powered by ViewVC 1.1.20