/[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.116 - (hide annotations) (download)
Fri Oct 10 20:11:46 2008 UTC (6 years, 1 month ago) by betelgeuse
Branch: MAIN
Changes since 1.115: +9 -1 lines
Run java-config --help to see if the user hasn't run python-updater.

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

  ViewVC Help
Powered by ViewVC 1.1.20