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 has test ${JAVA_PKG_IUSE} && RESTRICT+=" !test? ( test )"
33 # @VARIABLE: JAVA_PKG_E_DEPEND
36 # This is a convience variable to be used from the other java eclasses. This is
37 # the version of java-config we want to use. Usually the latest stable version
38 # so that ebuilds can use new features without depending on specific versions.
39 JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.2.0-r3"
40 has source ${JAVA_PKG_IUSE} && JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} source? ( app-arch/zip )"
42 # @ECLASS-VARIABLE: JAVA_PKG_WANT_BOOTCLASSPATH
45 # The version of bootclasspath the package needs to work. Translates to a proper
46 # dependency. The bootclasspath can then be obtained by java-ant_rewrite-bootclasspath
47 if [[ -n "${JAVA_PKG_WANT_BOOTCLASSPATH}" ]]; then
48 if [[ "${JAVA_PKG_WANT_BOOTCLASSPATH}" == "1.5" ]]; then
49 JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} >=dev-java/gnu-classpath-0.98-r1:0.98"
51 eerror "Unknown value of JAVA_PKG_WANT_BOOTCLASSPATH"
52 # since die in global scope doesn't work, this will make repoman fail
53 JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} BAD_JAVA_PKG_WANT_BOOTCLASSPATH"
57 # @ECLASS-VARIABLE: JAVA_PKG_ALLOW_VM_CHANGE
59 # Allow this eclass to change the active VM?
60 # If your system VM isn't sufficient for the package, the build will fail
61 # instead of trying to switch to another VM.
63 # Overriding the default can be useful for testing specific VMs locally, but
64 # should not be used in the final ebuild.
65 JAVA_PKG_ALLOW_VM_CHANGE=${JAVA_PKG_ALLOW_VM_CHANGE:="yes"}
67 # @ECLASS-VARIABLE: JAVA_PKG_FORCE_VM
70 # Explicitly set a particular VM to use. If its not valid, it'll fall back to
71 # whatever /etc/java-config-2/build/jdk.conf would elect to use.
73 # Should only be used for testing and debugging.
75 # Example: use sun-jdk-1.5 to emerge foo:
77 # JAVA_PKG_FORCE_VM=sun-jdk-1.5 emerge foo
80 # @ECLASS-VARIABLE: JAVA_PKG_WANT_BUILD_VM
83 # A list of VM handles to choose a build VM from. If the list contains the
84 # currently active VM use that one, otherwise step through the list till a
85 # usable/installed VM is found.
87 # This allows to use an explicit list of JDKs in DEPEND instead of a virtual.
88 # Users of this variable must make sure at least one of the listed handles is
90 # Requires JAVA_PKG_WANT_SOURCE and JAVA_PKG_WANT_TARGET to be set as well.
92 # @ECLASS-VARIABLE: JAVA_PKG_WANT_SOURCE
95 # Specify a non-standard Java source version for compilation (via javac -source
96 # parameter or Ant equivalent via build.xml rewriting done by java-ant-2 eclass).
97 # Normally this is determined from the jdk version specified in DEPEND.
98 # See java-pkg_get-source function below.
100 # Should generally only be used for testing and debugging.
102 # Use 1.4 source to emerge baz
104 # JAVA_PKG_WANT_SOURCE=1.4 emerge baz
107 # @ECLASS-VARIABLE: JAVA_PKG_WANT_TARGET
110 # Same as JAVA_PKG_WANT_SOURCE (see above) but for javac -target parameter,
111 # which affects the version of generated bytecode.
112 # Normally this is determined from the jre/jdk version specified in RDEPEND.
113 # See java-pkg_get-target function below.
115 # Should generallyonly be used for testing and debugging.
117 # emerge bar to be compatible with 1.3
119 # JAVA_PKG_WANT_TARGET=1.3 emerge bar
122 # @ECLASS-VARIABLE: JAVA_PKG_DEBUG
125 # A variable to be set with "yes" or "y", or ANY string of length non equal to
126 # zero. When set, verbosity across java eclasses is increased and extra
127 # logging is displayed.
129 # JAVA_PKG_DEBUG="yes"
132 # @ECLASS-VARIABLE: JAVA_RM_FILES
135 # An array containing a list of files to remove. If defined, this array will be
136 # automatically handed over to java-pkg_rm_files for processing during the
146 # @VARIABLE: JAVA_PKG_COMPILER_DIR
149 # Directory where compiler settings are saved, without trailing slash.
150 # You probably shouldn't touch this variable except local testing.
151 JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"}
153 # @VARIABLE: JAVA_PKG_COMPILERS_CONF
156 # Path to file containing information about which compiler to use.
157 # Can be overloaded, but it should be overloaded only for local testing.
158 JAVA_PKG_COMPILERS_CONF=${JAVA_PKG_COMPILERS_CONF:="/etc/java-config-2/build/compilers.conf"}
160 # @ECLASS-VARIABLE: JAVA_PKG_FORCE_COMPILER
164 # Explicitly set a list of compilers to choose from. This is normally read from
165 # JAVA_PKG_COMPILERS_CONF.
167 # Useful for local testing.
169 # Use jikes and javac, in that order
171 # JAVA_PKG_FORCE_COMPILER="jikes javac"
174 # @ECLASS-VARIABLE: JAVA_PKG_FORCE_ANT_TASKS
177 # An $IFS separated list of ant tasks. Can be set in environment before calling
178 # emerge/ebuild to override variables set in ebuild, mainly for testing before
179 # putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in
180 # eant() call, not the dependencies specified in WANT_ANT_TASKS.
183 # JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \
184 # ebuild foo.ebuild compile
188 JAVA_PKG_QA_VIOLATIONS=0
190 # @FUNCTION: java-pkg_doexamples
191 # @USAGE: [--subdir <subdir>] <file1/dir1> [<file2> ...]
193 # Installs given arguments to /usr/share/doc/${PF}/examples
194 # If you give it only one parameter and it is a directory it will install
195 # everything in that directory to the examples directory.
199 # --subdir - If the examples need a certain directory structure
200 # $* - list of files to install
203 # java-pkg_doexamples demo
204 # java-pkg_doexamples demo/* examples/*
206 java-pkg_doexamples() {
207 debug-print-function ${FUNCNAME} $*
209 [[ ${#} -lt 1 ]] && die "At least one argument needed"
211 java-pkg_check-phase install
214 local dest=/usr/share/doc/${PF}/examples
215 if [[ ${1} == --subdir ]]; then
216 local dest=${dest}/${2}
221 if [[ ${#} = 1 && -d ${1} ]]; then
222 ( # dont want to pollute calling env
225 ) || die "Installing examples failed"
227 ( # dont want to pollute calling env
230 ) || die "Installing examples failed"
233 # Let's make a symlink to the directory we have everything else under
234 dosym "${dest}" "${JAVA_PKG_SHAREPATH}/examples" || die
237 # @FUNCTION: java-pkg_addres
238 # @USAGE: <jar> <dir> [<find arguments> ...]
240 # Adds resource files to an existing jar.
241 # It is important that the directory given is actually the root of the
242 # corresponding resource tree. The target directory as well as
243 # sources.lst, MANIFEST.MF, *.class, *.jar, and *.java files are
244 # automatically excluded. Symlinks are always followed. Additional
245 # arguments are passed through to find.
248 # java-pkg_addres ${PN}.jar resources ! -name "*.html"
251 # @param $1 - jar file
252 # @param $2 - resource tree directory
253 # @param $* - arguments to pass to find
255 debug-print-function ${FUNCNAME} $*
257 [[ ${#} -lt 2 ]] && die "at least two arguments needed"
259 local jar=$(realpath "$1" || die "realpath $1 failed")
263 pushd "${dir}" > /dev/null || die "pushd ${dir} failed"
264 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"
265 popd > /dev/null || die "popd failed"
268 # @FUNCTION: java-pkg_rm_files
269 # @USAGE: <File1.java> [File2.java] ...
271 # Remove unneeded files in ${S}.
273 # Every now and then, you'll run into situations whereby a file needs removing,
274 # be it a unit test or a regular java class.
276 # You can use this function by either:
277 # - calling it yourself in src_prepare() and feeding java-pkg_rm_files with
278 # the list of files you wish to remove.
279 # - defining an array in the ebuild named JAVA_RM_FILES with the list of files
280 # you wish to remove.
282 # Both way work and it is left to the developer's preferences. If the
283 # JAVA_RM_FILES array is defined, it will be automatically handed over to
284 # java-pkg_rm_files during the src_prepare phase.
286 # See java-utils-2_src_prepare.
289 # java-pkg_rm_files File1.java File2.java
292 # @param $* - list of files to remove.
293 java-pkg_rm_files() {
294 debug-print-function ${FUNCNAME} $*
296 for filename in "$@"; do
297 [[ ! -f "${filename}" ]] && die "${filename} is not a regular file. Aborting."
298 einfo "Removing unneeded file ${filename}"
299 rm -f "${S}/${filename}" || die "cannot remove ${filename}"
304 # @FUNCTION: java-pkg_dojar
305 # @USAGE: <jar1> [<jar2> ...]
307 # Installs any number of jars.
308 # Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default.
309 # You can use java-pkg_jarinto to change this path.
310 # You should never install a jar with a package version in the filename.
311 # Instead, use java-pkg_newjar defined below.
314 # java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar
317 # @param $* - list of jars to install
319 debug-print-function ${FUNCNAME} $*
321 [[ ${#} -lt 1 ]] && die "At least one argument needed"
323 java-pkg_check-phase install
326 # Create JARDEST if it doesn't exist
327 dodir ${JAVA_PKG_JARDEST}
331 for jar in "${@}"; do
332 local jar_basename=$(basename "${jar}")
334 java-pkg_check-versioned-jar ${jar_basename}
337 if [[ -e "${jar}" ]] ; then
338 # Don't overwrite if jar has already been installed with the same
340 local dest="${ED}${JAVA_PKG_JARDEST}/${jar_basename}"
341 if [[ -e "${dest}" ]]; then
342 ewarn "Overwriting ${dest}"
345 # install it into JARDEST if it's a non-symlink
346 if [[ ! -L "${jar}" ]] ; then
347 #but first check class version when in strict mode.
348 is-java-strict && java-pkg_verify-classes "${jar}"
351 insinto "${JAVA_PKG_JARDEST}"
353 ) || die "failed to install ${jar}"
354 java-pkg_append_ JAVA_PKG_CLASSPATH "${EPREFIX}/${JAVA_PKG_JARDEST}/${jar_basename}"
355 debug-print "installed ${jar} to ${ED}${JAVA_PKG_JARDEST}"
356 # make a symlink to the original jar if it's symlink
358 # TODO use dosym, once we find something that could use it
360 ln -s "$(readlink "${jar}")" "${ED}${JAVA_PKG_JARDEST}/${jar_basename}"
361 debug-print "${jar} is a symlink, linking accordingly"
364 die "${jar} does not exist"
368 # Extra logging if enabled.
369 if [[ -n ${JAVA_PKG_DEBUG} ]]; then
370 einfo "Verbose logging for \"${FUNCNAME}\" function"
371 einfo "Jar file(s) destination: ${JAVA_PKG_JARDEST}"
372 einfo "Jar file(s) created: ${@}"
373 einfo "Complete command:"
374 einfo "${FUNCNAME} ${@}"
380 # @FUNCTION: java-pkg_regjar
381 # @USAGE: </path/to/installed/jar>
383 # Records an already installed (in ${D}) jar in the package.env
384 # This would mostly be used if the package has make or a custom script to
388 # if you want to use shell expansion, you have to use ${D}/... as the for in
389 # this function will not be able to expand the path, here's an example:
392 # java-pkg_regjar ${D}/opt/my-java/lib/*.jar
396 # TODO should we be making sure the jar is present on ${D} or wherever?
398 debug-print-function ${FUNCNAME} $*
400 java-pkg_check-phase install
402 [[ ${#} -lt 1 ]] && die "at least one argument needed"
406 local jar jar_dir jar_file
407 for jar in "${@}"; do
408 # TODO use java-pkg_check-versioned-jar
409 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
410 [[ -d "${jar}" || -d "${D}${jar}" ]] \
411 && die "Called ${FUNCNAME} on a directory $*"
413 #check that class version correct when in strict mode
414 is-java-strict && java-pkg_verify-classes "${jar}"
416 # nelchael: we should strip ${D} in this case too, here's why:
418 # java-pkg_regjar ${D}/opt/java/*.jar
419 # such call will fall into this case (-e ${jar}) and will
420 # record paths with ${D} in package.env
421 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
423 if [[ ${jar} = *\** ]]; then
424 eerror "The argument ${jar} to ${FUNCNAME}"
425 eerror "has * in it. If you want it to glob in"
426 eerror '${D} add ${D} to the argument.'
428 debug-print "${jar} or ${D}${jar} not found"
429 die "${jar} does not exist"
436 # @FUNCTION: java-pkg_newjar
437 # @USAGE: <path/to/oldname.jar> [<newname.jar>]
439 # Installs a jar with a new name (defaults to $PN.jar)
441 # For example, installs a versioned jar without the version
443 debug-print-function ${FUNCNAME} $*
445 local original_jar="${1}"
446 local new_jar="${2:-${PN}.jar}"
447 local new_jar_dest="${T}/${new_jar}"
449 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
450 [[ ! -f ${original_jar} ]] \
451 && die "${original_jar} does not exist or is not a file!"
453 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
454 cp "${original_jar}" "${new_jar_dest}" \
455 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
456 java-pkg_dojar "${new_jar_dest}"
459 # @FUNCTION: java-pkg_addcp
460 # @USAGE: <classpath>
462 # Add something to the package's classpath. For jars, you should use dojar,
463 # newjar, or regjar. This is typically used to add directories to the classpath.
464 # The parameters of this function are appended to JAVA_PKG_CLASSPATH
466 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
470 # @FUNCTION: java-pkg_doso
471 # @USAGE: <path/to/file1.so> [...]
473 # Installs any number of JNI libraries
474 # They will be installed into /usr/lib by default, but java-pkg_sointo
475 # can be used change this path
482 debug-print-function ${FUNCNAME} $*
484 java-pkg_check-phase install
486 [[ ${#} -lt 1 ]] && die "${FUNCNAME} requires at least one argument"
493 # if the lib exists...
494 if [[ -e "${lib}" ]] ; then
495 # install if it isn't a symlink
496 if [[ ! -L "${lib}" ]] ; then
498 insinto "${JAVA_PKG_LIBDEST}"
501 ) || die "failed to install ${lib}"
502 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
503 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
504 # otherwise make a symlink to the symlink's origin
506 dosym "$(readlink "${lib}")" "${JAVA_PKG_LIBDEST}/${lib##*/}"
507 debug-print "${lib} is a symlink, linking accordantly"
511 die "${lib} does not exist"
518 # @FUNCTION: java-pkg_regso
519 # @USAGE: <file1.so> [...]
521 # Registers an already installed JNI library in package.env.
525 # $@ - JNI libraries to register
528 # java-pkg_regso *.so /path/*.so
531 debug-print-function ${FUNCNAME} $*
533 java-pkg_check-phase install
535 [[ ${#} -lt 1 ]] && die "${FUNCNAME} requires at least one argument"
541 # Check the absolute path of the lib
542 if [[ -e "${lib}" ]] ; then
543 target_dir="$(java-pkg_expand_dir_ ${lib})"
544 java-pkg_append_ JAVA_PKG_LIBRARY "/${target_dir#${D}}"
545 # Check the path of the lib relative to ${D}
546 elif [[ -e "${D}${lib}" ]]; then
547 target_dir="$(java-pkg_expand_dir_ ${D}${lib})"
548 java-pkg_append_ JAVA_PKG_LIBRARY "${target_dir}"
550 die "${lib} does not exist"
557 # @FUNCTION: java-pkg_jarinto
558 # @USAGE: </path/to/install/jars/into>
560 # Changes the path jars are installed into via subsequent java-pkg_dojar calls.
562 debug-print-function ${FUNCNAME} $*
564 JAVA_PKG_JARDEST="${1}"
567 # @FUNCTION: java-pkg_sointo
568 # @USAGE: </path/to/install/sofiles/into>
570 # Changes the path that JNI libraries are installed into via subsequent
571 # java-pkg_doso calls.
573 debug-print-function ${FUNCNAME} $*
575 JAVA_PKG_LIBDEST="${1}"
578 # @FUNCTION: java-pkg_dohtml
579 # @USAGE: <path/to/javadoc/documentation> [...]
581 # Install Javadoc HTML documentation. Usage of java-pkg_dojavadoc is preferred.
584 # java-pkg_dohtml dist/docs/
587 debug-print-function ${FUNCNAME} $*
589 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
591 # Do away with dohtml and rely on dodoc instead to do the deed.
595 # This probably shouldn't be here but it provides
596 # a reasonable way to catch # docs for all of the
598 java-pkg_recordjavadoc
601 # @FUNCTION: java-pkg_dojavadoc
602 # @USAGE: [--symlink destination] <path/to/javadocs/root>
604 # Installs javadoc documentation. This should be controlled by the doc use flag.
608 # $1: optional --symlink creates to symlink like this for html
609 # documentation bundles.
610 # $2: - The javadoc root directory.
613 # java-pkg_dojavadoc docs/api
614 # java-pkg_dojavadoc --symlink apidocs docs/api
616 java-pkg_dojavadoc() {
617 debug-print-function ${FUNCNAME} $*
619 # For html documentation bundles that link to Javadoc
621 if [[ ${1} = --symlink ]]; then
627 local dest=/usr/share/doc/${PF}/html
631 java-pkg_check-phase install
634 [[ -z "${dir}" ]] && die "Must specify a directory!"
635 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!"
636 if [[ ! -e "${dir}/index.html" ]]; then
637 local msg="No index.html in javadoc directory"
639 is-java-strict && die "${msg}"
642 if [[ -e ${D}/${dest}/api ]]; then
643 eerror "${dest} already exists. Will not overwrite."
647 # Renaming to match our directory layout
649 local dir_to_install="${dir}"
650 if [[ "$(basename "${dir}")" != "api" ]]; then
651 dir_to_install="${T}/api"
653 cp -r "${dir}" "${dir_to_install}" || die "cp failed"
656 # Actual installation
657 java-pkg_dohtml -r "${dir_to_install}"
659 # Let's make a symlink to the directory we have everything else under
660 dosym ${dest}/api "${JAVA_PKG_SHAREPATH}/api" || die
662 if [[ ${symlink} ]]; then
663 debug-print "symlinking ${dest}/{api,${symlink}}"
664 dosym ${dest}/{api,${symlink}} || die
667 # Extra logging if enabled.
668 if [[ -n ${JAVA_PKG_DEBUG} ]]; then
669 einfo "Verbose logging for \"${FUNCNAME}\" function"
670 einfo "Documentation destination: ${dest}"
671 einfo "Directory to install: ${dir_to_install}"
672 einfo "Complete command:"
673 einfo "${FUNCNAME} ${@}"
677 # @FUNCTION: java-pkg_dosrc
678 # @USAGE: <path/to/sources> [...]
680 # Installs a zip containing the source for a package, so it can used in
681 # from IDEs like eclipse and netbeans.
682 # Ebuild needs to DEPEND on app-arch/zip to use this. It also should be controlled by USE=source.
686 # java-pkg_dosrc src/*
689 # TODO change so it the arguments it takes are the base directories containing
692 # TODO should we be able to handle multiple calls to dosrc? -nichoj
694 # TODO maybe we can take an existing zip/jar? -nichoj
696 # FIXME apparently this fails if you give it an empty directories
698 debug-print-function ${FUNCNAME} $*
700 [ ${#} -lt 1 ] && die "At least one argument needed"
702 java-pkg_check-phase install
704 [[ ${#} -lt 1 ]] && die "At least one argument needed"
706 if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
707 local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
708 java-pkg_announce-qa-violation ${msg}
713 local zip_name="${PN}-src.zip"
714 local zip_path="${T}/${zip_name}"
716 for dir in "${@}"; do
717 local dir_parent=$(dirname "${dir}")
718 local dir_name=$(basename "${dir}")
719 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
720 zip -q -r ${zip_path} ${dir_name} -i '*.java'
722 # 12 means zip has nothing to do
723 if [[ ${result} != 12 && ${result} != 0 ]]; then
724 die "failed to zip ${dir_name}"
726 popd >/dev/null || die
731 insinto "${JAVA_PKG_SOURCESPATH}"
733 ) || die "Failed to install source"
735 JAVA_SOURCES="${JAVA_PKG_SOURCESPATH}/${zip_name}"
737 # Extra logging if enabled.
738 if [[ -n ${JAVA_PKG_DEBUG} ]]; then
739 einfo "Verbose logging for \"${FUNCNAME}\" function"
740 einfo "Zip filename created: ${zip_name}"
741 einfo "Zip file destination: ${JAVA_PKG_SOURCESPATH}"
742 einfo "Directories zipped: ${@}"
743 einfo "Complete command:"
744 einfo "${FUNCNAME} ${@}"
750 # @FUNCTION: java-pkg_dolauncher
751 # @USAGE: <filename> [options]
753 # Make a wrapper script to lauch/start this package
754 # If necessary, the wrapper will switch to the appropriate VM.
756 # Can be called without parameters if the package installs only one jar
757 # that has the Main-class attribute set. The wrapper will be named ${PN}.
761 # $1 - filename of launcher to create
762 # $2 - options, as follows:
763 # --main the.main.class.to.start
764 # --jar /the/jar/too/launch.jar or just <name>.jar
765 # --java_args 'Extra arguments to pass to java'
766 # --pkg_args 'Extra arguments to pass to the package'
767 # --pwd Directory the launcher changes to before executing java
768 # -into Directory to install the launcher to, instead of /usr/bin
769 # -pre Prepend contents of this file to the launcher
771 java-pkg_dolauncher() {
772 debug-print-function ${FUNCNAME} $*
774 java-pkg_check-phase install
777 if [[ ${#} = 0 ]]; then
784 # TODO rename to launcher
785 local target="${T}/${name}"
786 local var_tmp="${T}/launcher_variables_tmp"
789 # Process the other the rest of the arguments
790 while [[ -n "${1}" && -n "${2}" ]]; do
791 local var="${1}" value="${2}"
792 if [[ "${var:0:2}" == "--" ]]; then
794 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
795 local gjl_${var}="${value}"
796 elif [[ "${var}" == "-into" ]]; then
797 target_dir="${value}"
798 elif [[ "${var}" == "-pre" ]]; then
804 # Test if no --jar and --main arguments were given and
805 # in that case check if the package only installs one jar
807 if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
808 local cp="${JAVA_PKG_CLASSPATH}"
809 if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
810 echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
812 local msg="Not enough information to create a launcher given."
813 msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
818 # Write the actual script
819 echo "#!/bin/bash" > "${target}"
820 if [[ -n "${pre}" ]]; then
821 if [[ -f "${pre}" ]]; then
822 cat "${pre}" >> "${target}"
824 die "-pre specified file '${pre}' does not exist"
827 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
828 cat "${var_tmp}" >> "${target}"
830 echo "source ${EPREFIX}/usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
832 if [[ -n "${target_dir}" ]]; then
844 # @FUNCTION: java-pkg_dowar
849 debug-print-function ${FUNCNAME} $*
851 # Check for arguments
852 [[ ${#} -lt 1 ]] && die "At least one argument needed"
853 java-pkg_check-phase install
860 # TODO evaluate if we want to handle symlinks differently -nichoj
862 if [[ -L "${war}" ]] ; then
864 warpath="${T}$(basename "${war}")"
865 # Check for directory
866 # TODO evaluate if we want to handle directories differently -nichoj
867 elif [[ -d "${war}" ]] ; then
868 echo "dowar: warning, skipping directory ${war}"
874 # Install those files like you mean it
877 insinto "${JAVA_PKG_WARDEST}"
883 # @FUNCTION: java-pkg_recordjavadoc
886 # Scan for JavaDocs, and record their existence in the package.env file
888 # TODO make sure this in the proper section
889 java-pkg_recordjavadoc()
891 debug-print-function ${FUNCNAME} $*
892 # the find statement is important
893 # as some packages include multiple trees of javadoc
894 JAVADOC_PATH="$(find ${D}/usr/share/doc/ -name allclasses-frame.html -printf '%h:')"
895 # remove $D - TODO: check this is ok with all cases of the above
896 JAVADOC_PATH="${JAVADOC_PATH//${D}}"
897 if [[ -n "${JAVADOC_PATH}" ]] ; then
898 debug-print "javadocs found in ${JAVADOC_PATH%:}"
901 debug-print "No javadocs found"
906 # @FUNCTION: java-pkg_jar-from
907 # @USAGE: [--build-only] [--with-dependencies] [--virtual] [--into dir] <package> [<package.jar>] [<destination.jar>]
909 # Makes a symlink to a jar from a certain package
910 # A lot of java packages include dependencies in a lib/ directory
911 # You can use this function to replace these bundled dependencies.
912 # The dependency is recorded into package.env DEPEND line, unless "--build-only"
913 # is passed as the very first argument, for jars that have to be present only
914 # at build time and are not needed on runtime (junit testing etc).
917 # Example: get all jars from xerces slot 2
918 # java-pkg_jar-from xerces-2
920 # Example: get a specific jar from xerces slot 2
921 # java-pkg_jar-from xerces-2 xml-apis.jar
923 # Example: get a specific jar from xerces slot 2, and name it diffrently
924 # java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
926 # Example: get junit.jar which is needed only for building
927 # java-pkg_jar-from --build-only junit junit.jar
932 # --build-only - makes the jar(s) not added into package.env DEPEND line.
933 # (assumed automatically when called inside src_test)
934 # --with-dependencies - get jars also from requested package's dependencies
936 # --virtual - Packages passed to this function are to be handled as virtuals
937 # and will not have individual jar dependencies recorded.
938 # --into $dir - symlink jar(s) into $dir (must exist) instead of .
939 # $1 - Package to get jars from, or comma-separated list of packages in
940 # case other parameters are not used.
941 # $2 - jar from package. If not specified, all jars will be used.
942 # $3 - When a single jar is specified, destination filename of the
943 # symlink. Defaults to the name of the jar.
946 # TODO could probably be cleaned up a little
947 java-pkg_jar-from() {
948 debug-print-function ${FUNCNAME} $*
956 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
958 while [[ "${1}" == --* ]]; do
959 if [[ "${1}" = "--build-only" ]]; then
961 elif [[ "${1}" = "--with-dependencies" ]]; then
962 deep="--with-dependencies"
963 elif [[ "${1}" = "--virtual" ]]; then
965 elif [[ "${1}" = "--into" ]]; then
969 die "java-pkg_jar-from called with unknown parameter: ${1}"
974 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
976 [[ -z ${target_pkg} ]] && die "Must specify a package"
978 if [[ "${EAPI}" == "1" ]]; then
979 target_pkg="${target_pkg//:/-}"
982 # default destjar to the target jar
983 [[ -z "${destjar}" ]] && destjar="${target_jar}"
985 local error_msg="There was a problem getting the classpath for ${target_pkg}."
987 classpath="$(java-config ${deep} --classpath=${target_pkg})"
988 [[ $? != 0 ]] && die ${error_msg}
990 # When we have commas this functions is called to bring jars from multiple
991 # packages. This affects recording of dependencencies performed later
992 # which expects one package only, so we do it here.
993 if [[ ${target_pkg} = *,* ]]; then
994 for pkg in ${target_pkg//,/ }; do
995 java-pkg_ensure-dep "${build_only}" "${pkg}"
996 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
998 # setting this disables further record-jar_ calls later
1001 java-pkg_ensure-dep "${build_only}" "${target_pkg}"
1004 # Record the entire virtual as a dependency so that
1005 # no jars are missed.
1006 if [[ -z "${build_only}" && -n "${virtual}" ]]; then
1007 java-pkg_record-jar_ "${target_pkg}"
1008 # setting this disables further record-jars_ calls later
1012 pushd ${destdir} > /dev/null \
1013 || die "failed to change directory to ${destdir}"
1016 for jar in ${classpath//:/ }; do
1017 local jar_name=$(basename "${jar}")
1018 if [[ ! -f "${jar}" ]] ; then
1019 debug-print "${jar} from ${target_pkg} does not exist"
1020 die "Installation problems with jars in ${target_pkg} - is it installed?"
1022 # If no specific target jar was indicated, link it
1023 if [[ -z "${target_jar}" ]] ; then
1024 [[ -f "${target_jar}" ]] && rm "${target_jar}"
1026 || die "Failed to make symlink from ${jar} to ${jar_name}"
1027 if [[ -z "${record_jar}" ]]; then
1028 if [[ -z "${build_only}" ]]; then
1029 java-pkg_record-jar_ "${target_pkg}" "${jar}"
1031 java-pkg_record-jar_ --build-only "${target_pkg}" "${jar}"
1034 # otherwise, if the current jar is the target jar, link it
1035 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
1036 [[ -f "${destjar}" ]] && rm "${destjar}"
1037 ln -snf "${jar}" "${destjar}" \
1038 || die "Failed to make symlink from ${jar} to ${destjar}"
1039 if [[ -z "${record_jar}" ]]; then
1040 if [[ -z "${build_only}" ]]; then
1041 java-pkg_record-jar_ "${target_pkg}" "${jar}"
1043 java-pkg_record-jar_ --build-only "${target_pkg}" "${jar}"
1046 popd > /dev/null || die
1050 popd > /dev/null || die
1051 # if no target was specified, we're ok
1052 if [[ -z "${target_jar}" ]] ; then
1054 # otherwise, die bitterly
1056 die "Failed to find ${target_jar:-jar} in ${target_pkg}"
1060 # @FUNCTION: java-pkg_jarfrom
1062 # See java-pkg_jar-from
1063 java-pkg_jarfrom() {
1064 java-pkg_jar-from "$@"
1067 # @FUNCTION: java-pkg_getjars
1068 # @USAGE: [--build-only] [--with-dependencies] <package1>[,<package2>...]
1070 # Get the classpath provided by any number of packages
1071 # Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
1072 # The providing packages are recorded as dependencies into package.env DEPEND
1073 # line, unless "--build-only" is passed as the very first argument, for jars
1074 # that have to be present only at build time and are not needed on runtime
1075 # (junit testing etc).
1078 # Example: Get the classpath for xerces-2 and xalan,
1079 # java-pkg_getjars xerces-2,xalan
1082 # /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
1086 # --build-only - makes the jar(s) not added into package.env DEPEND line.
1087 # (assumed automatically when called inside src_test)
1088 # --with-dependencies - get jars also from requested package's dependencies
1090 # $1 - list of packages to get jars from
1091 # (passed to java-config --classpath)
1093 java-pkg_getjars() {
1094 debug-print-function ${FUNCNAME} $*
1099 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1101 while [[ "${1}" == --* ]]; do
1102 if [[ "${1}" = "--build-only" ]]; then
1104 elif [[ "${1}" = "--with-dependencies" ]]; then
1105 deep="--with-dependencies"
1107 die "java-pkg_jar-from called with unknown parameter: ${1}"
1112 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
1117 if [[ "${EAPI}" == "1" ]]; then
1121 jars="$(java-config ${deep} --classpath=${pkgs})"
1122 [[ $? != 0 ]] && die "java-config --classpath=${pkgs} failed"
1123 debug-print "${pkgs}:${jars}"
1125 for pkg in ${pkgs//,/ }; do
1126 java-pkg_ensure-dep "${build_only}" "${pkg}"
1129 for pkg in ${pkgs//,/ }; do
1130 if [[ -z "${build_only}" ]]; then
1131 java-pkg_record-jar_ "${pkg}"
1133 java-pkg_record-jar_ --build-only "${pkg}"
1140 # @FUNCTION: java-pkg_getjar
1141 # @USAGE: [--build-only] [--virtual] <package> <jarfile>
1143 # Get the complete path of a single jar from a package
1144 # The providing package is recorded as runtime dependency into package.env
1145 # DEPEND line, unless "--build-only" is passed as the very first argument, for
1146 # jars that have to be present only at build time and are not needed on runtime
1147 # (junit testing etc).
1151 # java-pkg_getjar xerces-2 xml-apis.jar
1153 # /usr/share/xerces-2/lib/xml-apis.jar
1156 # --build-only - makes the jar not added into package.env DEPEND line.
1157 # --virtual - Packages passed to this function are to be handled as virtuals
1158 # and will not have individual jar dependencies recorded.
1159 # $1 - package to use
1163 debug-print-function ${FUNCNAME} $*
1169 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1171 while [[ "${1}" == --* ]]; do
1172 if [[ "${1}" = "--build-only" ]]; then
1174 elif [[ "${1}" == "--virtual" ]]; then
1177 die "java-pkg_getjar called with unknown parameter: ${1}"
1182 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
1184 local pkg="${1}" target_jar="${2}" jar
1186 if [[ "${EAPI}" == "1" ]]; then
1190 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
1191 [[ -z ${target_jar} ]] && die "Must specify jar to get"
1193 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
1195 classpath=$(java-config --classpath=${pkg})
1196 [[ $? != 0 ]] && die ${error_msg}
1198 java-pkg_ensure-dep "${build_only}" "${pkg}"
1200 # Record the package(Virtual) as a dependency and then set build_only
1201 # So that individual jars are not recorded.
1202 if [[ -n "${virtual}" ]]; then
1203 if [[ -z "${build_only}" ]]; then
1204 java-pkg_record-jar_ "${pkg}"
1206 java-pkg_record-jar_ --build-only "${pkg}"
1211 for jar in ${classpath//:/ }; do
1212 if [[ ! -f "${jar}" ]] ; then
1213 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
1216 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
1217 # Only record jars that aren't build-only
1218 if [[ -z "${record_jar}" ]]; then
1219 if [[ -z "${build_only}" ]]; then
1220 java-pkg_record-jar_ "${pkg}" "${jar}"
1222 java-pkg_record-jar_ --build-only "${pkg}" "${jar}"
1230 die "Could not find ${target_jar} in ${pkg}"
1234 # @FUNCTION: java-pkg_register-dependency
1235 # @USAGE: <package>[,<package2>...] [<jarfile>]
1237 # Registers runtime dependency on a package, list of packages, or a single jar
1238 # from a package, into package.env DEPEND line. Can only be called in
1239 # src_install phase.
1240 # Intended for binary packages where you don't need to symlink the jars or get
1241 # their classpath during build. As such, the dependencies only need to be
1242 # specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1246 # $1 - comma-separated list of packages, or a single package
1247 # $2 - if param $1 is a single package, optionally specify the jar
1251 # Record the dependency on whole xerces-2 and xalan,
1252 # java-pkg_register-dependency xerces-2,xalan
1254 # Record the dependency on ant.jar from ant-core
1255 # java-pkg_register-dependency ant-core ant.jar
1258 # Note: Passing both list of packages as the first parameter AND specifying the
1259 # jar as the second is not allowed and will cause the function to die. We assume
1260 # that there's more chance one passes such combination as a mistake, than that
1261 # there are more packages providing identically named jar without class
1263 java-pkg_register-dependency() {
1264 debug-print-function ${FUNCNAME} $*
1266 java-pkg_check-phase install
1268 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1273 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1275 if [[ "${EAPI}" == "1" ]]; then
1279 if [[ -z "${jar}" ]]; then
1280 for pkg in ${pkgs//,/ }; do
1281 java-pkg_ensure-dep runtime "${pkg}"
1282 java-pkg_record-jar_ "${pkg}"
1285 [[ ${pkgs} == *,* ]] && \
1286 die "${FUNCNAME} called with both package list and jar name"
1287 java-pkg_ensure-dep runtime "${pkgs}"
1288 java-pkg_record-jar_ "${pkgs}" "${jar}"
1294 # @FUNCTION: java-pkg_register-optional-dependency
1295 # @USAGE: <package>[,<package2>...] [<jarfile>]
1297 # Registers optional runtime dependency on a package, list of packages, or a
1298 # single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be
1299 # called in src_install phase.
1300 # Intended for packages that can use other packages when those are in classpath.
1301 # Will be put on classpath by launcher if they are installed. Typical case is
1302 # JDBC implementations for various databases. It's better than having USE flag
1303 # for each implementation triggering hard dependency.
1307 # $1 - comma-separated list of packages, or a single package
1308 # $2 - if param $1 is a single package, optionally specify the jar to depend on
1311 # Record the optional dependency on some jdbc providers
1312 # java-pkg_register-optional-dependency jdbc-jaybird,jtds-1.2,jdbc-mysql
1315 # Note: Passing both list of packages as the first parameter AND specifying the
1316 # jar as the second is not allowed and will cause the function to die. We assume
1317 # that there's more chance one passes such combination as a mistake, than that
1318 # there are more packages providing identically named jar without class
1320 java-pkg_register-optional-dependency() {
1321 debug-print-function ${FUNCNAME} $*
1323 java-pkg_check-phase install
1325 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1330 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1332 if [[ "${EAPI}" == "1" ]]; then
1336 if [[ -z "${jar}" ]]; then
1337 for pkg in ${pkgs//,/ }; do
1338 java-pkg_record-jar_ --optional "${pkg}"
1341 [[ ${pkgs} == *,* ]] && \
1342 die "${FUNCNAME} called with both package list and jar name"
1343 java-pkg_record-jar_ --optional "${pkgs}" "${jar}"
1349 # @FUNCTION: java-pkg_register-environment-variable
1350 # @USAGE: <name> <value>
1352 # Register an arbitrary environment variable into package.env. The gjl launcher
1353 # for this package or any package depending on this will export it into
1354 # environement before executing java command.
1355 # Must only be called in src_install phase.
1356 JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
1357 JAVA_PKG_EXTRA_ENV_VARS=""
1358 java-pkg_register-environment-variable() {
1359 debug-print-function ${FUNCNAME} $*
1361 java-pkg_check-phase install
1363 [[ ${#} != 2 ]] && die "${FUNCNAME} takes two arguments"
1365 echo "${1}=\"${2}\"" >> ${JAVA_PKG_EXTRA_ENV}
1366 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
1371 # @FUNCTION: java-pkg_get-bootclasspath
1374 # Returns classpath of a given bootclasspath-providing package version.
1376 # @param $1 - the version of bootclasspath (e.g. 1.5), 'auto' for bootclasspath
1377 # of the current JDK
1378 java-pkg_get-bootclasspath() {
1379 local version="${1}"
1382 case "${version}" in
1384 bcp="$(java-config -g BOOTCLASSPATH)"
1387 bcp="$(java-pkg_getjars --build-only gnu-classpath-0.98)"
1390 eerror "unknown parameter of java-pkg_get-bootclasspath"
1391 die "unknown parameter of java-pkg_get-bootclasspath"
1399 # This function reads stdin, and based on that input, figures out how to
1400 # populate jars from the filesystem.
1401 # Need to figure out a good way of making use of this, ie be able to use a
1402 # string that was built instead of stdin
1403 # NOTE: this isn't quite ready for primetime.
1404 #java-pkg_populate-jars() {
1408 # while [[ -n "${line}" ]]; do
1410 # [[ ${line%%#*} == "" ]] && continue
1412 # # get rid of any spaces
1413 # line="${line// /}"
1415 # # format: path=jarinfo
1416 # local path=${line%%=*}
1417 # local jarinfo=${line##*=}
1419 # # format: jar@package
1420 # local jar=${jarinfo%%@*}.jar
1421 # local package=${jarinfo##*@}
1422 # if [[ -n ${replace_only} ]]; then
1423 # [[ ! -f $path ]] && die "No jar exists at ${path}"
1425 # if [[ -n ${create_parent} ]]; then
1426 # local parent=$(dirname ${path})
1427 # mkdir -p "${parent}"
1429 # java-pkg_jar-from "${package}" "${jar}" "${path}"
1435 # @FUNCTION: java-pkg_find-normal-jars
1436 # @USAGE: [<path/to/directory>]
1438 # Find the files with suffix .jar file in the given directory (default: $WORKDIR)
1439 java-pkg_find-normal-jars() {
1441 [[ "${dir}" ]] || dir="${WORKDIR}"
1443 for jar in $(find "${dir}" -name "*.jar" -type f); do
1451 # @FUNCTION: java-pkg_ensure-no-bundled-jars
1453 # Try to locate bundled jar files in ${WORKDIR} and die if found.
1454 # This function should be called after WORKDIR has been populated with symlink
1455 # to system jar files or bundled jars removed.
1456 java-pkg_ensure-no-bundled-jars() {
1457 debug-print-function ${FUNCNAME} $*
1459 local bundled_jars=$(java-pkg_find-normal-jars)
1460 if [[ -n ${bundled_jars} ]]; then
1461 echo "Bundled jars found:"
1463 for jar in ${bundled_jars}; do
1464 echo $(pwd)${jar/./}
1466 die "Bundled jars found!"
1470 # @FUNCTION: java-pkg_ensure-vm-version-sufficient
1473 # Checks if we have a sufficient VM and dies if we don't.
1474 java-pkg_ensure-vm-version-sufficient() {
1475 debug-print-function ${FUNCNAME} $*
1477 if ! java-pkg_is-vm-version-sufficient; then
1478 debug-print "VM is not suffient"
1479 eerror "Current Java VM cannot build this package"
1480 einfo "Please use \"eselect java-vm set system\" to set the correct one"
1481 die "Active Java VM cannot build this package"
1485 # @FUNCTION: java-pkg_is-vm-version-sufficient
1488 # @RETURN: zero - VM is sufficient; non-zero - VM is not sufficient
1489 java-pkg_is-vm-version-sufficient() {
1490 debug-print-function ${FUNCNAME} $*
1492 depend-java-query --is-sufficient "${DEPEND}" > /dev/null
1496 # @FUNCTION: java-pkg_ensure-vm-version-eq
1499 # Die if the current VM is not equal to the argument passed.
1501 # @param $@ - Desired VM version to ensure
1502 java-pkg_ensure-vm-version-eq() {
1503 debug-print-function ${FUNCNAME} $*
1505 if ! java-pkg_is-vm-version-eq $@ ; then
1506 debug-print "VM is not suffient"
1507 eerror "This package requires a Java VM version = $@"
1508 einfo "Please use \"eselect java-vm set system\" to set the correct one"
1509 die "Active Java VM too old"
1513 # @FUNCTION: java-pkg_is-vm-version-eq
1516 # @RETURN: zero - VM versions are equal; non-zero - VM version are not equal
1517 java-pkg_is-vm-version-eq() {
1518 debug-print-function ${FUNCNAME} $*
1520 local needed_version="$@"
1522 [[ -z "${needed_version}" ]] && die "need an argument"
1524 local vm_version="$(java-pkg_get-vm-version)"
1526 vm_version="$(ver_cut 1-2 "${vm_version}")"
1527 needed_version="$(ver_cut 1-2 "${needed_version}")"
1529 if [[ -z "${vm_version}" ]]; then
1530 debug-print "Could not get JDK version from DEPEND"
1533 if [[ "${vm_version}" == "${needed_version}" ]]; then
1534 debug-print "Detected a JDK(${vm_version}) = ${needed_version}"
1537 debug-print "Detected a JDK(${vm_version}) != ${needed_version}"
1543 # @FUNCTION: java-pkg_ensure-vm-version-ge
1546 # Die if the current VM is not greater than the desired version
1548 # @param $@ - VM version to compare current to
1549 java-pkg_ensure-vm-version-ge() {
1550 debug-print-function ${FUNCNAME} $*
1552 if ! java-pkg_is-vm-version-ge "$@" ; then
1553 debug-print "vm is not suffient"
1554 eerror "This package requires a Java VM version >= $@"
1555 einfo "Please use \"eselect java-vm set system\" to set the correct one"
1556 die "Active Java VM too old"
1560 # @FUNCTION: java-pkg_is-vm-version-ge
1565 # $@ - VM version to compare current VM to
1567 # @RETURN: zero - current VM version is greater than checked version;
1568 # non-zero - current VM version is not greater than checked version
1569 java-pkg_is-vm-version-ge() {
1570 debug-print-function ${FUNCNAME} $*
1572 local needed_version=$@
1573 local vm_version=$(java-pkg_get-vm-version)
1574 if [[ -z "${vm_version}" ]]; then
1575 debug-print "Could not get JDK version from DEPEND"
1578 if ver_test "${vm_version}" -ge "${needed_version}"; then
1579 debug-print "Detected a JDK(${vm_version}) >= ${needed_version}"
1582 debug-print "Detected a JDK(${vm_version}) < ${needed_version}"
1588 java-pkg_set-current-vm() {
1589 export GENTOO_VM=${1}
1592 java-pkg_get-current-vm() {
1596 java-pkg_current-vm-matches() {
1597 has $(java-pkg_get-current-vm) ${@}
1601 # @FUNCTION: java-pkg_get-source
1603 # Determines what source version should be used, for passing to -source.
1604 # Unless you want to break things you probably shouldn't set _WANT_SOURCE
1606 # @RETURN: string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1607 java-pkg_get-source() {
1608 echo ${JAVA_PKG_WANT_SOURCE:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1611 # @FUNCTION: java-pkg_get-target
1613 # Determines what target version should be used, for passing to -target.
1614 # If you don't care about lower versions, you can set _WANT_TARGET to the
1615 # version of your JDK.
1617 # @RETURN: string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1618 java-pkg_get-target() {
1619 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1622 # @FUNCTION: java-pkg_get-javac
1624 # Returns the compiler executable
1625 java-pkg_get-javac() {
1626 debug-print-function ${FUNCNAME} $*
1628 java-pkg_init-compiler_
1629 local compiler="${GENTOO_COMPILER}"
1631 local compiler_executable
1632 if [[ "${compiler}" = "javac" ]]; then
1633 # nothing fancy needs to be done for javac
1634 compiler_executable="javac"
1636 # for everything else, try to determine from an env file
1638 local compiler_env="/usr/share/java-config-2/compiler/${compiler}"
1639 if [[ -f ${compiler_env} ]]; then
1640 local old_javac=${JAVAC}
1642 # try to get value of JAVAC
1643 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1644 export JAVAC=${old_javac}
1646 if [[ -z ${compiler_executable} ]]; then
1647 die "JAVAC is empty or undefined in ${compiler_env}"
1650 # check that it's executable
1651 if [[ ! -x ${compiler_executable} ]]; then
1652 die "${compiler_executable} doesn't exist, or isn't executable"
1655 die "Could not find environment file for ${compiler}"
1658 echo ${compiler_executable}
1661 # @FUNCTION: java-pkg_javac-args
1663 # If an ebuild uses javac directly, instead of using ejavac, it should call this
1664 # to know what -source/-target to use.
1666 # @RETURN: string - arguments to pass to javac, complete with -target and -source
1667 java-pkg_javac-args() {
1668 debug-print-function ${FUNCNAME} $*
1670 local want_source="$(java-pkg_get-source)"
1671 local want_target="$(java-pkg_get-target)"
1673 local source_str="-source ${want_source}"
1674 local target_str="-target ${want_target}"
1676 debug-print "want source: ${want_source}"
1677 debug-print "want target: ${want_target}"
1679 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1680 die "Could not find valid -source/-target values for javac"
1682 echo "${source_str} ${target_str}"
1686 # @FUNCTION: java-pkg_get-jni-cflags
1688 # Echos the CFLAGS for JNI compilations
1689 java-pkg_get-jni-cflags() {
1690 local flags="-I${JAVA_HOME}/include"
1692 local platform="linux"
1693 use elibc_FreeBSD && platform="freebsd"
1695 # TODO do a check that the directories are valid
1696 flags="${flags} -I${JAVA_HOME}/include/${platform}"
1701 java-pkg_ensure-gcj() {
1702 # was enforcing sys-devel/gcc[gcj]
1703 die "${FUNCNAME} was removed. Use use-deps available as of EAPI 2 instead. #261562"
1706 java-pkg_ensure-test() {
1707 # was enforcing USE=test if FEATURES=test
1708 die "${FUNCNAME} was removed. Package mangers handle this already. #278965"
1711 # @FUNCTION: java-pkg_register-ant-task
1712 # @USAGE: [--version x.y] [<name>]
1714 # Register this package as ant task, so that ant will load it when no specific
1715 # ANT_TASKS are specified. Note that even without this registering, all packages
1716 # specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1717 # packages, but can be also used by other ebuilds that used to symlink their
1718 # .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1723 # --version x.y Register only for ant version x.y (otherwise for any ant
1724 # version). Used by the ant-* packages to prevent loading of mismatched
1725 # ant-core ant tasks after core was updated, before the tasks are updated,
1726 # without a need for blockers.
1727 # $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1729 java-pkg_register-ant-task() {
1730 local TASKS_DIR="tasks"
1732 # check for --version x.y parameters
1733 while [[ -n "${1}" && -n "${2}" ]]; do
1736 if [[ "${var}" == "version" ]]; then
1737 TASKS_DIR="tasks-${val}"
1739 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1744 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1746 dodir /usr/share/ant/${TASKS_DIR}
1747 touch "${ED}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1750 # @FUNCTION: java-pkg_ant-tasks-depend
1753 # Translates the WANT_ANT_TASKS variable into valid dependencies.
1754 java-pkg_ant-tasks-depend() {
1755 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1757 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1759 for i in ${WANT_ANT_TASKS}
1761 if [[ ${i} = ant-* ]]; then
1762 DEP="${DEP}dev-java/${i} "
1763 elif [[ ${i} = */*:* ]]; then
1766 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1778 # @FUNCTION: ejunit_
1781 # Internal Junit wrapper function. Makes it easier to run the tests and checks for
1782 # dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner.
1785 # $1 - junit package (junit or junit-4)
1786 # $2 - -cp or -classpath
1787 # $3 - classpath; junit and recorded dependencies get appended
1788 # $@ - the rest of the parameters are passed to java
1791 debug-print-function ${FUNCNAME} $*
1794 if [[ -f ${JAVA_PKG_DEPEND_FILE} ]]; then
1795 for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
1796 pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
1803 local cp=$(java-pkg_getjars --with-dependencies ${junit}${pkgs})
1804 if [[ ${1} = -cp || ${1} = -classpath ]]; then
1811 local runner=junit.textui.TestRunner
1812 if [[ "${junit}" == "junit-4" ]] ; then
1813 runner=org.junit.runner.JUnitCore
1815 debug-print "Calling: java -cp \"${cp}\" -Djava.io.tmpdir=\"${T}\" -Djava.awt.headless=true ${runner} ${@}"
1816 java -cp "${cp}" -Djava.io.tmpdir="${T}/" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
1821 # Junit wrapper function. Makes it easier to run the tests and checks for
1822 # dev-java/junit in DEPEND. Launches the tests using org.junit.runner.JUnitCore.
1826 # $1 - -cp or -classpath
1827 # $2 - classpath; junit and recorded dependencies get appended
1828 # $@ - the rest of the parameters are passed to java
1831 # ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1832 # ejunit org.blinkenlights.jid3.test.AllTests
1833 # ejunit org.blinkenlights.jid3.test.FirstTest org.blinkenlights.jid3.test.SecondTest
1836 debug-print-function ${FUNCNAME} $*
1838 ejunit_ "junit" "${@}"
1841 # @FUNCTION: ejunit4
1843 # Junit4 wrapper function. Makes it easier to run the tests and checks for
1844 # dev-java/junit:4 in DEPEND. Launches the tests using junit.textui.TestRunner.
1848 # $1 - -cp or -classpath
1849 # $2 - classpath; junit and recorded dependencies get appended
1850 # $@ - the rest of the parameters are passed to java
1853 # ejunit4 -cp build/classes org.blinkenlights.jid3.test.AllTests
1854 # ejunit4 org.blinkenlights.jid3.test.AllTests
1855 # ejunit4 org.blinkenlights.jid3.test.FirstTest \
1856 # org.blinkenlights.jid3.test.SecondTest
1859 debug-print-function ${FUNCNAME} $*
1861 ejunit_ "junit-4" "${@}"
1864 # @FUNCTION: java-utils-2_src_prepare
1866 # src_prepare Searches for bundled jars
1867 # Don't call directly, but via java-pkg-2_src_prepare!
1868 java-utils-2_src_prepare() {
1871 java-pkg_func-exists java_prepare && java_prepare ;;
1873 java-pkg_func-exists java_prepare &&
1874 eqawarn "java_prepare is no longer called, define src_prepare instead."
1878 # Check for files in JAVA_RM_FILES array.
1879 if [[ ${JAVA_RM_FILES[@]} ]]; then
1880 debug-print "$FUNCNAME: removing unneeded files"
1881 java-pkg_rm_files "${JAVA_RM_FILES[@]}"
1884 if is-java-strict; then
1885 echo "Searching for bundled jars:"
1886 java-pkg_find-normal-jars || echo "None found."
1887 echo "Searching for bundled classes (no output if none found):"
1888 find "${WORKDIR}" -name "*.class"
1893 # @FUNCTION: java-utils-2_pkg_preinst
1895 # pkg_preinst Searches for missing and unneeded dependencies
1896 # Don't call directly, but via java-pkg-2_pkg_preinst!
1897 java-utils-2_pkg_preinst() {
1898 if is-java-strict; then
1899 if [[ ! -e "${JAVA_PKG_ENV}" ]] || has ant-tasks ${INHERITED}; then
1903 if has_version dev-java/java-dep-check; then
1904 local output=$(GENTOO_VM= java-dep-check --image "${D}" "${JAVA_PKG_ENV}")
1905 [[ ${output} ]] && ewarn "${output}"
1907 eerror "Install dev-java/java-dep-check for dependency checking"
1913 # @USAGE: <ant_build_target(s)>
1915 # Ant wrapper function. Will use the appropriate compiler, based on user-defined
1916 # compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1921 # EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1922 # gentoo.classpath property. Be sure to call java-ant_rewrite-classpath in src_unpack.
1923 # EANT_NEEDS_TOOLS - add tools.jar to the gentoo.classpath. Should only be used
1924 # for build-time purposes, the dependency is not recorded to
1926 # ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1929 debug-print-function ${FUNCNAME} $*
1931 if [[ ${EBUILD_PHASE} = compile ]]; then
1932 java-ant-2_src_configure
1935 if ! has java-ant-2 ${INHERITED}; then
1936 local msg="You should inherit java-ant-2 when using eant"
1937 java-pkg_announce-qa-violation "${msg}"
1940 local antflags="-Dnoget=true -Dmaven.mode.offline=true -Dbuild.sysclasspath=ignore"
1942 java-pkg_init-compiler_
1943 local compiler="${GENTOO_COMPILER}"
1945 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1946 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})"
1947 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1948 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1951 if [[ ${compiler} != "javac" ]]; then
1952 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1953 # Figure out any extra stuff to put on the classpath for compilers aside
1955 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1957 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})"
1958 if [[ -n ${build_compiler_deps} ]]; then
1959 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1963 for arg in "${@}"; do
1964 if [[ ${arg} = -lib ]]; then
1965 if is-java-strict; then
1966 eerror "You should not use the -lib argument to eant because it will fail"
1967 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1968 eerror "or ant properties to make dependencies available."
1969 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1970 eerror "split ant (>=dev-java/ant-core-1.7)."
1971 die "eant -lib is deprecated/forbidden"
1973 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1979 # parse WANT_ANT_TASKS for atoms
1980 local want_ant_tasks
1981 for i in ${WANT_ANT_TASKS}; do
1982 if [[ ${i} = */*:* ]]; then
1985 want_ant_tasks+="${i/:/-} "
1987 want_ant_tasks+="${i} "
1990 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1991 ANT_TASKS="${ANT_TASKS:-${want_ant_tasks% }}"
1993 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1994 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1996 # if ant-tasks is not set by ebuild or forced, use none
1997 ANT_TASKS="${ANT_TASKS:-none}"
1999 # at this point, ANT_TASKS should be "all", "none" or explicit list
2000 if [[ "${ANT_TASKS}" == "all" ]]; then
2001 einfo "Using all available ANT_TASKS"
2002 elif [[ "${ANT_TASKS}" == "none" ]]; then
2003 einfo "Disabling all optional ANT_TASKS"
2005 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
2010 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
2011 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
2013 local gcp="${EANT_GENTOO_CLASSPATH}"
2016 if [[ ${EBUILD_PHASE} = "test" ]]; then
2017 antflags="${antflags} -DJunit.present=true"
2018 getjarsarg="--with-dependencies"
2020 local re="\bant-junit4?([-:]\S+)?\b"
2021 [[ ${ANT_TASKS} =~ ${re} ]] && gcp+=" ${BASH_REMATCH[0]}"
2023 antflags="${antflags} -Dmaven.test.skip=true"
2028 for atom in ${gcp}; do
2029 cp+=":$(java-pkg_getjars ${getjarsarg} ${atom})"
2032 [[ ${EANT_NEEDS_TOOLS} ]] && cp+=":$(java-config --tools)"
2033 [[ ${EANT_GENTOO_CLASSPATH_EXTRA} ]] && cp+=":${EANT_GENTOO_CLASSPATH_EXTRA}"
2035 if [[ ${cp#:} ]]; then
2036 # It seems ant does not like single quotes around ${cp}
2037 # And ant 1.9.13+ also does not like double quotes around ${cp}
2038 # https://bz.apache.org/bugzilla/show_bug.cgi?id=58898
2039 antflags="${antflags} -Dgentoo.classpath=${cp#:}"
2042 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
2043 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
2044 ant ${antflags} "${@}" || die "eant failed"
2048 # @USAGE: <javac_arguments>
2050 # Javac wrapper function. Will use the appropriate compiler, based on
2051 # /etc/java-config/compilers.conf
2053 debug-print-function ${FUNCNAME} $*
2055 local compiler_executable
2056 compiler_executable=$(java-pkg_get-javac)
2059 javac_args="$(java-pkg_javac-args)"
2061 if [[ -n ${JAVA_PKG_DEBUG} ]]; then
2062 einfo "Verbose logging for \"${FUNCNAME}\" function"
2063 einfo "Compiler executable: ${compiler_executable}"
2064 einfo "Extra arguments: ${javac_args}"
2065 einfo "Complete command:"
2066 einfo "${compiler_executable} ${javac_args} ${@}"
2070 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
2073 # @FUNCTION: ejavadoc
2074 # @USAGE: <javadoc_arguments>
2076 # javadoc wrapper function. Will set some flags based on the VM version
2077 # due to strict javadoc rules in 1.8.
2079 debug-print-function ${FUNCNAME} $*
2081 local javadoc_args=""
2083 if java-pkg_is-vm-version-ge "1.8" ; then
2084 javadoc_args="-Xdoclint:none"
2087 if [[ -n ${JAVA_PKG_DEBUG} ]]; then
2088 einfo "Verbose logging for \"${FUNCNAME}\" function"
2089 einfo "Javadoc executable: javadoc"
2090 einfo "Extra arguments: ${javadoc_args}"
2091 einfo "Complete command:"
2092 einfo "javadoc ${javadoc_args} ${@}"
2095 ebegin "Generating JavaDoc"
2096 javadoc ${javadoc_args} "${@}" || die "ejavadoc failed"
2099 # @FUNCTION: java-pkg_filter-compiler
2100 # @USAGE: <compiler(s)_to_filter>
2102 # Used to prevent the use of some compilers. Should be used in src_compile.
2103 # Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
2104 java-pkg_filter-compiler() {
2105 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@"
2108 # @FUNCTION: java-pkg_force-compiler
2109 # @USAGE: <compiler(s)_to_force>
2111 # Used to force the use of particular compilers. Should be used in src_compile.
2112 # A common use of this would be to force ecj-3.1 to be used on amd64, to avoid
2113 # OutOfMemoryErrors that may come up.
2114 java-pkg_force-compiler() {
2115 JAVA_PKG_FORCE_COMPILER="$@"
2118 # @FUNCTION: use_doc
2121 # Helper function for getting ant to build javadocs. If the user has USE=doc,
2122 # then 'javadoc' or the argument are returned. Otherwise, there is no return.
2124 # The output of this should be passed to ant.
2127 # $@ - Option value to return. Defaults to 'javadoc'
2130 # build javadocs by calling 'javadoc' target
2133 # build javadocs by calling 'apidoc' target
2134 # eant $(use_doc apidoc)
2136 # @RETURN string - Name of the target to create javadocs
2138 use doc && echo ${@:-javadoc}
2142 # @FUNCTION: java-pkg_init
2145 # The purpose of this function, as the name might imply, is to initialize the
2146 # Java environment. It ensures that that there aren't any environment variables
2147 # that'll muss things up. It initializes some variables, which are used
2148 # internally. And most importantly, it'll switch the VM if necessary.
2150 # This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will
2151 # call it during each of the phases of the merge process.
2153 debug-print-function ${FUNCNAME} $*
2155 # Don't set up build environment if installing from binary. #206024 #258423
2156 [[ "${MERGE_TYPE}" == "binary" ]] && return
2157 # Also try Portage's nonstandard EMERGE_FROM for old EAPIs, if it doesn't
2158 # work nothing is lost.
2159 has ${EAPI:-0} 0 1 2 3 && [[ "${EMERGE_FROM}" == "binary" ]] && return
2164 java-config --help >/dev/null || {
2166 eerror "Can't run java-config --help"
2167 eerror "Have you upgraded python recently but haven't"
2168 eerror "run python-updater yet?"
2169 die "Can't run java-config --help"
2172 # People do all kinds of weird things.
2173 # https://forums.gentoo.org/viewtopic-p-3943166.html
2174 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
2175 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
2176 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
2177 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
2178 ewarn "sun-jdk vms and and as such break configure scripts that"
2179 ewarn "use it (for example app-office/openoffice) so we filter it out."
2180 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
2181 ewarn "make.conf for example) to silence this warning or"
2182 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
2185 if [[ -z ${accept} ]]; then
2186 # export _JAVA_OPTIONS= doesn't work because it will show up in java
2189 # phase hooks make this run many times without this
2190 I_WANT_GLOBAL_JAVA_OPTIONS="true"
2194 PATH=${JAVA_HOME}/bin:${PATH}
2196 # TODO we will probably want to set JAVAC and JAVACFLAGS
2199 java-pkg_check-jikes
2201 # Can't use unset here because Portage does not save the unset
2202 # see https://bugs.gentoo.org/show_bug.cgi?id=189417#c11
2204 # When users have crazy classpaths some packages can fail to compile.
2205 # and everything should work with empty CLASSPATH.
2206 # This also helps prevent unexpected dependencies on random things
2207 # from the CLASSPATH.
2210 # Unset external ANT_ stuff
2213 export ANT_RESPECT_JAVA_HOME=
2216 # @FUNCTION: java-pkg-init-compiler_
2219 # This function attempts to figure out what compiler should be used. It does
2220 # this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
2221 # COMPILERS variable defined there.
2222 # This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
2224 # It will go through the list of compilers, and verify that it supports the
2225 # target and source that are needed. If it is not suitable, then the next
2226 # compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
2229 # Once the which compiler to use has been figured out, it is set to
2232 # If you hadn't guessed, JAVA_PKG_FORCE_COMPILER is for testing only.
2234 # If the user doesn't defined anything in JAVA_PKG_COMPILERS_CONF, or no
2235 # suitable compiler was found there, then the default is to use javac provided
2236 # by the current VM.
2239 # @RETURN name of the compiler to use
2240 java-pkg_init-compiler_() {
2241 debug-print-function ${FUNCNAME} $*
2243 if [[ -n ${GENTOO_COMPILER} ]]; then
2244 debug-print "GENTOO_COMPILER already set"
2249 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
2250 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
2252 compilers=${JAVA_PKG_FORCE_COMPILER}
2255 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
2257 # Figure out if we should announce what compiler we're using
2259 for compiler in ${compilers}; do
2260 debug-print "Checking ${compiler}..."
2261 # javac should always be alright
2262 if [[ ${compiler} = "javac" ]]; then
2263 debug-print "Found javac... breaking"
2264 export GENTOO_COMPILER="javac"
2268 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
2269 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
2270 einfo "Filtering ${compiler}" >&2
2275 # for non-javac, we need to make sure it supports the right target and
2277 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
2278 if [[ -f ${compiler_env} ]]; then
2279 local desired_target="$(java-pkg_get-target)"
2280 local desired_source="$(java-pkg_get-source)"
2283 # Verify that the compiler supports target
2284 local supported_target=$(source ${compiler_env} 1>/dev/null 2>&1; echo ${SUPPORTED_TARGET})
2285 if ! has ${desired_target} ${supported_target}; then
2286 ewarn "${compiler} does not support -target ${desired_target}, skipping"
2290 # Verify that the compiler supports source
2291 local supported_source=$(source ${compiler_env} 1>/dev/null 2>&1; echo ${SUPPORTED_SOURCE})
2292 if ! has ${desired_source} ${supported_source}; then
2293 ewarn "${compiler} does not support -source ${desired_source}, skipping"
2297 # if you get here, then the compiler should be good to go
2298 export GENTOO_COMPILER="${compiler}"
2301 ewarn "Could not find configuration for ${compiler}, skipping"
2302 ewarn "Perhaps it is not installed?"
2307 # If it hasn't been defined already, default to javac
2308 if [[ -z ${GENTOO_COMPILER} ]]; then
2309 if [[ -n ${compilers} ]]; then
2310 einfo "No suitable compiler found: defaulting to JDK default for compilation" >&2
2312 # probably don't need to notify users about the default.
2313 :;#einfo "Defaulting to javac for compilation" >&2
2315 if java-config -g GENTOO_COMPILER 2> /dev/null; then
2316 export GENTOO_COMPILER=$(java-config -g GENTOO_COMPILER)
2318 export GENTOO_COMPILER=javac
2321 einfo "Using ${GENTOO_COMPILER} for compilation" >&2
2326 # @FUNCTION: init_paths_
2329 # Initializes some variables that will be used. These variables are mostly used
2330 # to determine where things will eventually get installed.
2331 java-pkg_init_paths_() {
2332 debug-print-function ${FUNCNAME} $*
2335 if [[ "${SLOT%/*}" == "0" ]] ; then
2336 JAVA_PKG_NAME="${PN}"
2338 JAVA_PKG_NAME="${PN}-${SLOT%/*}"
2341 JAVA_PKG_SHAREPATH="/usr/share/${JAVA_PKG_NAME}"
2342 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/"
2343 JAVA_PKG_ENV="${ED}${JAVA_PKG_SHAREPATH}/package.env"
2344 JAVA_PKG_VIRTUALS_PATH="/usr/share/java-config-2/virtuals"
2345 JAVA_PKG_VIRTUAL_PROVIDER="${ED}${JAVA_PKG_VIRTUALS_PATH}/${JAVA_PKG_NAME}"
2347 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib"
2348 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="/usr/$(get_libdir)/${JAVA_PKG_NAME}"
2349 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps"
2351 # TODO maybe only print once?
2352 debug-print "JAVA_PKG_SHAREPATH: ${JAVA_PKG_SHAREPATH}"
2353 debug-print "JAVA_PKG_ENV: ${JAVA_PKG_ENV}"
2354 debug-print "JAVA_PKG_JARDEST: ${JAVA_PKG_JARDEST}"
2355 debug-print "JAVA_PKG_LIBDEST: ${JAVA_PKG_LIBDEST}"
2356 debug-print "JAVA_PKG_WARDEST: ${JAVA_PKG_WARDEST}"
2359 # @FUNCTION: java-pkg_do_write_
2362 # Writes the package.env out to disk.
2364 # TODO change to do-write, to match everything else
2365 java-pkg_do_write_() {
2366 debug-print-function ${FUNCNAME} $*
2367 java-pkg_init_paths_
2368 # Create directory for package.env
2369 dodir "${JAVA_PKG_SHAREPATH}"
2371 # Create package.env
2373 echo "DESCRIPTION=\"${DESCRIPTION}\""
2374 echo "GENERATION=\"2\""
2375 echo "SLOT=\"${SLOT}\""
2376 echo "CATEGORY=\"${CATEGORY}\""
2377 echo "PVR=\"${PVR}\""
2379 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
2380 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
2381 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
2382 [[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
2383 && echo "DEPEND=\"$(sort -u "${JAVA_PKG_DEPEND_FILE}" | tr '\n' ':')\""
2384 [[ -f "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]] \
2385 && echo "OPTIONAL_DEPEND=\"$(sort -u "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" | tr '\n' ':')\""
2386 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
2387 [[ -f "${JAVA_PKG_BUILD_DEPEND_FILE}" ]] \
2388 && echo "BUILD_DEPEND=\"$(sort -u "${JAVA_PKG_BUILD_DEPEND_FILE}" | tr '\n' ':')\""
2389 ) > "${JAVA_PKG_ENV}"
2391 # register target/source
2392 local target="$(java-pkg_get-target)"
2393 local source="$(java-pkg_get-source)"
2394 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
2395 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
2397 # register javadoc info
2398 [[ -n ${JAVADOC_PATH} ]] && echo "JAVADOC_PATH=\"${JAVADOC_PATH}\"" \
2400 # register source archives
2401 [[ -n ${JAVA_SOURCES} ]] && echo "JAVA_SOURCES=\"${JAVA_SOURCES}\"" \
2404 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
2405 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
2407 # extra env variables
2408 if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
2409 cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}" || die
2410 # nested echo to remove leading/trailing spaces
2411 echo "ENV_VARS=\"$(echo ${JAVA_PKG_EXTRA_ENV_VARS})\"" \
2412 >> "${JAVA_PKG_ENV}" || die
2415 # Strip unnecessary leading and trailing colons
2416 # TODO try to cleanup if possible
2417 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
2420 # @FUNCTION: java-pkg_record-jar_
2423 # Record an (optional) dependency to the package.env
2426 # --optional - record dependency as optional
2427 # --build - record dependency as build_only
2428 # $1 - package to record
2429 # $2 - (optional) jar of package to record
2431 JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2432 JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
2433 JAVA_PKG_BUILD_DEPEND_FILE="${T}/java-pkg-build-depend"
2435 java-pkg_record-jar_() {
2436 debug-print-function ${FUNCNAME} $*
2438 local depend_file="${JAVA_PKG_DEPEND_FILE}"
2440 "--optional") depend_file="${JAVA_PKG_OPTIONAL_DEPEND_FILE}"; shift;;
2441 "--build-only") depend_file="${JAVA_PKG_BUILD_DEPEND_FILE}"; shift;;
2444 local pkg=${1} jar=${2} append
2445 if [[ -z "${jar}" ]]; then
2448 append="$(basename ${jar})@${pkg}"
2451 echo "${append}" >> "${depend_file}"
2454 # @FUNCTION: java-pkg_append_
2457 # Appends a value to a variable
2461 # $1 variable name to modify
2462 # $2 value to append
2465 # java-pkg_append_ CLASSPATH foo.jar
2467 java-pkg_append_() {
2468 debug-print-function ${FUNCNAME} $*
2470 local var="${1}" value="${2}"
2471 if [[ -z "${!var}" ]] ; then
2472 export ${var}="${value}"
2474 local oldIFS=${IFS} cur haveit
2476 for cur in ${!var}; do
2477 if [[ ${cur} == ${value} ]]; then
2482 [[ -z ${haveit} ]] && export ${var}="${!var}:${value}"
2487 # @FUNCTION: java-pkg_expand_dir_
2490 # Gets the full path of the file/directory's parent.
2493 # $1 - file/directory to find parent directory for
2495 # @RETURN: path to $1's parent directory
2496 java-pkg_expand_dir_() {
2497 pushd "$(dirname "${1}")" >/dev/null 2>&1 || die
2499 popd >/dev/null 2>&1 || die
2502 # @FUNCTION: java-pkg_func-exists
2505 # Does the indicated function exist?
2506 # @RETURN: 0 - function is declared, 1 - function is undeclared
2507 java-pkg_func-exists() {
2508 declare -F ${1} > /dev/null
2511 # @FUNCTION: java-pkg_setup-vm
2514 # Sets up the environment for a specific VM
2515 java-pkg_setup-vm() {
2516 debug-print-function ${FUNCNAME} $*
2518 local vendor="$(java-pkg_get-vm-vendor)"
2519 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
2520 addpredict "/dev/random"
2521 elif [[ "${vendor}" == "ibm" ]]; then
2522 addpredict "/proc/self/maps"
2523 addpredict "/proc/cpuinfo"
2524 addpredict "/proc/self/coredump_filter"
2525 elif [[ "${vendor}" == "oracle" ]]; then
2526 addpredict "/dev/random"
2527 addpredict "/proc/self/coredump_filter"
2528 elif [[ "${vendor}" == icedtea* ]] && java-pkg_is-vm-version-ge "1.7" ; then
2529 addpredict "/dev/random"
2530 addpredict "/proc/self/coredump_filter"
2531 elif [[ "${vendor}" == "jrockit" ]]; then
2532 addpredict "/proc/cpuinfo"
2536 # @FUNCTION: java-pkg_needs-vm
2539 # Does the current package depend on virtual/jdk or does it set
2540 # JAVA_PKG_WANT_BUILD_VM?
2542 # @RETURN: 0 - Package depends on virtual/jdk; 1 - Package does not depend on virtual/jdk
2543 java-pkg_needs-vm() {
2544 debug-print-function ${FUNCNAME} $*
2546 if [[ -n "$(echo ${JAVA_PKG_NV_DEPEND:-${DEPEND}} | sed -e '\:virtual/jdk:!d')" ]]; then
2550 [[ -n "${JAVA_PKG_WANT_BUILD_VM}" ]] && return 0
2555 # @FUNCTION: java-pkg_get-current-vm
2557 # @RETURN - The current VM being used
2558 java-pkg_get-current-vm() {
2562 # @FUNCTION: java-pkg_get-vm-vendor
2564 # @RETURN - The vendor of the current VM
2565 java-pkg_get-vm-vendor() {
2566 debug-print-function ${FUNCNAME} $*
2568 local vm="$(java-pkg_get-current-vm)"
2573 # @FUNCTION: java-pkg_get-vm-version
2575 # @RETURN - The version of the current VM
2576 java-pkg_get-vm-version() {
2577 debug-print-function ${FUNCNAME} $*
2579 java-config -g PROVIDES_VERSION
2582 # @FUNCTION: java-pkg_build-vm-from-handle
2585 # Selects a build vm from a list of vm handles. First checks for the system-vm
2586 # beeing usable, then steps through the listed handles till a suitable vm is
2589 # @RETURN - VM handle of an available JDK
2590 java-pkg_build-vm-from-handle() {
2591 debug-print-function ${FUNCNAME} "$*"
2594 vm=$(java-pkg_get-current-vm 2>/dev/null)
2595 if [[ $? -eq 0 ]]; then
2596 if has ${vm} ${JAVA_PKG_WANT_BUILD_VM}; then
2602 for vm in ${JAVA_PKG_WANT_BUILD_VM}; do
2603 if java-config-2 --select-vm=${vm} 2>/dev/null; then
2609 eerror "${FUNCNAME}: No vm found for handles: ${JAVA_PKG_WANT_BUILD_VM}"
2613 # @FUNCTION: java-pkg_switch-vm
2616 # Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
2617 # verify that the current VM is sufficient.
2618 # Setup the environment for the VM being used.
2619 java-pkg_switch-vm() {
2620 debug-print-function ${FUNCNAME} $*
2622 if java-pkg_needs-vm; then
2623 # Use the VM specified by JAVA_PKG_FORCE_VM
2624 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
2625 # If you're forcing the VM, I hope you know what your doing...
2626 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
2627 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
2628 # if we're allowed to switch the vm...
2629 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
2630 # if there is an explicit list of handles to choose from
2631 if [[ -n "${JAVA_PKG_WANT_BUILD_VM}" ]]; then
2632 debug-print "JAVA_PKG_WANT_BUILD_VM used: ${JAVA_PKG_WANT_BUILD_VM}"
2633 GENTOO_VM=$(java-pkg_build-vm-from-handle)
2634 if [[ $? != 0 ]]; then
2635 eerror "${FUNCNAME}: No VM found for handles: ${JAVA_PKG_WANT_BUILD_VM}"
2636 die "${FUNCNAME}: Failed to determine VM for building"
2638 # JAVA_PKG_WANT_SOURCE and JAVA_PKG_WANT_TARGET are required as
2639 # they can't be deduced from handles.
2640 if [[ -z "${JAVA_PKG_WANT_SOURCE}" ]]; then
2641 eerror "JAVA_PKG_WANT_BUILD_VM specified but not JAVA_PKG_WANT_SOURCE"
2642 die "Specify JAVA_PKG_WANT_SOURCE"
2644 if [[ -z "${JAVA_PKG_WANT_TARGET}" ]]; then
2645 eerror "JAVA_PKG_WANT_BUILD_VM specified but not JAVA_PKG_WANT_TARGET"
2646 die "Specify JAVA_PKG_WANT_TARGET"
2648 # otherwise determine a vm from dep string
2650 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
2651 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
2652 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
2653 eerror "Unable to determine VM for building from dependencies:"
2654 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
2655 die "Failed to determine VM for building."
2659 # otherwise just make sure the current VM is sufficient
2661 java-pkg_ensure-vm-version-sufficient
2663 debug-print "Using: $(java-config -f)"
2667 export JAVA=$(java-config --java)
2668 export JAVAC=$(java-config --javac)
2669 JAVACFLAGS="$(java-pkg_javac-args)"
2670 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
2673 export JAVA_HOME="$(java-config -g JAVA_HOME)"
2674 export JDK_HOME=${JAVA_HOME}
2676 #TODO If you know a better solution let us know.
2677 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
2679 local tann="${T}/announced-vm"
2680 # With the hooks we should only get here once from pkg_setup but better safe than sorry
2681 # if people have for example modified eclasses some where
2682 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
2683 einfo "Using: $(java-config -f)"
2684 [[ ! -f "${tann}" ]] && touch "${tann}"
2688 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!"
2692 # @FUNCTION: java-pkg_die
2695 # Enhanced die for Java packages, which displays some information that may be
2696 # useful for debugging bugs on bugzilla.
2697 #register_die_hook java-pkg_die
2698 if ! has java-pkg_die ${EBUILD_DEATH_HOOKS}; then
2699 EBUILD_DEATH_HOOKS="${EBUILD_DEATH_HOOKS} java-pkg_die"
2703 echo "!!! When you file a bug report, please include the following information:" >&2
2704 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2
2705 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2
2706 echo "and of course, the output of emerge --info =${P}" >&2
2711 # List jars in the source directory, ${S}
2712 java-pkg_jar-list() {
2713 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
2715 find "${S}" -type l -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2717 find "${S}" -type f -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2719 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2723 # @FUNCTION: java-pkg_verify-classes
2726 # Verify that the classes were compiled for the right source / target. Dies if
2729 # $1 (optional) - the file to check, otherwise checks whole ${D}
2731 java-pkg_verify-classes() {
2732 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
2734 local version_verify_1="${EPREFIX}/usr/$(get_libdir)/javatoolkit/bin/class-version-verify.py"
2735 local version_verify_2="${EPREFIX}/usr/libexec/javatoolkit/class-version-verify.py"
2737 if [[ -x "${version_verify_1}" ]]; then
2738 local version_verify=${version_verify_1}
2740 local version_verify=${version_verify_2}
2743 if [[ ! -x "${version_verify}" ]]; then
2744 ewarn "Unable to perform class version checks as"
2745 ewarn "class-version-verify.py is unavailable"
2746 ewarn "Please install dev-java/javatoolkit."
2750 local target=$(java-pkg_get-target)
2752 local log="${T}/class-version-verify.log"
2753 if [[ -n "${1}" ]]; then
2754 ${version_verify} -v -t ${target} "${1}" > "${log}"
2757 ebegin "Verifying java class versions (target: ${target})"
2758 ${version_verify} -v -t ${target} -r "${D}" > "${log}"
2762 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2763 if [[ ${result} != 0 ]]; then
2764 eerror "Incorrect bytecode version found"
2765 [[ -n "${1}" ]] && eerror "in file: ${1}"
2766 eerror "See ${log} for more details."
2767 die "Incorrect bytecode found"
2771 # @FUNCTION: java-pkg_ensure-dep
2774 # Check that a package being used in jarfrom, getjars and getjar is contained
2775 # within DEPEND or RDEPEND with the correct SLOT. See this mail for details:
2776 # https://archives.gentoo.org/gentoo-dev/message/dcb644f89520f4bbb61cc7bbe45fdf6e
2779 # $1 - empty - check both vars; "runtime" or "build" - check only
2780 # RDEPEND, resp. DEPEND
2781 # $2 - Package name and slot.
2783 java-pkg_ensure-dep() {
2784 debug-print-function ${FUNCNAME} $*
2786 local limit_to="${1}"
2787 local target_pkg="${2}"
2790 # Transform into a regular expression to look for a matching package
2791 # and SLOT. SLOTs don't have to be numeric so foo-bar could either
2792 # mean foo-bar:0 or foo:bar. So you want to get your head around the
2795 # * The target package first has any dots escaped, e.g. foo-1.2
2798 # * sed then looks at the component following the last - or :
2799 # character, or the whole string if there is no - or :
2800 # character. It uses this to build a new regexp with two
2801 # significant branches.
2803 # * The first checks for the whole target package string, optionally
2804 # followed by a version number, and then :0.
2806 # * The second checks for the first part of the target package
2807 # string, optionally followed by a version number, followed by the
2808 # aforementioned component, treating that as a SLOT.
2810 local stripped_pkg=/$(sed -r 's/[-:]?([^-:]+)$/(\0(-[^:]+)?:0|(-[^:]+)?:\1)/' <<< "${target_pkg//./\\.}")\\b
2812 debug-print "Matching against: ${stripped_pkg}"
2814 # Uncomment the lines below once we've dealt with more of these
2815 # otherwise we'll be tempted to turn JAVA_PKG_STRICT off while
2816 # getting hit with a wave of bug reports. :(
2818 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ $stripped_pkg ) ]]; then
2819 dev_error="The ebuild is attempting to use ${target_pkg}, which is not "
2820 dev_error+="declared with a SLOT in DEPEND."
2821 # if is-java-strict; then
2822 # die "${dev_error}"
2824 eqawarn "java-pkg_ensure-dep: ${dev_error}"
2825 # eerror "Because you have ${target_pkg} installed,"
2826 # eerror "the package will build without problems, but please"
2827 # eerror "report this to https://bugs.gentoo.org."
2829 elif [[ ${limit_to} != build && ! ( "${RDEPEND}${PDEPEND}" =~ ${stripped_pkg} ) ]]; then
2830 dev_error="The ebuild is attempting to use ${target_pkg}, which is not "
2831 dev_error+="declared with a SLOT in [RP]DEPEND and --build-only wasn't given."
2832 # if is-java-strict; then
2833 # die "${dev_error}"
2835 eqawarn "java-pkg_ensure-dep: ${dev_error}"
2836 # eerror "The package will build without problems, but may fail to run"
2837 # eerror "if you don't have ${target_pkg} installed,"
2838 # eerror "so please report this to https://bugs.gentoo.org."
2843 java-pkg_check-phase() {
2845 local funcname=${FUNCNAME[1]}
2846 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
2847 local msg="${funcname} used outside of src_${phase}"
2848 java-pkg_announce-qa-violation "${msg}"
2852 java-pkg_check-versioned-jar() {
2855 if [[ ${jar} =~ ${PV} ]]; then
2856 java-pkg_announce-qa-violation "installing versioned jar '${jar}'"
2860 java-pkg_check-jikes() {
2861 if has jikes ${IUSE}; then
2862 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
2866 java-pkg_announce-qa-violation() {
2868 if [[ ${1} == "--nodie" ]]; then
2872 echo "Java QA Notice: $@" >&2
2873 increment-qa-violations
2874 [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
2877 increment-qa-violations() {
2878 let "JAVA_PKG_QA_VIOLATIONS+=1"
2879 export JAVA_PKG_QA_VIOLATIONS
2883 [[ -n ${JAVA_PKG_STRICT} ]]
2887 # @FUNCTION: java-pkg_clean
2889 # Java package cleaner function. This will remove all *.class and *.jar
2890 # files, removing any bundled dependencies.
2892 if [[ -z "${JAVA_PKG_NO_CLEAN}" ]]; then
2893 find "${@}" '(' -name '*.class' -o -name '*.jar' ')' -type f -delete -print || die
2897 # @FUNCTION: java-pkg_gen-cp
2900 # Java package generate classpath will create a classpath based on
2901 # special variable CP_DEPEND in the ebuild.
2905 # $1 - classpath variable either EANT_GENTOO_CLASSPATH or JAVA_GENTOO_CLASSPATH
2908 debug-print-function ${FUNCNAME} "${@}"
2911 for atom in ${CP_DEPEND}; do
2912 if [[ ${atom} =~ /(([[:alnum:]+_-]+)-[0-9]+(\.[0-9]+)*[a-z]?(_[[:alnum:]]+)*(-r[0-9]*)?|[[:alnum:]+_-]+):([[:alnum:]+_.-]+) ]]; then
2913 atom=${BASH_REMATCH[2]:-${BASH_REMATCH[1]}}
2914 [[ ${BASH_REMATCH[6]} != 0 ]] && atom+=-${BASH_REMATCH[6]}
2915 local regex="(^|\s|,)${atom}($|\s|,)"
2916 [[ ${!1} =~ ${regex} ]] || declare -g ${1}+=${!1:+,}${atom}
2918 die "Invalid CP_DEPEND atom ${atom}, ensure a SLOT is included"