/[gentoo-x86]/eclass/java-utils-2.eclass
Gentoo

Diff of /eclass/java-utils-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.38 Revision 1.61
4# Copyright (c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org> 4# Copyright (c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
5# Copyright (c) 2004-2005, Gentoo Foundation 5# Copyright (c) 2004-2005, Gentoo Foundation
6# 6#
7# Licensed under the GNU General Public License, v2 7# Licensed under the GNU General Public License, v2
8# 8#
9# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.38 2006/12/31 19:30:54 betelgeuse Exp $ 9# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.61 2007/03/03 16:27:31 betelgeuse Exp $
10 10
11 11
12# ----------------------------------------------------------------------------- 12# -----------------------------------------------------------------------------
13# @eclass-begin 13# @eclass-begin
14# @eclass-shortdesc Java Utility eclass 14# @eclass-shortdesc Java Utility eclass
36# ----------------------------------------------------------------------------- 36# -----------------------------------------------------------------------------
37 37
38# Make sure we use java-config-2 38# Make sure we use java-config-2
39export WANT_JAVA_CONFIG="2" 39export WANT_JAVA_CONFIG="2"
40 40
41# TODO document 41# -----------------------------------------------------------------------------
42# @variable-external WANT_ANT_TASKS
43# @variable-default ""
44#
45# An $IFS separated list of ant tasks.
46# Ebuild can specify this variable before inheriting java-ant-2 eclass to
47# determine ANT_TASKS it needs. They will be automatically translated to
48# DEPEND variable and ANT_TASKS variable. JAVA_PKG_FORCE_ANT_TASKS can override
49# ANT_TASKS set by WANT_ANT_TASKS, but not the DEPEND due to caching.
50# Ebuilds that need to depend conditionally on certain tasks and specify them
51# differently for different eant calls can't use this simplified approach.
52# You also cannot specify version or anything else than ant-*.
53#
54# @example WANT_ANT_TASKS="ant-junit ant-trax"
55#
56# @seealso JAVA_PKG_FORCE_ANT_TASKS
57# -----------------------------------------------------------------------------
58#WANT_ANT_TASKS
59
60# @variable-internal JAVA_PKG_PORTAGE_DEP
61#
62# The version of portage we need to function properly. At this moment it's
63# portage with phase hooks support.
64# -----------------------------------------------------------------------------
42JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1" 65JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1"
43 66
44# ----------------------------------------------------------------------------- 67# -----------------------------------------------------------------------------
45# @variable-internal JAVA_PKG_E_DEPEND 68# @variable-internal JAVA_PKG_E_DEPEND
46# 69#
47# This is a convience variable to be used from the other java eclasses. This is 70# This is a convience variable to be used from the other java eclasses. This is
48# the version of java-config we want to use. We also need a recent version 71# the version of java-config we want to use. We also need a recent version
49# portage, that includes phase hooks. 72# portage, that includes phase hooks.
50# ----------------------------------------------------------------------------- 73# -----------------------------------------------------------------------------
51JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 ${JAVA_PKG_PORTAGE_DEP}" 74JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.31 ${JAVA_PKG_PORTAGE_DEP}"
52 75
53# ----------------------------------------------------------------------------- 76# -----------------------------------------------------------------------------
54# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 77# @variable-external JAVA_PKG_ALLOW_VM_CHANGE
55# @variable-default yes 78# @variable-default yes
56# 79#
128# JAVA_PKG_COMPILERS_CONF. 151# JAVA_PKG_COMPILERS_CONF.
129# 152#
130# @note This should only be used internally or for testing. 153# @note This should only be used internally or for testing.
131# @example Use jikes and javac, in that order 154# @example Use jikes and javac, in that order
132# JAVA_PKG_FORCE_COMPILER="jikes javac" 155# JAVA_PKG_FORCE_COMPILER="jikes javac"
156# -----------------------------------------------------------------------------
157
158# -----------------------------------------------------------------------------
159# @variable-external JAVA_PKG_FORCE_ANT_TASKS
160#
161# An $IFS separated list of ant tasks. Can be set in environment before calling
162# emerge/ebuild to override variables set in ebuild, mainly for testing before
163# putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in
164# eant() call, not the dependencies specified in WANT_ANT_TASKS.
165#
166# @example JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \
167# ebuild foo.ebuild compile
168#
169# @seealso WANT_ANT_TASKS
133# ----------------------------------------------------------------------------- 170# -----------------------------------------------------------------------------
134 171
135# TODO document me 172# TODO document me
136JAVA_PKG_QA_VIOLATIONS=0 173JAVA_PKG_QA_VIOLATIONS=0
137 174
174 # Create JARDEST if it doesn't exist 211 # Create JARDEST if it doesn't exist
175 dodir ${JAVA_PKG_JARDEST} 212 dodir ${JAVA_PKG_JARDEST}
176 213
177 local jar 214 local jar
178 # for each jar 215 # for each jar
179 for jar in "$@"; do 216 for jar in "${@}"; do
180 local jar_basename=$(basename "${jar}") 217 local jar_basename=$(basename "${jar}")
181 218
182 java-pkg_check-versioned-jar ${jar_basename} 219 java-pkg_check-versioned-jar ${jar_basename}
183 220
184 # check if it exists 221 # check if it exists
185 if [[ -e "${jar}" ]] ; then 222 if [[ -e "${jar}" ]] ; then
223 # Don't overwrite if jar has already been installed with the same
224 # name
225 local dest="${D}${JAVA_PKG_JARDEST}/${jar_basename}"
226 if [[ -e "${dest}" ]]; then
227 ewarn "Overwriting ${dest}"
228 fi
229
186 # install it into JARDEST if it's a non-symlink 230 # install it into JARDEST if it's a non-symlink
187 if [[ ! -L "${jar}" ]] ; then 231 if [[ ! -L "${jar}" ]] ; then
232 #but first check class version when in strict mode.
233 is-java-strict && java-pkg_verify-classes "${jar}"
234
188 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 235 INSDESTTREE="${JAVA_PKG_JARDEST}" \
189 doins "${jar}" || die "failed to install ${jar}" 236 doins "${jar}" || die "failed to install ${jar}"
190 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 237 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
191 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}" 238 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}"
192 # make a symlink to the original jar if it's symlink 239 # make a symlink to the original jar if it's symlink
212# Using env variables keeps this eclass working with java-config versions that 259# Using env variables keeps this eclass working with java-config versions that
213# do not handle use flags. 260# do not handle use flags.
214# ------------------------------------------------------------------------------ 261# ------------------------------------------------------------------------------
215 262
216depend-java-query() { 263depend-java-query() {
264 # Used to have a which call here but it caused endless loops for some people
265 # please tell us why if you you have any idea. Maybe bash 3.1?
217 USE="${USE}" $(which depend-java-query) "${@}" 266 USE="${USE}" /usr/bin/depend-java-query "${@}"
218} 267}
219 268
220# ------------------------------------------------------------------------------ 269# ------------------------------------------------------------------------------
221# @ebuild-function java-pkg_regjar 270# @ebuild-function java-pkg_regjar
222# 271#
254 [[ ${#} -lt 1 ]] && die "at least one argument needed" 303 [[ ${#} -lt 1 ]] && die "at least one argument needed"
255 304
256 java-pkg_init_paths_ 305 java-pkg_init_paths_
257 306
258 local jar jar_dir jar_file 307 local jar jar_dir jar_file
259 for jar in "$@"; do 308 for jar in "${@}"; do
260 # TODO use java-pkg_check-versioned-jar 309 # TODO use java-pkg_check-versioned-jar
261 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then 310 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
262 [[ -d "${jar}" || -d "${D}${jar}" ]] \ 311 [[ -d "${jar}" || -d "${D}${jar}" ]] \
263 && die "Called ${FUNCNAME} on a directory $*" 312 && die "Called ${FUNCNAME} on a directory $*"
313
314 #check that class version correct when in strict mode
315 is-java-strict && java-pkg_verify-classes "${jar}"
316
264 # nelchael: we should strip ${D} in this case too, here's why: 317 # nelchael: we should strip ${D} in this case too, here's why:
265 # imagine such call: 318 # imagine such call:
266 # java-pkg_regjar ${D}/opt/java/*.jar 319 # java-pkg_regjar ${D}/opt/java/*.jar
267 # such call will fall into this case (-e ${jar}) and will 320 # such call will fall into this case (-e ${jar}) and will
268 # record paths with ${D} in package.env 321 # record paths with ${D} in package.env
292 local original_jar="${1}" 345 local original_jar="${1}"
293 local new_jar="${2:-${PN}.jar}" 346 local new_jar="${2:-${PN}.jar}"
294 local new_jar_dest="${T}/${new_jar}" 347 local new_jar_dest="${T}/${new_jar}"
295 348
296 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 349 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
297 [[ ! -f ${original_jar} ]] && die "${original_jar} does not exist!" 350 [[ ! -f ${original_jar} ]] \
351 && die "${original_jar} does not exist or is not a file!"
298 352
299 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 353 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
300 cp "${original_jar}" "${new_jar_dest}" \ 354 cp "${original_jar}" "${new_jar_dest}" \
301 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 355 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
302 java-pkg_dojar "${new_jar_dest}" 356 java-pkg_dojar "${new_jar_dest}"
351 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 405 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
352 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 406 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
353 # otherwise make a symlink to the symlink's origin 407 # otherwise make a symlink to the symlink's origin
354 else 408 else
355 # TODO use dosym 409 # TODO use dosym
410 ln -s "$(readlink "${lib}")" \
356 ln -s "$(readlink "${lib}")" "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")" 411 "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")"
357 debug-print "${lib} is a symlink, linking accordanly" 412 debug-print "${lib} is a symlink, linking accordanly"
358 fi 413 fi
359 # otherwise die 414 # otherwise die
360 else 415 else
361 die "${lib} does not exist" 416 die "${lib} does not exist"
515 java-pkg_init_paths_ 570 java-pkg_init_paths_
516 571
517 local zip_name="${PN}-src.zip" 572 local zip_name="${PN}-src.zip"
518 local zip_path="${T}/${zip_name}" 573 local zip_path="${T}/${zip_name}"
519 local dir 574 local dir
520 for dir in ${@}; do 575 for dir in "${@}"; do
521 local dir_parent=$(dirname "${dir}") 576 local dir_parent=$(dirname "${dir}")
522 local dir_name=$(basename "${dir}") 577 local dir_name=$(basename "${dir}")
523 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 578 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
524 zip -q -r ${zip_path} ${dir_name} -i '*.java' 579 zip -q -r ${zip_path} ${dir_name} -i '*.java'
525 local result=$? 580 local result=$?
550# @param $1 - filename of launcher to create 605# @param $1 - filename of launcher to create
551# @param $2 - options, as follows: 606# @param $2 - options, as follows:
552# --main the.main.class.too.start 607# --main the.main.class.too.start
553# --jar /the/jar/too/launch.jar or just <name>.jar 608# --jar /the/jar/too/launch.jar or just <name>.jar
554# --java_args 'Extra arguments to pass to java' 609# --java_args 'Extra arguments to pass to java'
555# --pkg_args 'Extra arguments too pass to the package' 610# --pkg_args 'Extra arguments to pass to the package'
556# --pwd 611# --pwd Directory the launcher changes to before executing java
557# -into 612# -into Directory to install the launcher to, instead of /usr/bin
558# -pre 613# -pre Prepend contents of this file to the launcher
559# ------------------------------------------------------------------------------ 614# ------------------------------------------------------------------------------
560java-pkg_dolauncher() { 615java-pkg_dolauncher() {
561 debug-print-function ${FUNCNAME} $* 616 debug-print-function ${FUNCNAME} $*
562 617
563 java-pkg_check-phase install 618 java-pkg_check-phase install
604 fi 659 fi
605 fi 660 fi
606 661
607 # Write the actual script 662 # Write the actual script
608 echo "#!/bin/bash" > "${target}" 663 echo "#!/bin/bash" > "${target}"
609 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 664 if [[ -n "${pre}" ]]; then
665 if [[ -f "${pre}" ]]; then
666 cat "${pre}" >> "${target}"
667 else
668 die "-pre specified file '${pre}' does not exist"
669 fi
670 fi
610 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 671 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
611 cat "${var_tmp}" >> "${target}" 672 cat "${var_tmp}" >> "${target}"
612 rm -f "${var_tmp}" 673 rm -f "${var_tmp}"
613 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 674 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
614 675
706# Example: get a specific jar from xerces slot 2, and name it diffrently 767# Example: get a specific jar from xerces slot 2, and name it diffrently
707# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 768# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
708# Example: get junit.jar which is needed only for building 769# Example: get junit.jar which is needed only for building
709# java-pkg_jar-from --build-only junit junit.jar 770# java-pkg_jar-from --build-only junit junit.jar
710# 771#
711# @param $1 - (optional) "--build-only" makes the jar(s) not added into 772# @param $opt
712# package.env DEPEND line. 773# --build-only - makes the jar(s) not added into package.env DEPEND line.
774# (assumed automatically when called inside src_test)
775# --with-dependencies - get jars also from requested package's dependencies
776# transitively.
777# --into $dir - symlink jar(s) into $dir (must exist) instead of .
713# @param $1 - Package to get jars from. 778# @param $1 - Package to get jars from.
714# @param $2 - jar from package. If not specified, all jars will be used. 779# @param $2 - jar from package. If not specified, all jars will be used.
715# @param $3 - When a single jar is specified, destination filename of the 780# @param $3 - When a single jar is specified, destination filename of the
716# symlink. Defaults to the name of the jar. 781# symlink. Defaults to the name of the jar.
717# ------------------------------------------------------------------------------ 782# ------------------------------------------------------------------------------
718# TODO could probably be cleaned up a little 783# TODO could probably be cleaned up a little
719java-pkg_jar-from() { 784java-pkg_jar-from() {
720 debug-print-function ${FUNCNAME} $* 785 debug-print-function ${FUNCNAME} $*
721 786
722 local build_only="" 787 local build_only=""
788 local destdir="."
789 local deep=""
723 790
791 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true"
792
793 while [[ "${1}" == --* ]]; do
724 if [[ "${1}" = "--build-only" ]]; then 794 if [[ "${1}" = "--build-only" ]]; then
725 build_only="true" 795 build_only="true"
796 elif [[ "${1}" = "--with-dependencies" ]]; then
797 deep="--with-dependencies"
798 elif [[ "${1}" = "--into" ]]; then
799 destdir="${2}"
800 shift
801 else
802 die "java-pkg_jar-from called with unknown parameter: ${1}"
803 fi
726 shift 804 shift
727 fi 805 done
728 806
729 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 807 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
730 808
731 [[ -z ${target_pkg} ]] && die "Must specify a package" 809 [[ -z ${target_pkg} ]] && die "Must specify a package"
732 810
733 # default destjar to the target jar 811 # default destjar to the target jar
734 [[ -z "${destjar}" ]] && destjar="${target_jar}" 812 [[ -z "${destjar}" ]] && destjar="${target_jar}"
735 813
736 local error_msg="There was a problem getting the classpath for ${target_pkg}." 814 local error_msg="There was a problem getting the classpath for ${target_pkg}."
737 local classpath 815 local classpath
738 classpath="$(java-config --classpath=${target_pkg})" 816 classpath="$(java-config ${deep} --classpath=${target_pkg})"
739 [[ $? != 0 ]] && die ${error_msg} 817 [[ $? != 0 ]] && die ${error_msg}
818
819 pushd ${destdir} > /dev/null \
820 || die "failed to change directory to ${destdir}"
821
822 # When we have commas this functions is called to bring jars from multiple
823 # packages. This affects recording of dependencencies because that syntax uses :
824 # if we don't change them to : gjl and java-config -d -p break
825 if [[ ${target_pkg} = *,* ]]; then
826 build_only="true"
827 java-pkg_record-jar_ ${target_pkg//,/:}
828 fi
740 829
741 local jar 830 local jar
742 for jar in ${classpath//:/ }; do 831 for jar in ${classpath//:/ }; do
743 local jar_name=$(basename "${jar}") 832 local jar_name=$(basename "${jar}")
744 if [[ ! -f "${jar}" ]] ; then 833 if [[ ! -f "${jar}" ]] ; then
755 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 844 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
756 [[ -f "${destjar}" ]] && rm "${destjar}" 845 [[ -f "${destjar}" ]] && rm "${destjar}"
757 ln -snf "${jar}" "${destjar}" \ 846 ln -snf "${jar}" "${destjar}" \
758 || die "Failed to make symlink from ${jar} to ${destjar}" 847 || die "Failed to make symlink from ${jar} to ${destjar}"
759 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}" 848 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
849 popd > /dev/null
760 return 0 850 return 0
761 fi 851 fi
762 done 852 done
853 popd > /dev/null
763 # if no target was specified, we're ok 854 # if no target was specified, we're ok
764 if [[ -z "${target_jar}" ]] ; then 855 if [[ -z "${target_jar}" ]] ; then
765 return 0 856 return 0
766 # otherwise, die bitterly 857 # otherwise, die bitterly
767 else 858 else
791# Example: Get the classpath for xerces-2 and xalan, 882# Example: Get the classpath for xerces-2 and xalan,
792# java-pkg_getjars xerces-2,xalan 883# java-pkg_getjars xerces-2,xalan
793# Example Return: 884# Example Return:
794# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 885# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
795# 886#
796# @param $1 - (optional) "--build-only" makes the jar(s) not added into 887# @param $opt
797# package.env DEPEND line. 888# --build-only - makes the jar(s) not added into package.env DEPEND line.
889# (assumed automatically when called inside src_test)
890# --with-dependencies - get jars also from requested package's dependencies
891# transitively.
798# @param $2 - list of packages to get jars from 892# @param $1 - list of packages to get jars from
799# (passed to java-config --classpath) 893# (passed to java-config --classpath)
800# ------------------------------------------------------------------------------ 894# ------------------------------------------------------------------------------
801java-pkg_getjars() { 895java-pkg_getjars() {
802 debug-print-function ${FUNCNAME} $* 896 debug-print-function ${FUNCNAME} $*
803 897
898 local build_only=""
899 local deep=""
900
901 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true"
902
903 while [[ "${1}" == --* ]]; do
804 if [[ "${1}" = "--build-only" ]]; then 904 if [[ "${1}" = "--build-only" ]]; then
805 local build_only="true" 905 build_only="true"
906 elif [[ "${1}" = "--with-dependencies" ]]; then
907 deep="--with-dependencies"
908 else
909 die "java-pkg_jar-from called with unknown parameter: ${1}"
910 fi
806 shift 911 shift
807 fi 912 done
808 913
809 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --build-only" 914 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
810 915
811 local classpath pkgs="${1}" 916 local classpath pkgs="${1}"
812 jars="$(java-config --classpath=${pkgs})" 917 jars="$(java-config ${deep} --classpath=${pkgs})"
813 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed" 918 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed"
814 debug-print "${pkgs}:${jars}" 919 debug-print "${pkgs}:${jars}"
815 920
816 if [[ -z "${classpath}" ]]; then 921 if [[ -z "${classpath}" ]]; then
817 classpath="${jars}" 922 classpath="${jars}"
844# @example 949# @example
845# java-pkg_getjar xerces-2 xml-apis.jar 950# java-pkg_getjar xerces-2 xml-apis.jar
846# @example-return 951# @example-return
847# /usr/share/xerces-2/lib/xml-apis.jar 952# /usr/share/xerces-2/lib/xml-apis.jar
848# 953#
849# @param $1 - (optional) "--build-only" makes the jar not added into 954# @param $opt
850# package.env DEPEND line. 955# --build-only - makes the jar not added into package.env DEPEND line.
851# @param $1 - package to use 956# @param $1 - package to use
852# @param $2 - jar to get 957# @param $2 - jar to get
853# ------------------------------------------------------------------------------ 958# ------------------------------------------------------------------------------
854java-pkg_getjar() { 959java-pkg_getjar() {
855 debug-print-function ${FUNCNAME} $* 960 debug-print-function ${FUNCNAME} $*
856 961
857 local build_only="" 962 local build_only=""
858 963
964 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true"
965
966 while [[ "${1}" == --* ]]; do
859 if [[ "${1}" = "--build-only" ]]; then 967 if [[ "${1}" = "--build-only" ]]; then
860 build_only="true" 968 build_only="true"
969 else
970 die "java-pkg_jar-from called with unknown parameter: ${1}"
971 fi
861 shift 972 shift
862 fi 973 done
974
975 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
863 976
864 local pkg="${1}" target_jar="${2}" jar 977 local pkg="${1}" target_jar="${2}" jar
865 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 978 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
866 [[ -z ${target_jar} ]] && die "Must specify jar to get" 979 [[ -z ${target_jar} ]] && die "Must specify jar to get"
867 980
1009# 1122#
1010# export DEPEND="${DEPEND} ${depstr}" 1123# export DEPEND="${DEPEND} ${depstr}"
1011# export RDEPEND="${RDEPEND} ${depstr}" 1124# export RDEPEND="${RDEPEND} ${depstr}"
1012#} 1125#}
1013 1126
1127# ------------------------------------------------------------------------------
1128# @ebuild-function java-pkg_find-normal-jars
1129#
1130# Find the files with suffix .jar file in the given directory or $WORKDIR
1131#
1132# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1133# ------------------------------------------------------------------------------
1134java-pkg_find-normal-jars() {
1135 local dir=$1
1136 [[ "${dir}" ]] || dir="${WORKDIR}"
1137 local found
1138 for jar in $(find "${dir}" -name "*.jar" -type f); do
1139 echo "${jar}"
1140 found="true"
1141 done
1142 [[ "${found}" ]]
1143 return $?
1144}
1145
1146# ------------------------------------------------------------------------------
1147# @ebuild-function java-pkg_ensure-no-bundled-jars
1148#
1149# Try to locate bundled jar files in ${WORKDIR} and die if found.
1014# This should be used after S has been populated with symlinks to jars 1150# This function should be called after WORKDIR has been populated with symlink
1015# TODO document 1151# to system jar files or bundled jars removed.
1152# ------------------------------------------------------------------------------
1016java-pkg_ensure-no-bundled-jars() { 1153java-pkg_ensure-no-bundled-jars() {
1017 debug-print-function ${FUNCNAME} $* 1154 debug-print-function ${FUNCNAME} $*
1018 pushd ${WORKDIR} >/dev/null 2>/dev/null
1019 1155
1020 local bundled_jars=$(find . -name "*.jar" -type f) 1156 local bundled_jars=$(java-pkg_find-normal-jars)
1021 if [[ -n ${bundled_jars} ]]; then 1157 if [[ -n ${bundled_jars} ]]; then
1022 echo "Bundled jars found:" 1158 echo "Bundled jars found:"
1023 local jar 1159 local jar
1024 for jar in ${bundled_jars}; do 1160 for jar in ${bundled_jars}; do
1025 echo $(pwd)${jar/./} 1161 echo $(pwd)${jar/./}
1026 done 1162 done
1027 die "Bundled jars found!" 1163 die "Bundled jars found!"
1028
1029 fi 1164 fi
1030 popd >/dev/null 2>/dev/null
1031} 1165}
1032 1166
1033# ------------------------------------------------------------------------------ 1167# ------------------------------------------------------------------------------
1034# @internal-function java-pkg_ensure-vm-version-sufficient 1168# @internal-function java-pkg_ensure-vm-version-sufficient
1035# 1169#
1297 die "Need USE=test enabled" 1431 die "Need USE=test enabled"
1298 fi 1432 fi
1299} 1433}
1300 1434
1301# ------------------------------------------------------------------------------ 1435# ------------------------------------------------------------------------------
1436# @ebuild-function java-pkg_register-ant-task
1437#
1438# Register this package as ant task, so that ant will load it when no specific
1439# ANT_TASKS are specified. Note that even without this registering, all packages
1440# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1441# packages, but can be also used by other ebuilds that used to symlink their
1442# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1443# compatibility.
1444#
1445# @param --version x.y Register only for ant version x.y (otherwise for any ant
1446# version). Used by the ant-* packages to prevent loading of mismatched
1447# ant-core ant tasks after core was updated, before the tasks are updated,
1448# without a need for blockers.
1449# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1450# ------------------------------------------------------------------------------
1451java-pkg_register-ant-task() {
1452 local TASKS_DIR="tasks"
1453
1454 # check for --version x.y parameters
1455 while [[ -n "${1}" && -n "${2}" ]]; do
1456 local var="${1#--}"
1457 local val="${2}"
1458 if [[ "${var}" == "version" ]]; then
1459 TASKS_DIR="tasks-${val}"
1460 else
1461 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1462 fi
1463 shift 2
1464 done
1465
1466 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1467
1468 dodir /usr/share/ant/${TASKS_DIR}
1469 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1470}
1471
1472# ------------------------------------------------------------------------------
1473# @internal-function java-pkg_ant-tasks-from-deps
1474#
1475# Function to determine ANT_TASKS from DEPEND variable for backwards
1476# compatibility with ebuilds that don't set ANT_TASKS before calling eant() or
1477# WANT_ANT_TASKS before inheriting java-pkg-2. If the DEPEND string contains
1478# "dev-java/ant" or "dev-java/ant-tasks", then it returns "all", otherwise
1479# "none". It's not smart enough to cope with USE flag depends but that shouldn't
1480# be a problem, the worst it can do is activace all tasks when not needed.
1481# Note that this is called only with JAVA_PKG_STRICT=1, to find ebuilds with
1482# insufficient dependencies, otherwise all available tasks are used for
1483# backwards compatilbility.
1484#
1485# @return "all" or "none"
1486# ------------------------------------------------------------------------------
1487java-pkg_ant-tasks-from-deps() {
1488 local found_ant found_ant_tasks
1489
1490 for dep in ${DEPEND}
1491 do
1492 local ant="$(awk '/(dev-java\/ant)/ { if (match($1, "(dev-java/ant)((-[0-9])+|$)", m)) print m[1] }' <<< ${dep})"
1493 [[ "${ant}" == "dev-java/ant" ]] && found_ant=true
1494 [[ "${dep}" == *"ant-tasks"* ]] && found_ant_tasks=true
1495 done
1496
1497 if [[ -n "${found_ant}" || -n "${found_ant_tasks}" ]]; then
1498 java-pkg_announce-qa-violation "The ebuild DEPENDS on deprecated ant or ant-tasks"
1499 echo "all"
1500 else
1501 # ebuild doesn't set ANT_TASKS and doesn't depend on ant-tasks or ant
1502 # so we deactivate all tasks that may be installed
1503 echo "none"
1504 fi
1505}
1506
1507# ------------------------------------------------------------------------------
1508# @internal-function java-pkg_ant-tasks-depend
1509#
1510# Translates the WANT_ANT_TASKS variable into valid dependencies.
1511# ------------------------------------------------------------------------------
1512java-pkg_ant-tasks-depend() {
1513 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1514
1515 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1516 local DEP=""
1517 for i in ${WANT_ANT_TASKS}
1518 do
1519 if [[ ${i} != ant-* ]]; then
1520 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1521 return 1
1522 fi
1523 DEP="${DEP}dev-java/${i} "
1524 done
1525 echo ${DEP}
1526 return 0
1527 else
1528 return 0
1529 fi
1530}
1531
1532# ------------------------------------------------------------------------------
1302# @section-end helper 1533# @section-end helper
1303# ------------------------------------------------------------------------------ 1534# ------------------------------------------------------------------------------
1304 1535
1305# ------------------------------------------------------------------------------ 1536# ------------------------------------------------------------------------------
1306# @section-begin build 1537# @section-begin build
1312 1543
1313# ------------------------------------------------------------------------------ 1544# ------------------------------------------------------------------------------
1314# @ebuild-function eant 1545# @ebuild-function eant
1315# 1546#
1316# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1547# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1317# compiler. 1548# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1318# 1549# variables:
1550# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1551# gentoo.classpath property. Be sure to call
1552# java-ant_rewrite-classpath in src_unpack.
1553# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1319# ------------------------------------------------------------------------------ 1554# ------------------------------------------------------------------------------
1320eant() { 1555eant() {
1321 debug-print-function ${FUNCNAME} $* 1556 debug-print-function ${FUNCNAME} $*
1322 1557
1323 # FIXME get this working 1558 # FIXME get this working
1324# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then 1559# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then
1325# java-pkg_announce-qa-violation \ 1560# java-pkg_announce-qa-violation \
1326# "Using eant, but not depending on dev-java/ant or dev-java/ant-core" 1561# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1327# fi 1562# fi
1328 1563
1329 local antflags="-Dnoget=true" 1564 if ! hasq java-ant-2 ${INHERITED} && is-java-strict; then
1565 local msg="You should inherit java-ant-2 when using eant"
1566 java-pkg_announce-qa-violation ${msg}
1567 die ${msg}
1568 fi
1569
1570 local antflags="-Dnoget=true -Dmaven.mode.offline=true"
1571
1330 java-pkg_init-compiler_ 1572 java-pkg_init-compiler_
1331 local compiler="${GENTOO_COMPILER}" 1573 local compiler="${GENTOO_COMPILER}"
1332 1574
1333 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1575 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1334 1576
1352 if is-java-strict; then 1594 if is-java-strict; then
1353 einfo "Disabling system classpath for ant" 1595 einfo "Disabling system classpath for ant"
1354 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1596 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1355 fi 1597 fi
1356 1598
1357 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1599 for arg in "${@}"; do
1358 antflags="${antflags} -debug" 1600 if [[ ${arg} = -lib ]]; then
1601 if is-java-strict; then
1602 eerror "You should not use the -lib argument to eant because it will fail"
1603 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1604 eerror "or ant properties to make dependencies available."
1605 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1606 eerror "split ant (>=dev-java/ant-core-1.7)."
1607 die "eant -lib is deprecated/forbidden"
1608 else
1609 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1610 echo "more info."
1611 fi
1612 fi
1613 done
1614
1615 if has_version ">=dev-java/ant-core-1.7.0"; then
1616 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1617 ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}"
1618
1619 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1620 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1621
1622 if is-java-strict; then
1623 # if ant-tasks were not set by ebuild or forced, try to determine them from depends
1624 if [[ -z "${ANT_TASKS}" ]]; then
1625 ANT_TASKS="$(java-pkg_ant-tasks-from-deps)"
1626 fi
1627 else
1628 # if ant-tasks is not set by ebuild or forced, activate all of them
1629 ANT_TASKS="${ANT_TASKS:-all}"
1630 fi
1631
1632 # at this point, ANT_TASKS should be "all", "none" or explicit list
1633 if [[ "${ANT_TASKS}" == "all" ]]; then
1634 einfo "Using all available ANT_TASKS"
1635 elif [[ "${ANT_TASKS}" == "none" ]]; then
1636 einfo "Disabling all optional ANT_TASKS"
1637 else
1638 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1639 fi
1640
1641 export ANT_TASKS
1642 fi
1643
1644 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1645 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1646
1647 local gcp="${EANT_GENTOO_CLASSPATH}"
1648
1649 if [[ ${EBUILD_PHASE} = "test" ]]; then
1650 antflags="${antflags} -DJunit.present=true"
1651 [[ ${gcp} && ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1652 fi
1653
1654 local cp
1655
1656 for atom in ${gcp}; do
1657 cp="${cp}:$(java-pkg_getjars ${atom})"
1658 done
1659
1660 if [[ ${cp} ]]; then
1661 # It seems ant does not like single quotes around ${cp}
1662 antflags="${antflags} -Dgentoo.classpath=\"${cp#:}\""
1359 fi 1663 fi
1360 1664
1361 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1665 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1666 debug-print "Calling ant: ${antflags} ${@}"
1362 ant ${antflags} "${@}" || die "eant failed" 1667 ant ${antflags} "${@}" || die "eant failed"
1363 1668
1364} 1669}
1365 1670
1366# ------------------------------------------------------------------------------ 1671# ------------------------------------------------------------------------------
1479 # When users have crazy classpaths some packages can fail to compile. 1784 # When users have crazy classpaths some packages can fail to compile.
1480 # and everything should work with empty CLASSPATH. 1785 # and everything should work with empty CLASSPATH.
1481 # This also helps prevent unexpected dependencies on random things 1786 # This also helps prevent unexpected dependencies on random things
1482 # from the CLASSPATH. 1787 # from the CLASSPATH.
1483 unset CLASSPATH 1788 unset CLASSPATH
1789
1790 # Unset external ANT_ stuff
1791 unset ANT_TASKS
1792 unset ANT_OPTS
1484} 1793}
1485 1794
1486# ------------------------------------------------------------------------------ 1795# ------------------------------------------------------------------------------
1487# @function-internal java-pkg-init-compiler_ 1796# @function-internal java-pkg-init-compiler_
1488# 1797#
1926 einfo "Classes" 2235 einfo "Classes"
1927 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR}," 2236 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1928 fi 2237 fi
1929} 2238}
1930 2239
1931# TODO document 2240# ------------------------------------------------------------------------------
2241# @internal-function java-pkg_verify-classes
2242#
1932# Verify that the classes were compiled for the right source / target 2243# Verify that the classes were compiled for the right source / target. Dies if
2244# not.
2245# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2246# ------------------------------------------------------------------------------
1933java-pkg_verify-classes() { 2247java-pkg_verify-classes() {
1934 ebegin "Verifying java class versions"
1935 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 2248 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1936 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 2249 local target=$(java-pkg_get-target)
2250 local result
2251 local log="${T}/class-version-verify.log"
2252 if [[ -n "${1}" ]]; then
2253 class-version-verify.py -v -t ${target} "${1}" > "${log}"
1937 result=$? 2254 result=$?
1938 eend ${result}
1939 if [[ ${result} == 0 ]]; then
1940 einfo "All good"
1941 else 2255 else
1942 ewarn "Possible problem" 2256 ebegin "Verifying java class versions (target: ${target})"
1943 die "Bad class files found" 2257 class-version-verify.py -v -t ${target} -r "${D}" > "${log}"
2258 result=$?
2259 eend ${result}
2260 fi
2261 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2262 if [[ ${result} != 0 ]]; then
2263 eerror "Incorrect bytecode version found"
2264 [[ -n "${1}" ]] && eerror "in file: ${1}"
2265 eerror "See ${log} for more details."
2266 die "Incorrect bytecode found"
1944 fi 2267 fi
1945} 2268}
1946 2269
1947# ------------------------------------------------------------------------------ 2270# ------------------------------------------------------------------------------
1948# @section-end internal 2271# @section-end internal

Legend:
Removed from v.1.38  
changed lines
  Added in v.1.61

  ViewVC Help
Powered by ViewVC 1.1.20