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