1 # Copyright 2004-2018 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: java-utils-2.eclass
8 # Thomas Matthijs <axxo@gentoo.org>, Karl Trygve Kalleberg <karltk@gentoo.org>
9 # @BLURB: Base eclass for Java packages
11 # This eclass provides functionality which is used by java-pkg-2.eclass,
12 # java-pkg-opt-2.eclass and java-ant-2 eclass, as well as from ebuilds.
14 # This eclass should not be inherited this directly from an ebuild. Instead,
15 # you should inherit java-pkg-2 for Java packages or java-pkg-opt-2 for packages
16 # that have optional Java support. In addition you can inherit java-ant-2 for
19 # EAPI 7 has version functions built-in. Use eapi7-ver for all earlier eclasses.
20 # Keep versionator inheritance in case consumers are using it implicitly.
21 [[ ${EAPI} == [0123456] ]] && inherit eapi7-ver eutils multilib versionator
25 # Make sure we use java-config-2
26 export WANT_JAVA_CONFIG="2"
28 # Prefix variables are only available for EAPI>=3
29 has "${EAPI:-0}" 0 1 2 && ED="${D}" EPREFIX= EROOT="${ROOT}"
31 # @VARIABLE: JAVA_PKG_E_DEPEND
34 # This is a convience variable to be used from the other java eclasses. This is
35 # the version of java-config we want to use. Usually the latest stable version
36 # so that ebuilds can use new features without depending on specific versions.
37 JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.2.0-r3"
38 has source ${JAVA_PKG_IUSE} && JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} source? ( app-arch/zip )"
40 # @ECLASS-VARIABLE: JAVA_PKG_WANT_BOOTCLASSPATH
43 # The version of bootclasspath the package needs to work. Translates to a proper
44 # dependency. The bootclasspath can then be obtained by java-ant_rewrite-bootclasspath
45 if [[ -n "${JAVA_PKG_WANT_BOOTCLASSPATH}" ]]; then
46 if [[ "${JAVA_PKG_WANT_BOOTCLASSPATH}" == "1.5" ]]; then
47 JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} >=dev-java/gnu-classpath-0.98-r1:0.98"
49 eerror "Unknown value of JAVA_PKG_WANT_BOOTCLASSPATH"
50 # since die in global scope doesn't work, this will make repoman fail
51 JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} BAD_JAVA_PKG_WANT_BOOTCLASSPATH"
55 # @ECLASS-VARIABLE: JAVA_PKG_ALLOW_VM_CHANGE
57 # Allow this eclass to change the active VM?
58 # If your system VM isn't sufficient for the package, the build will fail
59 # instead of trying to switch to another VM.
61 # Overriding the default can be useful for testing specific VMs locally, but
62 # should not be used in the final ebuild.
63 JAVA_PKG_ALLOW_VM_CHANGE=${JAVA_PKG_ALLOW_VM_CHANGE:="yes"}
65 # @ECLASS-VARIABLE: JAVA_PKG_FORCE_VM
68 # Explicitly set a particular VM to use. If its not valid, it'll fall back to
69 # whatever /etc/java-config-2/build/jdk.conf would elect to use.
71 # Should only be used for testing and debugging.
73 # Example: use sun-jdk-1.5 to emerge foo:
75 # JAVA_PKG_FORCE_VM=sun-jdk-1.5 emerge foo
78 # @ECLASS-VARIABLE: JAVA_PKG_WANT_BUILD_VM
81 # A list of VM handles to choose a build VM from. If the list contains the
82 # currently active VM use that one, otherwise step through the list till a
83 # usable/installed VM is found.
85 # This allows to use an explicit list of JDKs in DEPEND instead of a virtual.
86 # Users of this variable must make sure at least one of the listed handles is
88 # Requires JAVA_PKG_WANT_SOURCE and JAVA_PKG_WANT_TARGET to be set as well.
90 # @ECLASS-VARIABLE: JAVA_PKG_WANT_SOURCE
93 # Specify a non-standard Java source version for compilation (via javac -source
94 # parameter or Ant equivalent via build.xml rewriting done by java-ant-2 eclass).
95 # Normally this is determined from the jdk version specified in DEPEND.
96 # See java-pkg_get-source function below.
98 # Should generally only be used for testing and debugging.
100 # Use 1.4 source to emerge baz
102 # JAVA_PKG_WANT_SOURCE=1.4 emerge baz
105 # @ECLASS-VARIABLE: JAVA_PKG_WANT_TARGET
108 # Same as JAVA_PKG_WANT_SOURCE (see above) but for javac -target parameter,
109 # which affects the version of generated bytecode.
110 # Normally this is determined from the jre/jdk version specified in RDEPEND.
111 # See java-pkg_get-target function below.
113 # Should generallyonly be used for testing and debugging.
115 # emerge bar to be compatible with 1.3
117 # JAVA_PKG_WANT_TARGET=1.3 emerge bar
120 # @ECLASS-VARIABLE: JAVA_PKG_DEBUG
123 # A variable to be set with "yes" or "y", or ANY string of length non equal to
124 # zero. When set, verbosity across java eclasses is increased and extra
125 # logging is displayed.
127 # JAVA_PKG_DEBUG="yes"
130 # @ECLASS-VARIABLE: JAVA_RM_FILES
133 # An array containing a list of files to remove. If defined, this array will be
134 # automatically handed over to java-pkg_rm_files for processing during the
144 # @VARIABLE: JAVA_PKG_COMPILER_DIR
147 # Directory where compiler settings are saved, without trailing slash.
148 # You probably shouldn't touch this variable except local testing.
149 JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"}
151 # @VARIABLE: JAVA_PKG_COMPILERS_CONF
154 # Path to file containing information about which compiler to use.
155 # Can be overloaded, but it should be overloaded only for local testing.
156 JAVA_PKG_COMPILERS_CONF=${JAVA_PKG_COMPILERS_CONF:="/etc/java-config-2/build/compilers.conf"}
158 # @ECLASS-VARIABLE: JAVA_PKG_FORCE_COMPILER
162 # Explicitly set a list of compilers to choose from. This is normally read from
163 # JAVA_PKG_COMPILERS_CONF.
165 # Useful for local testing.
167 # Use jikes and javac, in that order
169 # JAVA_PKG_FORCE_COMPILER="jikes javac"
172 # @ECLASS-VARIABLE: JAVA_PKG_FORCE_ANT_TASKS
175 # An $IFS separated list of ant tasks. Can be set in environment before calling
176 # emerge/ebuild to override variables set in ebuild, mainly for testing before
177 # putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in
178 # eant() call, not the dependencies specified in WANT_ANT_TASKS.
181 # JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \
182 # ebuild foo.ebuild compile
186 JAVA_PKG_QA_VIOLATIONS=0
188 # @FUNCTION: java-pkg_doexamples
189 # @USAGE: [--subdir <subdir>] <file1/dir1> [<file2> ...]
191 # Installs given arguments to /usr/share/doc/${PF}/examples
192 # If you give it only one parameter and it is a directory it will install
193 # everything in that directory to the examples directory.
197 # --subdir - If the examples need a certain directory structure
198 # $* - list of files to install
201 # java-pkg_doexamples demo
202 # java-pkg_doexamples demo/* examples/*
204 java-pkg_doexamples() {
205 debug-print-function ${FUNCNAME} $*
207 [[ ${#} -lt 1 ]] && die "At least one argument needed"
209 java-pkg_check-phase install
212 local dest=/usr/share/doc/${PF}/examples
213 if [[ ${1} == --subdir ]]; then
214 local dest=${dest}/${2}
219 if [[ ${#} = 1 && -d ${1} ]]; then
220 ( # dont want to pollute calling env
223 ) || die "Installing examples failed"
225 ( # dont want to pollute calling env
228 ) || die "Installing examples failed"
231 # Let's make a symlink to the directory we have everything else under
232 dosym "${dest}" "${JAVA_PKG_SHAREPATH}/examples" || die
235 # @FUNCTION: java-pkg_addres
236 # @USAGE: <jar> <dir> [<find arguments> ...]
238 # Adds resource files to an existing jar.
239 # It is important that the directory given is actually the root of the
240 # corresponding resource tree. The target directory as well as
241 # sources.lst, MANIFEST.MF, *.class, *.jar, and *.java files are
242 # automatically excluded. Symlinks are always followed. Additional
243 # arguments are passed through to find.
246 # java-pkg_addres ${PN}.jar resources ! -name "*.html"
249 # @param $1 - jar file
250 # @param $2 - resource tree directory
251 # @param $* - arguments to pass to find
253 debug-print-function ${FUNCNAME} $*
255 [[ ${#} -lt 2 ]] && die "at least two arguments needed"
257 local jar=$(realpath "$1" || die "realpath $1 failed")
261 pushd "${dir}" > /dev/null || die "pushd ${dir} failed"
262 find -L -type f ! -path "./target/*" ! -path "./sources.lst" ! -name "MANIFEST.MF" ! -regex ".*\.\(class\|jar\|java\)" "${@}" -print0 | xargs -r0 jar uf "${jar}" || die "jar failed"
263 popd > /dev/null || die "popd failed"
266 # @FUNCTION: java-pkg_rm_files
267 # @USAGE: java-pkg_rm_files File1.java File2.java ...
269 # Remove unneeded files in ${S}.
271 # Every now and then, you'll run into situations whereby a file needs removing,
272 # be it a unit test or a regular java class.
274 # You can use this function by either:
275 # - calling it yourself in src_prepare() and feeding java-pkg_rm_files with
276 # the list of files you wish to remove.
277 # - defining an array in the ebuild named JAVA_RM_FILES with the list of files
278 # you wish to remove.
280 # Both way work and it is left to the developer's preferences. If the
281 # JAVA_RM_FILES array is defined, it will be automatically handed over to
282 # java-pkg_rm_files during the src_prepare phase.
284 # See java-utils-2_src_prepare.
287 # java-pkg_rm_files File1.java File2.java
290 # @param $* - list of files to remove.
291 java-pkg_rm_files() {
292 debug-print-function ${FUNCNAME} $*
294 for filename in "$@"; do
295 [[ ! -f "${filename}" ]] && die "${filename} is not a regular file. Aborting."
296 einfo "Removing unneeded file ${filename}"
297 rm -f "${S}/${filename}" || die "cannot remove ${filename}"
302 # @FUNCTION: java-pkg_dojar
303 # @USAGE: <jar1> [<jar2> ...]
305 # Installs any number of jars.
306 # Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default.
307 # You can use java-pkg_jarinto to change this path.
308 # You should never install a jar with a package version in the filename.
309 # Instead, use java-pkg_newjar defined below.
312 # java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar
315 # @param $* - list of jars to install
317 debug-print-function ${FUNCNAME} $*
319 [[ ${#} -lt 1 ]] && die "At least one argument needed"
321 java-pkg_check-phase install
324 # Create JARDEST if it doesn't exist
325 dodir ${JAVA_PKG_JARDEST}
329 for jar in "${@}"; do
330 local jar_basename=$(basename "${jar}")
332 java-pkg_check-versioned-jar ${jar_basename}
335 if [[ -e "${jar}" ]] ; then
336 # Don't overwrite if jar has already been installed with the same
338 local dest="${ED}${JAVA_PKG_JARDEST}/${jar_basename}"
339 if [[ -e "${dest}" ]]; then
340 ewarn "Overwriting ${dest}"
343 # install it into JARDEST if it's a non-symlink
344 if [[ ! -L "${jar}" ]] ; then
345 #but first check class version when in strict mode.
346 is-java-strict && java-pkg_verify-classes "${jar}"
349 insinto "${JAVA_PKG_JARDEST}"
351 ) || die "failed to install ${jar}"
352 java-pkg_append_ JAVA_PKG_CLASSPATH "${EPREFIX}/${JAVA_PKG_JARDEST}/${jar_basename}"
353 debug-print "installed ${jar} to ${ED}${JAVA_PKG_JARDEST}"
354 # make a symlink to the original jar if it's symlink
356 # TODO use dosym, once we find something that could use it
358 ln -s "$(readlink "${jar}")" "${ED}${JAVA_PKG_JARDEST}/${jar_basename}"
359 debug-print "${jar} is a symlink, linking accordingly"
362 die "${jar} does not exist"
366 # Extra logging if enabled.
367 if [[ -n ${JAVA_PKG_DEBUG} ]]; then
368 einfo "Verbose logging for \"${FUNCNAME}\" function"
369 einfo "Jar file(s) destination: ${JAVA_PKG_JARDEST}"
370 einfo "Jar file(s) created: ${@}"
371 einfo "Complete command:"
372 einfo "${FUNCNAME} ${@}"
378 # @FUNCTION: java-pkg_regjar
379 # @USAGE: </path/to/installed/jar>
381 # Records an already installed (in ${D}) jar in the package.env
382 # This would mostly be used if the package has make or a custom script to
386 # if you want to use shell expansion, you have to use ${D}/... as the for in
387 # this function will not be able to expand the path, here's an example:
390 # java-pkg_regjar ${D}/opt/my-java/lib/*.jar
394 # TODO should we be making sure the jar is present on ${D} or wherever?
396 debug-print-function ${FUNCNAME} $*
398 java-pkg_check-phase install
400 [[ ${#} -lt 1 ]] && die "at least one argument needed"
404 local jar jar_dir jar_file
405 for jar in "${@}"; do
406 # TODO use java-pkg_check-versioned-jar
407 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
408 [[ -d "${jar}" || -d "${D}${jar}" ]] \
409 && die "Called ${FUNCNAME} on a directory $*"
411 #check that class version correct when in strict mode
412 is-java-strict && java-pkg_verify-classes "${jar}"
414 # nelchael: we should strip ${D} in this case too, here's why:
416 # java-pkg_regjar ${D}/opt/java/*.jar
417 # such call will fall into this case (-e ${jar}) and will
418 # record paths with ${D} in package.env
419 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
421 if [[ ${jar} = *\** ]]; then
422 eerror "The argument ${jar} to ${FUNCNAME}"
423 eerror "has * in it. If you want it to glob in"
424 eerror '${D} add ${D} to the argument.'
426 debug-print "${jar} or ${D}${jar} not found"
427 die "${jar} does not exist"
434 # @FUNCTION: java-pkg_newjar
435 # @USAGE: <path/to/oldname.jar> [<newname.jar>]
437 # Installs a jar with a new name (defaults to $PN.jar)
439 # For example, installs a versioned jar without the version
441 debug-print-function ${FUNCNAME} $*
443 local original_jar="${1}"
444 local new_jar="${2:-${PN}.jar}"
445 local new_jar_dest="${T}/${new_jar}"
447 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
448 [[ ! -f ${original_jar} ]] \
449 && die "${original_jar} does not exist or is not a file!"
451 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
452 cp "${original_jar}" "${new_jar_dest}" \
453 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
454 java-pkg_dojar "${new_jar_dest}"
457 # @FUNCTION: java-pkg_addcp
458 # @USAGE: <classpath>
460 # Add something to the package's classpath. For jars, you should use dojar,
461 # newjar, or regjar. This is typically used to add directories to the classpath.
462 # The parameters of this function are appended to JAVA_PKG_CLASSPATH
464 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
468 # @FUNCTION: java-pkg_doso
469 # @USAGE: <path/to/file1.so> [...]
471 # Installs any number of JNI libraries
472 # They will be installed into /usr/lib by default, but java-pkg_sointo
473 # can be used change this path
480 debug-print-function ${FUNCNAME} $*
482 java-pkg_check-phase install
484 [[ ${#} -lt 1 ]] && die "${FUNCNAME} requires at least one argument"
491 # if the lib exists...
492 if [[ -e "${lib}" ]] ; then
493 # install if it isn't a symlink
494 if [[ ! -L "${lib}" ]] ; then
496 insinto "${JAVA_PKG_LIBDEST}"
499 ) || die "failed to install ${lib}"
500 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
501 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
502 # otherwise make a symlink to the symlink's origin
504 dosym "$(readlink "${lib}")" "${JAVA_PKG_LIBDEST}/${lib##*/}"
505 debug-print "${lib} is a symlink, linking accordantly"
509 die "${lib} does not exist"
516 # @FUNCTION: java-pkg_regso
517 # @USAGE: <file1.so> [...]
519 # Registers an already installed JNI library in package.env.
523 # $@ - JNI libraries to register
526 # java-pkg_regso *.so /path/*.so
529 debug-print-function ${FUNCNAME} $*
531 java-pkg_check-phase install
533 [[ ${#} -lt 1 ]] && die "${FUNCNAME} requires at least one argument"
539 # Check the absolute path of the lib
540 if [[ -e "${lib}" ]] ; then
541 target_dir="$(java-pkg_expand_dir_ ${lib})"
542 java-pkg_append_ JAVA_PKG_LIBRARY "/${target_dir#${D}}"
543 # Check the path of the lib relative to ${D}
544 elif [[ -e "${D}${lib}" ]]; then
545 target_dir="$(java-pkg_expand_dir_ ${D}${lib})"
546 java-pkg_append_ JAVA_PKG_LIBRARY "${target_dir}"
548 die "${lib} does not exist"
555 # @FUNCTION: java-pkg_jarinto
556 # @USAGE: </path/to/install/jars/into>
558 # Changes the path jars are installed into via subsequent java-pkg_dojar calls.
560 debug-print-function ${FUNCNAME} $*
562 JAVA_PKG_JARDEST="${1}"
565 # @FUNCTION: java-pkg_sointo
566 # @USAGE: </path/to/install/sofiles/into>
568 # Changes the path that JNI libraries are installed into via subsequent
569 # java-pkg_doso calls.
571 debug-print-function ${FUNCNAME} $*
573 JAVA_PKG_LIBDEST="${1}"
576 # @FUNCTION: java-pkg_dohtml
577 # @USAGE: <path/to/javadoc/documentation> [...]
579 # Install Javadoc HTML documentation. Usage of java-pkg_dojavadoc is preferred.
582 # java-pkg_dohtml dist/docs/
585 debug-print-function ${FUNCNAME} $*
587 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
589 # Do away with dohtml and rely on dodoc instead to do the deed.
593 # This probably shouldn't be here but it provides
594 # a reasonable way to catch # docs for all of the
596 java-pkg_recordjavadoc
599 # @FUNCTION: java-pkg_dojavadoc
600 # @USAGE: [--symlink destination] <path/to/javadocs/root>
602 # Installs javadoc documentation. This should be controlled by the doc use flag.
606 # $1: optional --symlink creates to symlink like this for html
607 # documentation bundles.
608 # $2: - The javadoc root directory.
611 # java-pkg_dojavadoc docs/api
612 # java-pkg_dojavadoc --symlink apidocs docs/api
614 java-pkg_dojavadoc() {
615 debug-print-function ${FUNCNAME} $*
617 # For html documentation bundles that link to Javadoc
619 if [[ ${1} = --symlink ]]; then
625 local dest=/usr/share/doc/${PF}/html
629 java-pkg_check-phase install
632 [[ -z "${dir}" ]] && die "Must specify a directory!"
633 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!"
634 if [[ ! -e "${dir}/index.html" ]]; then
635 local msg="No index.html in javadoc directory"
637 is-java-strict && die "${msg}"
640 if [[ -e ${D}/${dest}/api ]]; then
641 eerror "${dest} already exists. Will not overwrite."
645 # Renaming to match our directory layout
647 local dir_to_install="${dir}"
648 if [[ "$(basename "${dir}")" != "api" ]]; then
649 dir_to_install="${T}/api"
651 cp -r "${dir}" "${dir_to_install}" || die "cp failed"
654 # Actual installation
655 java-pkg_dohtml -r "${dir_to_install}"
657 # Let's make a symlink to the directory we have everything else under
658 dosym ${dest}/api "${JAVA_PKG_SHAREPATH}/api" || die
660 if [[ ${symlink} ]]; then
661 debug-print "symlinking ${dest}/{api,${symlink}}"
662 dosym ${dest}/{api,${symlink}} || die
665 # Extra logging if enabled.
666 if [[ -n ${JAVA_PKG_DEBUG} ]]; then
667 einfo "Verbose logging for \"${FUNCNAME}\" function"
668 einfo "Documentation destination: ${dest}"
669 einfo "Directory to install: ${dir_to_install}"
670 einfo "Complete command:"
671 einfo "${FUNCNAME} ${@}"
675 # @FUNCTION: java-pkg_dosrc
676 # @USAGE: <path/to/sources> [...]
678 # Installs a zip containing the source for a package, so it can used in
679 # from IDEs like eclipse and netbeans.
680 # Ebuild needs to DEPEND on app-arch/zip to use this. It also should be controlled by USE=source.
684 # java-pkg_dosrc src/*
687 # TODO change so it the arguments it takes are the base directories containing
690 # TODO should we be able to handle multiple calls to dosrc? -nichoj
692 # TODO maybe we can take an existing zip/jar? -nichoj
694 # FIXME apparently this fails if you give it an empty directories
696 debug-print-function ${FUNCNAME} $*
698 [ ${#} -lt 1 ] && die "At least one argument needed"
700 java-pkg_check-phase install
702 [[ ${#} -lt 1 ]] && die "At least one argument needed"
704 if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
705 local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
706 java-pkg_announce-qa-violation ${msg}
711 local zip_name="${PN}-src.zip"
712 local zip_path="${T}/${zip_name}"
714 for dir in "${@}"; do
715 local dir_parent=$(dirname "${dir}")
716 local dir_name=$(basename "${dir}")
717 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
718 zip -q -r ${zip_path} ${dir_name} -i '*.java'
720 # 12 means zip has nothing to do
721 if [[ ${result} != 12 && ${result} != 0 ]]; then
722 die "failed to zip ${dir_name}"
724 popd >/dev/null || die
729 insinto "${JAVA_PKG_SOURCESPATH}"
731 ) || die "Failed to install source"
733 JAVA_SOURCES="${JAVA_PKG_SOURCESPATH}/${zip_name}"
735 # Extra logging if enabled.
736 if [[ -n ${JAVA_PKG_DEBUG} ]]; then
737 einfo "Verbose logging for \"${FUNCNAME}\" function"
738 einfo "Zip filename created: ${zip_name}"
739 einfo "Zip file destination: ${JAVA_PKG_SOURCESPATH}"
740 einfo "Directories zipped: ${@}"
741 einfo "Complete command:"
742 einfo "${FUNCNAME} ${@}"
748 # @FUNCTION: java-pkg_dolauncher
749 # @USAGE: <filename> [options]
751 # Make a wrapper script to lauch/start this package
752 # If necessary, the wrapper will switch to the appropriate VM.
754 # Can be called without parameters if the package installs only one jar
755 # that has the Main-class attribute set. The wrapper will be named ${PN}.
759 # $1 - filename of launcher to create
760 # $2 - options, as follows:
761 # --main the.main.class.to.start
762 # --jar /the/jar/too/launch.jar or just <name>.jar
763 # --java_args 'Extra arguments to pass to java'
764 # --pkg_args 'Extra arguments to pass to the package'
765 # --pwd Directory the launcher changes to before executing java
766 # -into Directory to install the launcher to, instead of /usr/bin
767 # -pre Prepend contents of this file to the launcher
769 java-pkg_dolauncher() {
770 debug-print-function ${FUNCNAME} $*
772 java-pkg_check-phase install
775 if [[ ${#} = 0 ]]; then
782 # TODO rename to launcher
783 local target="${T}/${name}"
784 local var_tmp="${T}/launcher_variables_tmp"
787 # Process the other the rest of the arguments
788 while [[ -n "${1}" && -n "${2}" ]]; do
789 local var="${1}" value="${2}"
790 if [[ "${var:0:2}" == "--" ]]; then
792 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
793 local gjl_${var}="${value}"
794 elif [[ "${var}" == "-into" ]]; then
795 target_dir="${value}"
796 elif [[ "${var}" == "-pre" ]]; then
802 # Test if no --jar and --main arguments were given and
803 # in that case check if the package only installs one jar
805 if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
806 local cp="${JAVA_PKG_CLASSPATH}"
807 if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
808 echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
810 local msg="Not enough information to create a launcher given."
811 msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
816 # Write the actual script
817 echo "#!/bin/bash" > "${target}"
818 if [[ -n "${pre}" ]]; then
819 if [[ -f "${pre}" ]]; then
820 cat "${pre}" >> "${target}"
822 die "-pre specified file '${pre}' does not exist"
825 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
826 cat "${var_tmp}" >> "${target}"
828 echo "source ${EPREFIX}/usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
830 if [[ -n "${target_dir}" ]]; then
842 # @FUNCTION: java-pkg_dowar
847 debug-print-function ${FUNCNAME} $*
849 # Check for arguments
850 [[ ${#} -lt 1 ]] && die "At least one argument needed"
851 java-pkg_check-phase install
858 # TODO evaluate if we want to handle symlinks differently -nichoj
860 if [[ -L "${war}" ]] ; then
862 warpath="${T}$(basename "${war}")"
863 # Check for directory
864 # TODO evaluate if we want to handle directories differently -nichoj
865 elif [[ -d "${war}" ]] ; then
866 echo "dowar: warning, skipping directory ${war}"
872 # Install those files like you mean it
875 insinto "${JAVA_PKG_WARDEST}"
881 # @FUNCTION: java-pkg_recordjavadoc
884 # Scan for JavaDocs, and record their existence in the package.env file
886 # TODO make sure this in the proper section
887 java-pkg_recordjavadoc()
889 debug-print-function ${FUNCNAME} $*
890 # the find statement is important
891 # as some packages include multiple trees of javadoc
892 JAVADOC_PATH="$(find ${D}/usr/share/doc/ -name allclasses-frame.html -printf '%h:')"
893 # remove $D - TODO: check this is ok with all cases of the above
894 JAVADOC_PATH="${JAVADOC_PATH//${D}}"
895 if [[ -n "${JAVADOC_PATH}" ]] ; then
896 debug-print "javadocs found in ${JAVADOC_PATH%:}"
899 debug-print "No javadocs found"
904 # @FUNCTION: java-pkg_jar-from
905 # @USAGE: [--build-only] [--with-dependencies] [--virtual] [--into dir] <package> [<package.jar>] [<destination.jar>]
907 # Makes a symlink to a jar from a certain package
908 # A lot of java packages include dependencies in a lib/ directory
909 # You can use this function to replace these bundled dependencies.
910 # The dependency is recorded into package.env DEPEND line, unless "--build-only"
911 # is passed as the very first argument, for jars that have to be present only
912 # at build time and are not needed on runtime (junit testing etc).
915 # Example: get all jars from xerces slot 2
916 # java-pkg_jar-from xerces-2
918 # Example: get a specific jar from xerces slot 2
919 # java-pkg_jar-from xerces-2 xml-apis.jar
921 # Example: get a specific jar from xerces slot 2, and name it diffrently
922 # java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
924 # Example: get junit.jar which is needed only for building
925 # java-pkg_jar-from --build-only junit junit.jar
930 # --build-only - makes the jar(s) not added into package.env DEPEND line.
931 # (assumed automatically when called inside src_test)
932 # --with-dependencies - get jars also from requested package's dependencies
934 # --virtual - Packages passed to this function are to be handled as virtuals
935 # and will not have individual jar dependencies recorded.
936 # --into $dir - symlink jar(s) into $dir (must exist) instead of .
937 # $1 - Package to get jars from, or comma-separated list of packages in
938 # case other parameters are not used.
939 # $2 - jar from package. If not specified, all jars will be used.
940 # $3 - When a single jar is specified, destination filename of the
941 # symlink. Defaults to the name of the jar.
944 # TODO could probably be cleaned up a little
945 java-pkg_jar-from() {
946 debug-print-function ${FUNCNAME} $*
954 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
956 while [[ "${1}" == --* ]]; do
957 if [[ "${1}" = "--build-only" ]]; then
959 elif [[ "${1}" = "--with-dependencies" ]]; then
960 deep="--with-dependencies"
961 elif [[ "${1}" = "--virtual" ]]; then
963 elif [[ "${1}" = "--into" ]]; then
967 die "java-pkg_jar-from called with unknown parameter: ${1}"
972 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
974 [[ -z ${target_pkg} ]] && die "Must specify a package"
976 if [[ "${EAPI}" == "1" ]]; then
977 target_pkg="${target_pkg//:/-}"
980 # default destjar to the target jar
981 [[ -z "${destjar}" ]] && destjar="${target_jar}"
983 local error_msg="There was a problem getting the classpath for ${target_pkg}."
985 classpath="$(java-config ${deep} --classpath=${target_pkg})"
986 [[ $? != 0 ]] && die ${error_msg}
988 # When we have commas this functions is called to bring jars from multiple
989 # packages. This affects recording of dependencencies performed later
990 # which expects one package only, so we do it here.
991 if [[ ${target_pkg} = *,* ]]; then
992 for pkg in ${target_pkg//,/ }; do
993 java-pkg_ensure-dep "${build_only}" "${pkg}"
994 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
996 # setting this disables further record-jar_ calls later
999 java-pkg_ensure-dep "${build_only}" "${target_pkg}"
1002 # Record the entire virtual as a dependency so that
1003 # no jars are missed.
1004 if [[ -z "${build_only}" && -n "${virtual}" ]]; then
1005 java-pkg_record-jar_ "${target_pkg}"
1006 # setting this disables further record-jars_ calls later
1010 pushd ${destdir} > /dev/null \
1011 || die "failed to change directory to ${destdir}"
1014 for jar in ${classpath//:/ }; do
1015 local jar_name=$(basename "${jar}")
1016 if [[ ! -f "${jar}" ]] ; then
1017 debug-print "${jar} from ${target_pkg} does not exist"
1018 die "Installation problems with jars in ${target_pkg} - is it installed?"
1020 # If no specific target jar was indicated, link it
1021 if [[ -z "${target_jar}" ]] ; then
1022 [[ -f "${target_jar}" ]] && rm "${target_jar}"
1024 || die "Failed to make symlink from ${jar} to ${jar_name}"
1025 if [[ -z "${record_jar}" ]]; then
1026 if [[ -z "${build_only}" ]]; then
1027 java-pkg_record-jar_ "${target_pkg}" "${jar}"
1029 java-pkg_record-jar_ --build-only "${target_pkg}" "${jar}"
1032 # otherwise, if the current jar is the target jar, link it
1033 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
1034 [[ -f "${destjar}" ]] && rm "${destjar}"
1035 ln -snf "${jar}" "${destjar}" \
1036 || die "Failed to make symlink from ${jar} to ${destjar}"
1037 if [[ -z "${record_jar}" ]]; then
1038 if [[ -z "${build_only}" ]]; then
1039 java-pkg_record-jar_ "${target_pkg}" "${jar}"
1041 java-pkg_record-jar_ --build-only "${target_pkg}" "${jar}"
1044 popd > /dev/null || die
1048 popd > /dev/null || die
1049 # if no target was specified, we're ok
1050 if [[ -z "${target_jar}" ]] ; then
1052 # otherwise, die bitterly
1054 die "Failed to find ${target_jar:-jar} in ${target_pkg}"
1058 # @FUNCTION: java-pkg_jarfrom
1060 # See java-pkg_jar-from
1061 java-pkg_jarfrom() {
1062 java-pkg_jar-from "$@"
1065 # @FUNCTION: java-pkg_getjars
1066 # @USAGE: [--build-only] [--with-dependencies] <package1>[,<package2>...]
1068 # Get the classpath provided by any number of packages
1069 # Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
1070 # The providing packages are recorded as dependencies into package.env DEPEND
1071 # line, unless "--build-only" is passed as the very first argument, for jars
1072 # that have to be present only at build time and are not needed on runtime
1073 # (junit testing etc).
1076 # Example: Get the classpath for xerces-2 and xalan,
1077 # java-pkg_getjars xerces-2,xalan
1080 # /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
1084 # --build-only - makes the jar(s) not added into package.env DEPEND line.
1085 # (assumed automatically when called inside src_test)
1086 # --with-dependencies - get jars also from requested package's dependencies
1088 # $1 - list of packages to get jars from
1089 # (passed to java-config --classpath)
1091 java-pkg_getjars() {
1092 debug-print-function ${FUNCNAME} $*
1097 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1099 while [[ "${1}" == --* ]]; do
1100 if [[ "${1}" = "--build-only" ]]; then
1102 elif [[ "${1}" = "--with-dependencies" ]]; then
1103 deep="--with-dependencies"
1105 die "java-pkg_jar-from called with unknown parameter: ${1}"
1110 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
1115 if [[ "${EAPI}" == "1" ]]; then
1119 jars="$(java-config ${deep} --classpath=${pkgs})"
1120 [[ $? != 0 ]] && die "java-config --classpath=${pkgs} failed"
1121 debug-print "${pkgs}:${jars}"
1123 for pkg in ${pkgs//,/ }; do
1124 java-pkg_ensure-dep "${build_only}" "${pkg}"
1127 for pkg in ${pkgs//,/ }; do
1128 if [[ -z "${build_only}" ]]; then
1129 java-pkg_record-jar_ "${pkg}"
1131 java-pkg_record-jar_ --build-only "${pkg}"
1138 # @FUNCTION: java-pkg_getjar
1139 # @USAGE: [--build-only] [--virtual] <package> <jarfile>
1141 # Get the complete path of a single jar from a package
1142 # The providing package is recorded as runtime dependency into package.env
1143 # DEPEND line, unless "--build-only" is passed as the very first argument, for
1144 # jars that have to be present only at build time and are not needed on runtime
1145 # (junit testing etc).
1149 # java-pkg_getjar xerces-2 xml-apis.jar
1151 # /usr/share/xerces-2/lib/xml-apis.jar
1154 # --build-only - makes the jar not added into package.env DEPEND line.
1155 # --virtual - Packages passed to this function are to be handled as virtuals
1156 # and will not have individual jar dependencies recorded.
1157 # $1 - package to use
1161 debug-print-function ${FUNCNAME} $*
1167 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1169 while [[ "${1}" == --* ]]; do
1170 if [[ "${1}" = "--build-only" ]]; then
1172 elif [[ "${1}" == "--virtual" ]]; then
1175 die "java-pkg_getjar called with unknown parameter: ${1}"
1180 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
1182 local pkg="${1}" target_jar="${2}" jar
1184 if [[ "${EAPI}" == "1" ]]; then
1188 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
1189 [[ -z ${target_jar} ]] && die "Must specify jar to get"
1191 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
1193 classpath=$(java-config --classpath=${pkg})
1194 [[ $? != 0 ]] && die ${error_msg}
1196 java-pkg_ensure-dep "${build_only}" "${pkg}"
1198 # Record the package(Virtual) as a dependency and then set build_only
1199 # So that individual jars are not recorded.
1200 if [[ -n "${virtual}" ]]; then
1201 if [[ -z "${build_only}" ]]; then
1202 java-pkg_record-jar_ "${pkg}"
1204 java-pkg_record-jar_ --build-only "${pkg}"
1209 for jar in ${classpath//:/ }; do
1210 if [[ ! -f "${jar}" ]] ; then
1211 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
1214 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
1215 # Only record jars that aren't build-only
1216 if [[ -z "${record_jar}" ]]; then
1217 if [[ -z "${build_only}" ]]; then
1218 java-pkg_record-jar_ "${pkg}" "${jar}"
1220 java-pkg_record-jar_ --build-only "${pkg}" "${jar}"
1228 die "Could not find ${target_jar} in ${pkg}"
1232 # @FUNCTION: java-pkg_register-dependency
1233 # @USAGE: <package>[,<package2>...] [<jarfile>]
1235 # Registers runtime dependency on a package, list of packages, or a single jar
1236 # from a package, into package.env DEPEND line. Can only be called in
1237 # src_install phase.
1238 # Intended for binary packages where you don't need to symlink the jars or get
1239 # their classpath during build. As such, the dependencies only need to be
1240 # specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1244 # $1 - comma-separated list of packages, or a single package
1245 # $2 - if param $1 is a single package, optionally specify the jar
1249 # Record the dependency on whole xerces-2 and xalan,
1250 # java-pkg_register-dependency xerces-2,xalan
1252 # Record the dependency on ant.jar from ant-core
1253 # java-pkg_register-dependency ant-core ant.jar
1256 # Note: Passing both list of packages as the first parameter AND specifying the
1257 # jar as the second is not allowed and will cause the function to die. We assume
1258 # that there's more chance one passes such combination as a mistake, than that
1259 # there are more packages providing identically named jar without class
1261 java-pkg_register-dependency() {
1262 debug-print-function ${FUNCNAME} $*
1264 java-pkg_check-phase install
1266 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1271 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1273 if [[ "${EAPI}" == "1" ]]; then
1277 if [[ -z "${jar}" ]]; then
1278 for pkg in ${pkgs//,/ }; do
1279 java-pkg_ensure-dep runtime "${pkg}"
1280 java-pkg_record-jar_ "${pkg}"
1283 [[ ${pkgs} == *,* ]] && \
1284 die "${FUNCNAME} called with both package list and jar name"
1285 java-pkg_ensure-dep runtime "${pkgs}"
1286 java-pkg_record-jar_ "${pkgs}" "${jar}"
1292 # @FUNCTION: java-pkg_register-optional-dependency
1293 # @USAGE: <package>[,<package2>...] [<jarfile>]
1295 # Registers optional runtime dependency on a package, list of packages, or a
1296 # single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be
1297 # called in src_install phase.
1298 # Intended for packages that can use other packages when those are in classpath.
1299 # Will be put on classpath by launcher if they are installed. Typical case is
1300 # JDBC implementations for various databases. It's better than having USE flag
1301 # for each implementation triggering hard dependency.
1305 # $1 - comma-separated list of packages, or a single package
1306 # $2 - if param $1 is a single package, optionally specify the jar to depend on
1309 # Record the optional dependency on some jdbc providers
1310 # java-pkg_register-optional-dependency jdbc-jaybird,jtds-1.2,jdbc-mysql
1313 # Note: Passing both list of packages as the first parameter AND specifying the
1314 # jar as the second is not allowed and will cause the function to die. We assume
1315 # that there's more chance one passes such combination as a mistake, than that
1316 # there are more packages providing identically named jar without class
1318 java-pkg_register-optional-dependency() {
1319 debug-print-function ${FUNCNAME} $*
1321 java-pkg_check-phase install
1323 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1328 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1330 if [[ "${EAPI}" == "1" ]]; then
1334 if [[ -z "${jar}" ]]; then
1335 for pkg in ${pkgs//,/ }; do
1336 java-pkg_record-jar_ --optional "${pkg}"
1339 [[ ${pkgs} == *,* ]] && \
1340 die "${FUNCNAME} called with both package list and jar name"
1341 java-pkg_record-jar_ --optional "${pkgs}" "${jar}"
1347 # @FUNCTION: java-pkg_register-environment-variable
1348 # @USAGE: <name> <value>
1350 # Register an arbitrary environment variable into package.env. The gjl launcher
1351 # for this package or any package depending on this will export it into
1352 # environement before executing java command.
1353 # Must only be called in src_install phase.
1354 JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
1355 JAVA_PKG_EXTRA_ENV_VARS=""
1356 java-pkg_register-environment-variable() {
1357 debug-print-function ${FUNCNAME} $*
1359 java-pkg_check-phase install
1361 [[ ${#} != 2 ]] && die "${FUNCNAME} takes two arguments"
1363 echo "${1}=\"${2}\"" >> ${JAVA_PKG_EXTRA_ENV}
1364 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
1369 # @FUNCTION: java-pkg_get-bootclasspath
1372 # Returns classpath of a given bootclasspath-providing package version.
1374 # @param $1 - the version of bootclasspath (e.g. 1.5), 'auto' for bootclasspath
1375 # of the current JDK
1376 java-pkg_get-bootclasspath() {
1377 local version="${1}"
1380 case "${version}" in
1382 bcp="$(java-config -g BOOTCLASSPATH)"
1385 bcp="$(java-pkg_getjars --build-only gnu-classpath-0.98)"
1388 eerror "unknown parameter of java-pkg_get-bootclasspath"
1389 die "unknown parameter of java-pkg_get-bootclasspath"
1397 # This function reads stdin, and based on that input, figures out how to
1398 # populate jars from the filesystem.
1399 # Need to figure out a good way of making use of this, ie be able to use a
1400 # string that was built instead of stdin
1401 # NOTE: this isn't quite ready for primetime.
1402 #java-pkg_populate-jars() {
1406 # while [[ -n "${line}" ]]; do
1408 # [[ ${line%%#*} == "" ]] && continue
1410 # # get rid of any spaces
1411 # line="${line// /}"
1413 # # format: path=jarinfo
1414 # local path=${line%%=*}
1415 # local jarinfo=${line##*=}
1417 # # format: jar@package
1418 # local jar=${jarinfo%%@*}.jar
1419 # local package=${jarinfo##*@}
1420 # if [[ -n ${replace_only} ]]; then
1421 # [[ ! -f $path ]] && die "No jar exists at ${path}"
1423 # if [[ -n ${create_parent} ]]; then
1424 # local parent=$(dirname ${path})
1425 # mkdir -p "${parent}"
1427 # java-pkg_jar-from "${package}" "${jar}" "${path}"
1433 # @FUNCTION: java-pkg_find-normal-jars
1434 # @USAGE: [<path/to/directory>]
1436 # Find the files with suffix .jar file in the given directory (default: $WORKDIR)
1437 java-pkg_find-normal-jars() {
1439 [[ "${dir}" ]] || dir="${WORKDIR}"
1441 for jar in $(find "${dir}" -name "*.jar" -type f); do
1449 # @FUNCTION: java-pkg_ensure-no-bundled-jars
1451 # Try to locate bundled jar files in ${WORKDIR} and die if found.
1452 # This function should be called after WORKDIR has been populated with symlink
1453 # to system jar files or bundled jars removed.
1454 java-pkg_ensure-no-bundled-jars() {
1455 debug-print-function ${FUNCNAME} $*
1457 local bundled_jars=$(java-pkg_find-normal-jars)
1458 if [[ -n ${bundled_jars} ]]; then
1459 echo "Bundled jars found:"
1461 for jar in ${bundled_jars}; do
1462 echo $(pwd)${jar/./}
1464 die "Bundled jars found!"
1468 # @FUNCTION: java-pkg_ensure-vm-version-sufficient
1471 # Checks if we have a sufficient VM and dies if we don't.
1472 java-pkg_ensure-vm-version-sufficient() {
1473 debug-print-function ${FUNCNAME} $*
1475 if ! java-pkg_is-vm-version-sufficient; then
1476 debug-print "VM is not suffient"
1477 eerror "Current Java VM cannot build this package"
1478 einfo "Please use \"eselect java-vm set system\" to set the correct one"
1479 die "Active Java VM cannot build this package"
1483 # @FUNCTION: java-pkg_is-vm-version-sufficient
1486 # @RETURN: zero - VM is sufficient; non-zero - VM is not sufficient
1487 java-pkg_is-vm-version-sufficient() {
1488 debug-print-function ${FUNCNAME} $*
1490 depend-java-query --is-sufficient "${DEPEND}" > /dev/null
1494 # @FUNCTION: java-pkg_ensure-vm-version-eq
1497 # Die if the current VM is not equal to the argument passed.
1499 # @param $@ - Desired VM version to ensure
1500 java-pkg_ensure-vm-version-eq() {
1501 debug-print-function ${FUNCNAME} $*
1503 if ! java-pkg_is-vm-version-eq $@ ; then
1504 debug-print "VM is not suffient"
1505 eerror "This package requires a Java VM version = $@"
1506 einfo "Please use \"eselect java-vm set system\" to set the correct one"
1507 die "Active Java VM too old"
1511 # @FUNCTION: java-pkg_is-vm-version-eq
1514 # @RETURN: zero - VM versions are equal; non-zero - VM version are not equal
1515 java-pkg_is-vm-version-eq() {
1516 debug-print-function ${FUNCNAME} $*
1518 local needed_version="$@"
1520 [[ -z "${needed_version}" ]] && die "need an argument"
1522 local vm_version="$(java-pkg_get-vm-version)"
1524 vm_version="$(ver_cut 1-2 "${vm_version}")"
1525 needed_version="$(ver_cut 1-2 "${needed_version}")"
1527 if [[ -z "${vm_version}" ]]; then
1528 debug-print "Could not get JDK version from DEPEND"
1531 if [[ "${vm_version}" == "${needed_version}" ]]; then
1532 debug-print "Detected a JDK(${vm_version}) = ${needed_version}"
1535 debug-print "Detected a JDK(${vm_version}) != ${needed_version}"
1541 # @FUNCTION: java-pkg_ensure-vm-version-ge
1544 # Die if the current VM is not greater than the desired version
1546 # @param $@ - VM version to compare current to
1547 java-pkg_ensure-vm-version-ge() {
1548 debug-print-function ${FUNCNAME} $*
1550 if ! java-pkg_is-vm-version-ge "$@" ; then
1551 debug-print "vm is not suffient"
1552 eerror "This package requires a Java VM version >= $@"
1553 einfo "Please use \"eselect java-vm set system\" to set the correct one"
1554 die "Active Java VM too old"
1558 # @FUNCTION: java-pkg_is-vm-version-ge
1563 # $@ - VM version to compare current VM to
1565 # @RETURN: zero - current VM version is greater than checked version;
1566 # non-zero - current VM version is not greater than checked version
1567 java-pkg_is-vm-version-ge() {
1568 debug-print-function ${FUNCNAME} $*
1570 local needed_version=$@
1571 local vm_version=$(java-pkg_get-vm-version)
1572 if [[ -z "${vm_version}" ]]; then
1573 debug-print "Could not get JDK version from DEPEND"
1576 if ver_test "${vm_version}" -ge "${needed_version}"; then
1577 debug-print "Detected a JDK(${vm_version}) >= ${needed_version}"
1580 debug-print "Detected a JDK(${vm_version}) < ${needed_version}"
1586 java-pkg_set-current-vm() {
1587 export GENTOO_VM=${1}
1590 java-pkg_get-current-vm() {
1594 java-pkg_current-vm-matches() {
1595 has $(java-pkg_get-current-vm) ${@}
1599 # @FUNCTION: java-pkg_get-source
1601 # Determines what source version should be used, for passing to -source.
1602 # Unless you want to break things you probably shouldn't set _WANT_SOURCE
1604 # @RETURN: string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1605 java-pkg_get-source() {
1606 echo ${JAVA_PKG_WANT_SOURCE:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1609 # @FUNCTION: java-pkg_get-target
1611 # Determines what target version should be used, for passing to -target.
1612 # If you don't care about lower versions, you can set _WANT_TARGET to the
1613 # version of your JDK.
1615 # @RETURN: string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1616 java-pkg_get-target() {
1617 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1620 # @FUNCTION: java-pkg_get-javac
1622 # Returns the compiler executable
1623 java-pkg_get-javac() {
1624 debug-print-function ${FUNCNAME} $*
1626 java-pkg_init-compiler_
1627 local compiler="${GENTOO_COMPILER}"
1629 local compiler_executable
1630 if [[ "${compiler}" = "javac" ]]; then
1631 # nothing fancy needs to be done for javac
1632 compiler_executable="javac"
1634 # for everything else, try to determine from an env file
1636 local compiler_env="/usr/share/java-config-2/compiler/${compiler}"
1637 if [[ -f ${compiler_env} ]]; then
1638 local old_javac=${JAVAC}
1640 # try to get value of JAVAC
1641 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1642 export JAVAC=${old_javac}
1644 if [[ -z ${compiler_executable} ]]; then
1645 die "JAVAC is empty or undefined in ${compiler_env}"
1648 # check that it's executable
1649 if [[ ! -x ${compiler_executable} ]]; then
1650 die "${compiler_executable} doesn't exist, or isn't executable"
1653 die "Could not find environment file for ${compiler}"
1656 echo ${compiler_executable}
1659 # @FUNCTION: java-pkg_javac-args
1661 # If an ebuild uses javac directly, instead of using ejavac, it should call this
1662 # to know what -source/-target to use.
1664 # @RETURN: string - arguments to pass to javac, complete with -target and -source
1665 java-pkg_javac-args() {
1666 debug-print-function ${FUNCNAME} $*
1668 local want_source="$(java-pkg_get-source)"
1669 local want_target="$(java-pkg_get-target)"
1671 local source_str="-source ${want_source}"
1672 local target_str="-target ${want_target}"
1674 debug-print "want source: ${want_source}"
1675 debug-print "want target: ${want_target}"
1677 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1678 die "Could not find valid -source/-target values for javac"
1680 echo "${source_str} ${target_str}"
1684 # @FUNCTION: java-pkg_get-jni-cflags
1686 # Echos the CFLAGS for JNI compilations
1687 java-pkg_get-jni-cflags() {
1688 local flags="-I${JAVA_HOME}/include"
1690 local platform="linux"
1691 use elibc_FreeBSD && platform="freebsd"
1693 # TODO do a check that the directories are valid
1694 flags="${flags} -I${JAVA_HOME}/include/${platform}"
1699 java-pkg_ensure-gcj() {
1700 # was enforcing sys-devel/gcc[gcj]
1701 die "${FUNCNAME} was removed. Use use-deps available as of EAPI 2 instead. #261562"
1704 java-pkg_ensure-test() {
1705 # was enforcing USE=test if FEATURES=test
1706 die "${FUNCNAME} was removed. Package mangers handle this already. #278965"
1709 # @FUNCTION: java-pkg_register-ant-task
1710 # @USAGE: [--version x.y] [<name>]
1712 # Register this package as ant task, so that ant will load it when no specific
1713 # ANT_TASKS are specified. Note that even without this registering, all packages
1714 # specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1715 # packages, but can be also used by other ebuilds that used to symlink their
1716 # .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1721 # --version x.y Register only for ant version x.y (otherwise for any ant
1722 # version). Used by the ant-* packages to prevent loading of mismatched
1723 # ant-core ant tasks after core was updated, before the tasks are updated,
1724 # without a need for blockers.
1725 # $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1727 java-pkg_register-ant-task() {
1728 local TASKS_DIR="tasks"
1730 # check for --version x.y parameters
1731 while [[ -n "${1}" && -n "${2}" ]]; do
1734 if [[ "${var}" == "version" ]]; then
1735 TASKS_DIR="tasks-${val}"
1737 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1742 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1744 dodir /usr/share/ant/${TASKS_DIR}
1745 touch "${ED}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1748 # @FUNCTION: java-pkg_ant-tasks-depend
1751 # Translates the WANT_ANT_TASKS variable into valid dependencies.
1752 java-pkg_ant-tasks-depend() {
1753 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1755 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1757 for i in ${WANT_ANT_TASKS}
1759 if [[ ${i} = ant-* ]]; then
1760 DEP="${DEP}dev-java/${i} "
1761 elif [[ ${i} = */*:* ]]; then
1764 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1776 # @FUNCTION: ejunit_
1779 # Internal Junit wrapper function. Makes it easier to run the tests and checks for
1780 # dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner.
1783 # $1 - junit package (junit or junit-4)
1784 # $2 - -cp or -classpath
1785 # $3 - classpath; junit and recorded dependencies get appended
1786 # $@ - the rest of the parameters are passed to java
1789 debug-print-function ${FUNCNAME} $*
1792 if [[ -f ${JAVA_PKG_DEPEND_FILE} ]]; then
1793 for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
1794 pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
1801 local cp=$(java-pkg_getjars --with-dependencies ${junit}${pkgs})
1802 if [[ ${1} = -cp || ${1} = -classpath ]]; then
1809 local runner=junit.textui.TestRunner
1810 if [[ "${junit}" == "junit-4" ]] ; then
1811 runner=org.junit.runner.JUnitCore
1813 debug-print "Calling: java -cp \"${cp}\" -Djava.io.tmpdir=\"${T}\" -Djava.awt.headless=true ${runner} ${@}"
1814 java -cp "${cp}" -Djava.io.tmpdir="${T}/" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
1819 # Junit wrapper function. Makes it easier to run the tests and checks for
1820 # dev-java/junit in DEPEND. Launches the tests using org.junit.runner.JUnitCore.
1824 # $1 - -cp or -classpath
1825 # $2 - classpath; junit and recorded dependencies get appended
1826 # $@ - the rest of the parameters are passed to java
1829 # ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1830 # ejunit org.blinkenlights.jid3.test.AllTests
1831 # ejunit org.blinkenlights.jid3.test.FirstTest org.blinkenlights.jid3.test.SecondTest
1834 debug-print-function ${FUNCNAME} $*
1836 ejunit_ "junit" "${@}"
1839 # @FUNCTION: ejunit4
1841 # Junit4 wrapper function. Makes it easier to run the tests and checks for
1842 # dev-java/junit:4 in DEPEND. Launches the tests using junit.textui.TestRunner.
1846 # $1 - -cp or -classpath
1847 # $2 - classpath; junit and recorded dependencies get appended
1848 # $@ - the rest of the parameters are passed to java
1851 # ejunit4 -cp build/classes org.blinkenlights.jid3.test.AllTests
1852 # ejunit4 org.blinkenlights.jid3.test.AllTests
1853 # ejunit4 org.blinkenlights.jid3.test.FirstTest \
1854 # org.blinkenlights.jid3.test.SecondTest
1857 debug-print-function ${FUNCNAME} $*
1859 ejunit_ "junit-4" "${@}"
1862 # @FUNCTION: java-utils-2_src_prepare
1864 # src_prepare Searches for bundled jars
1865 # Don't call directly, but via java-pkg-2_src_prepare!
1866 java-utils-2_src_prepare() {
1869 java-pkg_func-exists java_prepare && java_prepare ;;
1871 java-pkg_func-exists java_prepare &&
1872 eqawarn "java_prepare is no longer called, define src_prepare instead."
1876 # Check for files in JAVA_RM_FILES array.
1877 if [[ ${JAVA_RM_FILES[@]} ]]; then
1878 debug-print "$FUNCNAME: removing unneeded files"
1879 java-pkg_rm_files "${JAVA_RM_FILES[@]}"
1882 if is-java-strict; then
1883 echo "Searching for bundled jars:"
1884 java-pkg_find-normal-jars || echo "None found."
1885 echo "Searching for bundled classes (no output if none found):"
1886 find "${WORKDIR}" -name "*.class"
1891 # @FUNCTION: java-utils-2_pkg_preinst
1893 # pkg_preinst Searches for missing and unneeded dependencies
1894 # Don't call directly, but via java-pkg-2_pkg_preinst!
1895 java-utils-2_pkg_preinst() {
1896 if is-java-strict; then
1897 if [[ ! -e "${JAVA_PKG_ENV}" ]] || has ant-tasks ${INHERITED}; then
1901 if has_version dev-java/java-dep-check; then
1902 local output=$(GENTOO_VM= java-dep-check --image "${D}" "${JAVA_PKG_ENV}")
1903 [[ ${output} ]] && ewarn "${output}"
1905 eerror "Install dev-java/java-dep-check for dependency checking"
1911 # @USAGE: <ant_build_target(s)>
1913 # Ant wrapper function. Will use the appropriate compiler, based on user-defined
1914 # compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1919 # EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1920 # gentoo.classpath property. Be sure to call java-ant_rewrite-classpath in src_unpack.
1921 # EANT_NEEDS_TOOLS - add tools.jar to the gentoo.classpath. Should only be used
1922 # for build-time purposes, the dependency is not recorded to
1924 # ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1927 debug-print-function ${FUNCNAME} $*
1929 if [[ ${EBUILD_PHASE} = compile ]]; then
1930 java-ant-2_src_configure
1933 if ! has java-ant-2 ${INHERITED}; then
1934 local msg="You should inherit java-ant-2 when using eant"
1935 java-pkg_announce-qa-violation "${msg}"
1938 local antflags="-Dnoget=true -Dmaven.mode.offline=true -Dbuild.sysclasspath=ignore"
1940 java-pkg_init-compiler_
1941 local compiler="${GENTOO_COMPILER}"
1943 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1944 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})"
1945 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1946 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1949 if [[ ${compiler} != "javac" ]]; then
1950 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1951 # Figure out any extra stuff to put on the classpath for compilers aside
1953 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1955 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})"
1956 if [[ -n ${build_compiler_deps} ]]; then
1957 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1961 for arg in "${@}"; do
1962 if [[ ${arg} = -lib ]]; then
1963 if is-java-strict; then
1964 eerror "You should not use the -lib argument to eant because it will fail"
1965 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1966 eerror "or ant properties to make dependencies available."
1967 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1968 eerror "split ant (>=dev-java/ant-core-1.7)."
1969 die "eant -lib is deprecated/forbidden"
1971 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1977 # parse WANT_ANT_TASKS for atoms
1978 local want_ant_tasks
1979 for i in ${WANT_ANT_TASKS}; do
1980 if [[ ${i} = */*:* ]]; then
1983 want_ant_tasks+="${i/:/-} "
1985 want_ant_tasks+="${i} "
1988 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1989 ANT_TASKS="${ANT_TASKS:-${want_ant_tasks% }}"
1991 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1992 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1994 # if ant-tasks is not set by ebuild or forced, use none
1995 ANT_TASKS="${ANT_TASKS:-none}"
1997 # at this point, ANT_TASKS should be "all", "none" or explicit list
1998 if [[ "${ANT_TASKS}" == "all" ]]; then
1999 einfo "Using all available ANT_TASKS"
2000 elif [[ "${ANT_TASKS}" == "none" ]]; then
2001 einfo "Disabling all optional ANT_TASKS"
2003 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
2008 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
2009 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
2011 local gcp="${EANT_GENTOO_CLASSPATH}"
2014 if [[ ${EBUILD_PHASE} = "test" ]]; then
2015 antflags="${antflags} -DJunit.present=true"
2016 getjarsarg="--with-dependencies"
2018 local re="\bant-junit4?([-:]\S+)?\b"
2019 [[ ${ANT_TASKS} =~ ${re} ]] && gcp+=" ${BASH_REMATCH[0]}"
2021 antflags="${antflags} -Dmaven.test.skip=true"
2026 for atom in ${gcp}; do
2027 cp+=":$(java-pkg_getjars ${getjarsarg} ${atom})"
2030 [[ ${EANT_NEEDS_TOOLS} ]] && cp+=":$(java-config --tools)"
2031 [[ ${EANT_GENTOO_CLASSPATH_EXTRA} ]] && cp+=":${EANT_GENTOO_CLASSPATH_EXTRA}"
2033 if [[ ${cp#:} ]]; then
2034 # It seems ant does not like single quotes around ${cp}
2035 # And ant 1.9.13+ also does not like double quotes around ${cp}
2036 # https://bz.apache.org/bugzilla/show_bug.cgi?id=58898
2037 antflags="${antflags} -Dgentoo.classpath=${cp#:}"
2040 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
2041 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
2042 ant ${antflags} "${@}" || die "eant failed"
2046 # @USAGE: <javac_arguments>
2048 # Javac wrapper function. Will use the appropriate compiler, based on
2049 # /etc/java-config/compilers.conf
2051 debug-print-function ${FUNCNAME} $*
2053 local compiler_executable
2054 compiler_executable=$(java-pkg_get-javac)
2057 javac_args="$(java-pkg_javac-args)"
2059 if [[ -n ${JAVA_PKG_DEBUG} ]]; then
2060 einfo "Verbose logging for \"${FUNCNAME}\" function"
2061 einfo "Compiler executable: ${compiler_executable}"
2062 einfo "Extra arguments: ${javac_args}"
2063 einfo "Complete command:"
2064 einfo "${compiler_executable} ${javac_args} ${@}"
2068 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
2071 # @FUNCTION: ejavadoc
2072 # @USAGE: <javadoc_arguments>
2074 # javadoc wrapper function. Will set some flags based on the VM version
2075 # due to strict javadoc rules in 1.8.
2077 debug-print-function ${FUNCNAME} $*
2079 local javadoc_args=""
2081 if java-pkg_is-vm-version-ge "1.8" ; then
2082 javadoc_args="-Xdoclint:none"
2085 if [[ -n ${JAVA_PKG_DEBUG} ]]; then
2086 einfo "Verbose logging for \"${FUNCNAME}\" function"
2087 einfo "Javadoc executable: javadoc"
2088 einfo "Extra arguments: ${javadoc_args}"
2089 einfo "Complete command:"
2090 einfo "javadoc ${javadoc_args} ${@}"
2093 ebegin "Generating JavaDoc"
2094 javadoc ${javadoc_args} "${@}" || die "ejavadoc failed"
2097 # @FUNCTION: java-pkg_filter-compiler
2098 # @USAGE: <compiler(s)_to_filter>
2100 # Used to prevent the use of some compilers. Should be used in src_compile.
2101 # Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
2102 java-pkg_filter-compiler() {
2103 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@"
2106 # @FUNCTION: java-pkg_force-compiler
2107 # @USAGE: <compiler(s)_to_force>
2109 # Used to force the use of particular compilers. Should be used in src_compile.
2110 # A common use of this would be to force ecj-3.1 to be used on amd64, to avoid
2111 # OutOfMemoryErrors that may come up.
2112 java-pkg_force-compiler() {
2113 JAVA_PKG_FORCE_COMPILER="$@"
2116 # @FUNCTION: use_doc
2119 # Helper function for getting ant to build javadocs. If the user has USE=doc,
2120 # then 'javadoc' or the argument are returned. Otherwise, there is no return.
2122 # The output of this should be passed to ant.
2125 # $@ - Option value to return. Defaults to 'javadoc'
2128 # build javadocs by calling 'javadoc' target
2131 # build javadocs by calling 'apidoc' target
2132 # eant $(use_doc apidoc)
2134 # @RETURN string - Name of the target to create javadocs
2136 use doc && echo ${@:-javadoc}
2140 # @FUNCTION: java-pkg_init
2143 # The purpose of this function, as the name might imply, is to initialize the
2144 # Java environment. It ensures that that there aren't any environment variables
2145 # that'll muss things up. It initializes some variables, which are used
2146 # internally. And most importantly, it'll switch the VM if necessary.
2148 # This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will
2149 # call it during each of the phases of the merge process.
2151 debug-print-function ${FUNCNAME} $*
2153 # Don't set up build environment if installing from binary. #206024 #258423
2154 [[ "${MERGE_TYPE}" == "binary" ]] && return
2155 # Also try Portage's nonstandard EMERGE_FROM for old EAPIs, if it doesn't
2156 # work nothing is lost.
2157 has ${EAPI:-0} 0 1 2 3 && [[ "${EMERGE_FROM}" == "binary" ]] && return
2162 java-config --help >/dev/null || {
2164 eerror "Can't run java-config --help"
2165 eerror "Have you upgraded python recently but haven't"
2166 eerror "run python-updater yet?"
2167 die "Can't run java-config --help"
2170 # People do all kinds of weird things.
2171 # https://forums.gentoo.org/viewtopic-p-3943166.html
2172 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
2173 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
2174 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
2175 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
2176 ewarn "sun-jdk vms and and as such break configure scripts that"
2177 ewarn "use it (for example app-office/openoffice) so we filter it out."
2178 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
2179 ewarn "make.conf for example) to silence this warning or"
2180 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
2183 if [[ -z ${accept} ]]; then
2184 # export _JAVA_OPTIONS= doesn't work because it will show up in java
2187 # phase hooks make this run many times without this
2188 I_WANT_GLOBAL_JAVA_OPTIONS="true"
2192 PATH=${JAVA_HOME}/bin:${PATH}
2194 # TODO we will probably want to set JAVAC and JAVACFLAGS
2197 java-pkg_check-jikes
2199 # Can't use unset here because Portage does not save the unset
2200 # see https://bugs.gentoo.org/show_bug.cgi?id=189417#c11
2202 # When users have crazy classpaths some packages can fail to compile.
2203 # and everything should work with empty CLASSPATH.
2204 # This also helps prevent unexpected dependencies on random things
2205 # from the CLASSPATH.
2208 # Unset external ANT_ stuff
2211 export ANT_RESPECT_JAVA_HOME=
2214 # @FUNCTION: java-pkg-init-compiler_
2217 # This function attempts to figure out what compiler should be used. It does
2218 # this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
2219 # COMPILERS variable defined there.
2220 # This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
2222 # It will go through the list of compilers, and verify that it supports the
2223 # target and source that are needed. If it is not suitable, then the next
2224 # compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
2227 # Once the which compiler to use has been figured out, it is set to
2230 # If you hadn't guessed, JAVA_PKG_FORCE_COMPILER is for testing only.
2232 # If the user doesn't defined anything in JAVA_PKG_COMPILERS_CONF, or no
2233 # suitable compiler was found there, then the default is to use javac provided
2234 # by the current VM.
2237 # @RETURN name of the compiler to use
2238 java-pkg_init-compiler_() {
2239 debug-print-function ${FUNCNAME} $*
2241 if [[ -n ${GENTOO_COMPILER} ]]; then
2242 debug-print "GENTOO_COMPILER already set"
2247 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
2248 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
2250 compilers=${JAVA_PKG_FORCE_COMPILER}
2253 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
2255 # Figure out if we should announce what compiler we're using
2257 for compiler in ${compilers}; do
2258 debug-print "Checking ${compiler}..."
2259 # javac should always be alright
2260 if [[ ${compiler} = "javac" ]]; then
2261 debug-print "Found javac... breaking"
2262 export GENTOO_COMPILER="javac"
2266 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
2267 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
2268 einfo "Filtering ${compiler}" >&2
2273 # for non-javac, we need to make sure it supports the right target and
2275 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
2276 if [[ -f ${compiler_env} ]]; then
2277 local desired_target="$(java-pkg_get-target)"
2278 local desired_source="$(java-pkg_get-source)"
2281 # Verify that the compiler supports target
2282 local supported_target=$(source ${compiler_env} 1>/dev/null 2>&1; echo ${SUPPORTED_TARGET})
2283 if ! has ${desired_target} ${supported_target}; then
2284 ewarn "${compiler} does not support -target ${desired_target}, skipping"
2288 # Verify that the compiler supports source
2289 local supported_source=$(source ${compiler_env} 1>/dev/null 2>&1; echo ${SUPPORTED_SOURCE})
2290 if ! has ${desired_source} ${supported_source}; then
2291 ewarn "${compiler} does not support -source ${desired_source}, skipping"
2295 # if you get here, then the compiler should be good to go
2296 export GENTOO_COMPILER="${compiler}"
2299 ewarn "Could not find configuration for ${compiler}, skipping"
2300 ewarn "Perhaps it is not installed?"
2305 # If it hasn't been defined already, default to javac
2306 if [[ -z ${GENTOO_COMPILER} ]]; then
2307 if [[ -n ${compilers} ]]; then
2308 einfo "No suitable compiler found: defaulting to JDK default for compilation" >&2
2310 # probably don't need to notify users about the default.
2311 :;#einfo "Defaulting to javac for compilation" >&2
2313 if java-config -g GENTOO_COMPILER 2> /dev/null; then
2314 export GENTOO_COMPILER=$(java-config -g GENTOO_COMPILER)
2316 export GENTOO_COMPILER=javac
2319 einfo "Using ${GENTOO_COMPILER} for compilation" >&2
2324 # @FUNCTION: init_paths_
2327 # Initializes some variables that will be used. These variables are mostly used
2328 # to determine where things will eventually get installed.
2329 java-pkg_init_paths_() {
2330 debug-print-function ${FUNCNAME} $*
2333 if [[ "${SLOT%/*}" == "0" ]] ; then
2334 JAVA_PKG_NAME="${PN}"
2336 JAVA_PKG_NAME="${PN}-${SLOT%/*}"
2339 JAVA_PKG_SHAREPATH="/usr/share/${JAVA_PKG_NAME}"
2340 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/"
2341 JAVA_PKG_ENV="${ED}${JAVA_PKG_SHAREPATH}/package.env"
2342 JAVA_PKG_VIRTUALS_PATH="/usr/share/java-config-2/virtuals"
2343 JAVA_PKG_VIRTUAL_PROVIDER="${ED}${JAVA_PKG_VIRTUALS_PATH}/${JAVA_PKG_NAME}"
2345 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib"
2346 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="/usr/$(get_libdir)/${JAVA_PKG_NAME}"
2347 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps"
2349 # TODO maybe only print once?
2350 debug-print "JAVA_PKG_SHAREPATH: ${JAVA_PKG_SHAREPATH}"
2351 debug-print "JAVA_PKG_ENV: ${JAVA_PKG_ENV}"
2352 debug-print "JAVA_PKG_JARDEST: ${JAVA_PKG_JARDEST}"
2353 debug-print "JAVA_PKG_LIBDEST: ${JAVA_PKG_LIBDEST}"
2354 debug-print "JAVA_PKG_WARDEST: ${JAVA_PKG_WARDEST}"
2357 # @FUNCTION: java-pkg_do_write_
2360 # Writes the package.env out to disk.
2362 # TODO change to do-write, to match everything else
2363 java-pkg_do_write_() {
2364 debug-print-function ${FUNCNAME} $*
2365 java-pkg_init_paths_
2366 # Create directory for package.env
2367 dodir "${JAVA_PKG_SHAREPATH}"
2369 # Create package.env
2371 echo "DESCRIPTION=\"${DESCRIPTION}\""
2372 echo "GENERATION=\"2\""
2373 echo "SLOT=\"${SLOT}\""
2374 echo "CATEGORY=\"${CATEGORY}\""
2375 echo "PVR=\"${PVR}\""
2377 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
2378 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
2379 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
2380 [[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
2381 && echo "DEPEND=\"$(sort -u "${JAVA_PKG_DEPEND_FILE}" | tr '\n' ':')\""
2382 [[ -f "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]] \
2383 && echo "OPTIONAL_DEPEND=\"$(sort -u "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" | tr '\n' ':')\""
2384 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
2385 [[ -f "${JAVA_PKG_BUILD_DEPEND_FILE}" ]] \
2386 && echo "BUILD_DEPEND=\"$(sort -u "${JAVA_PKG_BUILD_DEPEND_FILE}" | tr '\n' ':')\""
2387 ) > "${JAVA_PKG_ENV}"
2389 # register target/source
2390 local target="$(java-pkg_get-target)"
2391 local source="$(java-pkg_get-source)"
2392 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
2393 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
2395 # register javadoc info
2396 [[ -n ${JAVADOC_PATH} ]] && echo "JAVADOC_PATH=\"${JAVADOC_PATH}\"" \
2398 # register source archives
2399 [[ -n ${JAVA_SOURCES} ]] && echo "JAVA_SOURCES=\"${JAVA_SOURCES}\"" \
2402 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
2403 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
2405 # extra env variables
2406 if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
2407 cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}" || die
2408 # nested echo to remove leading/trailing spaces
2409 echo "ENV_VARS=\"$(echo ${JAVA_PKG_EXTRA_ENV_VARS})\"" \
2410 >> "${JAVA_PKG_ENV}" || die
2413 # Strip unnecessary leading and trailing colons
2414 # TODO try to cleanup if possible
2415 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
2418 # @FUNCTION: java-pkg_record-jar_
2421 # Record an (optional) dependency to the package.env
2424 # --optional - record dependency as optional
2425 # --build - record dependency as build_only
2426 # $1 - package to record
2427 # $2 - (optional) jar of package to record
2429 JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2430 JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
2431 JAVA_PKG_BUILD_DEPEND_FILE="${T}/java-pkg-build-depend"
2433 java-pkg_record-jar_() {
2434 debug-print-function ${FUNCNAME} $*
2436 local depend_file="${JAVA_PKG_DEPEND_FILE}"
2438 "--optional") depend_file="${JAVA_PKG_OPTIONAL_DEPEND_FILE}"; shift;;
2439 "--build-only") depend_file="${JAVA_PKG_BUILD_DEPEND_FILE}"; shift;;
2442 local pkg=${1} jar=${2} append
2443 if [[ -z "${jar}" ]]; then
2446 append="$(basename ${jar})@${pkg}"
2449 echo "${append}" >> "${depend_file}"
2452 # @FUNCTION: java-pkg_append_
2455 # Appends a value to a variable
2459 # $1 variable name to modify
2460 # $2 value to append
2463 # java-pkg_append_ CLASSPATH foo.jar
2465 java-pkg_append_() {
2466 debug-print-function ${FUNCNAME} $*
2468 local var="${1}" value="${2}"
2469 if [[ -z "${!var}" ]] ; then
2470 export ${var}="${value}"
2472 local oldIFS=${IFS} cur haveit
2474 for cur in ${!var}; do
2475 if [[ ${cur} == ${value} ]]; then
2480 [[ -z ${haveit} ]] && export ${var}="${!var}:${value}"
2485 # @FUNCTION: java-pkg_expand_dir_
2488 # Gets the full path of the file/directory's parent.
2491 # $1 - file/directory to find parent directory for
2493 # @RETURN: path to $1's parent directory
2494 java-pkg_expand_dir_() {
2495 pushd "$(dirname "${1}")" >/dev/null 2>&1 || die
2497 popd >/dev/null 2>&1 || die
2500 # @FUNCTION: java-pkg_func-exists
2503 # Does the indicated function exist?
2504 # @RETURN: 0 - function is declared, 1 - function is undeclared
2505 java-pkg_func-exists() {
2506 declare -F ${1} > /dev/null
2509 # @FUNCTION: java-pkg_setup-vm
2512 # Sets up the environment for a specific VM
2513 java-pkg_setup-vm() {
2514 debug-print-function ${FUNCNAME} $*
2516 local vendor="$(java-pkg_get-vm-vendor)"
2517 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
2518 addpredict "/dev/random"
2519 elif [[ "${vendor}" == "ibm" ]]; then
2520 addpredict "/proc/self/maps"
2521 addpredict "/proc/cpuinfo"
2522 addpredict "/proc/self/coredump_filter"
2523 elif [[ "${vendor}" == "oracle" ]]; then
2524 addpredict "/dev/random"
2525 addpredict "/proc/self/coredump_filter"
2526 elif [[ "${vendor}" == icedtea* ]] && java-pkg_is-vm-version-ge "1.7" ; then
2527 addpredict "/dev/random"
2528 addpredict "/proc/self/coredump_filter"
2529 elif [[ "${vendor}" == "jrockit" ]]; then
2530 addpredict "/proc/cpuinfo"
2534 # @FUNCTION: java-pkg_needs-vm
2537 # Does the current package depend on virtual/jdk or does it set
2538 # JAVA_PKG_WANT_BUILD_VM?
2540 # @RETURN: 0 - Package depends on virtual/jdk; 1 - Package does not depend on virtual/jdk
2541 java-pkg_needs-vm() {
2542 debug-print-function ${FUNCNAME} $*
2544 if [[ -n "$(echo ${JAVA_PKG_NV_DEPEND:-${DEPEND}} | sed -e '\:virtual/jdk:!d')" ]]; then
2548 [[ -n "${JAVA_PKG_WANT_BUILD_VM}" ]] && return 0
2553 # @FUNCTION: java-pkg_get-current-vm
2555 # @RETURN - The current VM being used
2556 java-pkg_get-current-vm() {
2560 # @FUNCTION: java-pkg_get-vm-vendor
2562 # @RETURN - The vendor of the current VM
2563 java-pkg_get-vm-vendor() {
2564 debug-print-function ${FUNCNAME} $*
2566 local vm="$(java-pkg_get-current-vm)"
2571 # @FUNCTION: java-pkg_get-vm-version
2573 # @RETURN - The version of the current VM
2574 java-pkg_get-vm-version() {
2575 debug-print-function ${FUNCNAME} $*
2577 java-config -g PROVIDES_VERSION
2580 # @FUNCTION: java-pkg_build-vm-from-handle
2583 # Selects a build vm from a list of vm handles. First checks for the system-vm
2584 # beeing usable, then steps through the listed handles till a suitable vm is
2587 # @RETURN - VM handle of an available JDK
2588 java-pkg_build-vm-from-handle() {
2589 debug-print-function ${FUNCNAME} "$*"
2592 vm=$(java-pkg_get-current-vm 2>/dev/null)
2593 if [[ $? -eq 0 ]]; then
2594 if has ${vm} ${JAVA_PKG_WANT_BUILD_VM}; then
2600 for vm in ${JAVA_PKG_WANT_BUILD_VM}; do
2601 if java-config-2 --select-vm=${vm} 2>/dev/null; then
2607 eerror "${FUNCNAME}: No vm found for handles: ${JAVA_PKG_WANT_BUILD_VM}"
2611 # @FUNCTION: java-pkg_switch-vm
2614 # Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
2615 # verify that the current VM is sufficient.
2616 # Setup the environment for the VM being used.
2617 java-pkg_switch-vm() {
2618 debug-print-function ${FUNCNAME} $*
2620 if java-pkg_needs-vm; then
2621 # Use the VM specified by JAVA_PKG_FORCE_VM
2622 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
2623 # If you're forcing the VM, I hope you know what your doing...
2624 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
2625 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
2626 # if we're allowed to switch the vm...
2627 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
2628 # if there is an explicit list of handles to choose from
2629 if [[ -n "${JAVA_PKG_WANT_BUILD_VM}" ]]; then
2630 debug-print "JAVA_PKG_WANT_BUILD_VM used: ${JAVA_PKG_WANT_BUILD_VM}"
2631 GENTOO_VM=$(java-pkg_build-vm-from-handle)
2632 if [[ $? != 0 ]]; then
2633 eerror "${FUNCNAME}: No VM found for handles: ${JAVA_PKG_WANT_BUILD_VM}"
2634 die "${FUNCNAME}: Failed to determine VM for building"
2636 # JAVA_PKG_WANT_SOURCE and JAVA_PKG_WANT_TARGET are required as
2637 # they can't be deduced from handles.
2638 if [[ -z "${JAVA_PKG_WANT_SOURCE}" ]]; then
2639 eerror "JAVA_PKG_WANT_BUILD_VM specified but not JAVA_PKG_WANT_SOURCE"
2640 die "Specify JAVA_PKG_WANT_SOURCE"
2642 if [[ -z "${JAVA_PKG_WANT_TARGET}" ]]; then
2643 eerror "JAVA_PKG_WANT_BUILD_VM specified but not JAVA_PKG_WANT_TARGET"
2644 die "Specify JAVA_PKG_WANT_TARGET"
2646 # otherwise determine a vm from dep string
2648 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
2649 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
2650 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
2651 eerror "Unable to determine VM for building from dependencies:"
2652 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
2653 die "Failed to determine VM for building."
2657 # otherwise just make sure the current VM is sufficient
2659 java-pkg_ensure-vm-version-sufficient
2661 debug-print "Using: $(java-config -f)"
2665 export JAVA=$(java-config --java)
2666 export JAVAC=$(java-config --javac)
2667 JAVACFLAGS="$(java-pkg_javac-args)"
2668 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
2671 export JAVA_HOME="$(java-config -g JAVA_HOME)"
2672 export JDK_HOME=${JAVA_HOME}
2674 #TODO If you know a better solution let us know.
2675 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
2677 local tann="${T}/announced-vm"
2678 # With the hooks we should only get here once from pkg_setup but better safe than sorry
2679 # if people have for example modified eclasses some where
2680 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
2681 einfo "Using: $(java-config -f)"
2682 [[ ! -f "${tann}" ]] && touch "${tann}"
2686 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!"
2690 # @FUNCTION: java-pkg_die
2693 # Enhanced die for Java packages, which displays some information that may be
2694 # useful for debugging bugs on bugzilla.
2695 #register_die_hook java-pkg_die
2696 if ! has java-pkg_die ${EBUILD_DEATH_HOOKS}; then
2697 EBUILD_DEATH_HOOKS="${EBUILD_DEATH_HOOKS} java-pkg_die"
2701 echo "!!! When you file a bug report, please include the following information:" >&2
2702 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2
2703 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2
2704 echo "and of course, the output of emerge --info =${P}" >&2
2709 # List jars in the source directory, ${S}
2710 java-pkg_jar-list() {
2711 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
2713 find "${S}" -type l -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2715 find "${S}" -type f -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2717 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2721 # @FUNCTION: java-pkg_verify-classes
2724 # Verify that the classes were compiled for the right source / target. Dies if
2727 # $1 (optional) - the file to check, otherwise checks whole ${D}
2729 java-pkg_verify-classes() {
2730 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
2732 local version_verify="/usr/bin/class-version-verify.py"
2734 if [[ ! -x "${version_verify}" ]]; then
2735 version_verify="/usr/$(get_libdir)/javatoolkit/bin/class-version-verify.py"
2738 if [[ ! -x "${version_verify}" ]]; then
2739 ewarn "Unable to perform class version checks as"
2740 ewarn "class-version-verify.py is unavailable"
2741 ewarn "Please install dev-java/javatoolkit."
2745 local target=$(java-pkg_get-target)
2747 local log="${T}/class-version-verify.log"
2748 if [[ -n "${1}" ]]; then
2749 ${version_verify} -v -t ${target} "${1}" > "${log}"
2752 ebegin "Verifying java class versions (target: ${target})"
2753 ${version_verify} -v -t ${target} -r "${D}" > "${log}"
2757 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2758 if [[ ${result} != 0 ]]; then
2759 eerror "Incorrect bytecode version found"
2760 [[ -n "${1}" ]] && eerror "in file: ${1}"
2761 eerror "See ${log} for more details."
2762 die "Incorrect bytecode found"
2766 # @FUNCTION: java-pkg_ensure-dep
2769 # Check that a package being used in jarfrom, getjars and getjar is contained
2770 # within DEPEND or RDEPEND with the correct SLOT. See this mail for details:
2771 # https://archives.gentoo.org/gentoo-dev/message/dcb644f89520f4bbb61cc7bbe45fdf6e
2774 # $1 - empty - check both vars; "runtime" or "build" - check only
2775 # RDEPEND, resp. DEPEND
2776 # $2 - Package name and slot.
2778 java-pkg_ensure-dep() {
2779 debug-print-function ${FUNCNAME} $*
2781 local limit_to="${1}"
2782 local target_pkg="${2}"
2785 # Transform into a regular expression to look for a matching package
2786 # and SLOT. SLOTs don't have to be numeric so foo-bar could either
2787 # mean foo-bar:0 or foo:bar. So you want to get your head around the
2790 # * The target package first has any dots escaped, e.g. foo-1.2
2793 # * sed then looks at the component following the last - or :
2794 # character, or the whole string if there is no - or :
2795 # character. It uses this to build a new regexp with two
2796 # significant branches.
2798 # * The first checks for the whole target package string, optionally
2799 # followed by a version number, and then :0.
2801 # * The second checks for the first part of the target package
2802 # string, optionally followed by a version number, followed by the
2803 # aforementioned component, treating that as a SLOT.
2805 local stripped_pkg=/$(sed -r 's/[-:]?([^-:]+)$/(\0(-[^:]+)?:0|(-[^:]+)?:\1)/' <<< "${target_pkg//./\\.}")\\b
2807 debug-print "Matching against: ${stripped_pkg}"
2809 # Uncomment the lines below once we've dealt with more of these
2810 # otherwise we'll be tempted to turn JAVA_PKG_STRICT off while
2811 # getting hit with a wave of bug reports. :(
2813 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ $stripped_pkg ) ]]; then
2814 dev_error="The ebuild is attempting to use ${target_pkg}, which is not "
2815 dev_error+="declared with a SLOT in DEPEND."
2816 # if is-java-strict; then
2817 # die "${dev_error}"
2819 eqawarn "java-pkg_ensure-dep: ${dev_error}"
2820 # eerror "Because you have ${target_pkg} installed,"
2821 # eerror "the package will build without problems, but please"
2822 # eerror "report this to https://bugs.gentoo.org."
2824 elif [[ ${limit_to} != build && ! ( "${RDEPEND}${PDEPEND}" =~ ${stripped_pkg} ) ]]; then
2825 dev_error="The ebuild is attempting to use ${target_pkg}, which is not "
2826 dev_error+="declared with a SLOT in [RP]DEPEND and --build-only wasn't given."
2827 # if is-java-strict; then
2828 # die "${dev_error}"
2830 eqawarn "java-pkg_ensure-dep: ${dev_error}"
2831 # eerror "The package will build without problems, but may fail to run"
2832 # eerror "if you don't have ${target_pkg} installed,"
2833 # eerror "so please report this to https://bugs.gentoo.org."
2838 java-pkg_check-phase() {
2840 local funcname=${FUNCNAME[1]}
2841 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
2842 local msg="${funcname} used outside of src_${phase}"
2843 java-pkg_announce-qa-violation "${msg}"
2847 java-pkg_check-versioned-jar() {
2850 if [[ ${jar} =~ ${PV} ]]; then
2851 java-pkg_announce-qa-violation "installing versioned jar '${jar}'"
2855 java-pkg_check-jikes() {
2856 if has jikes ${IUSE}; then
2857 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
2861 java-pkg_announce-qa-violation() {
2863 if [[ ${1} == "--nodie" ]]; then
2867 echo "Java QA Notice: $@" >&2
2868 increment-qa-violations
2869 [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
2872 increment-qa-violations() {
2873 let "JAVA_PKG_QA_VIOLATIONS+=1"
2874 export JAVA_PKG_QA_VIOLATIONS
2878 [[ -n ${JAVA_PKG_STRICT} ]]
2882 # @FUNCTION: java-pkg_clean
2884 # Java package cleaner function. This will remove all *.class and *.jar
2885 # files, removing any bundled dependencies.
2887 if [[ -z "${JAVA_PKG_NO_CLEAN}" ]]; then
2888 find "${@}" '(' -name '*.class' -o -name '*.jar' ')' -type f -delete -print || die
2892 # @FUNCTION: java-pkg_gen-cp
2895 # Java package generate classpath will create a classpath based on
2896 # special variable CP_DEPEND in the ebuild.
2900 # $1 - classpath variable either EANT_GENTOO_CLASSPATH or JAVA_GENTOO_CLASSPATH
2903 debug-print-function ${FUNCNAME} "${@}"
2906 for atom in ${CP_DEPEND}; do
2907 if [[ ${atom} =~ /(([[:alnum:]+_-]+)-[0-9]+(\.[0-9]+)*[a-z]?(_[[:alnum:]]+)*(-r[0-9]*)?|[[:alnum:]+_-]+):([[:alnum:]+_.-]+) ]]; then
2908 atom=${BASH_REMATCH[2]:-${BASH_REMATCH[1]}}
2909 [[ ${BASH_REMATCH[6]} != 0 ]] && atom+=-${BASH_REMATCH[6]}
2910 local regex="(^|\s|,)${atom}($|\s|,)"
2911 [[ ${!1} =~ ${regex} ]] || declare -g ${1}+=${!1:+,}${atom}
2913 die "Invalid CP_DEPEND atom ${atom}, ensure a SLOT is included"