/[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.67
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.67 2007/03/22 03:11:19 nichoj 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# -----------------------------------------------------------------------------
61# @variable-internal JAVA_PKG_PORTAGE_DEP
62#
63# The version of portage we need to function properly. At this moment it's
64# portage with phase hooks support.
65# -----------------------------------------------------------------------------
42JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1" 66JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1"
43 67
44# ----------------------------------------------------------------------------- 68# -----------------------------------------------------------------------------
45# @variable-internal JAVA_PKG_E_DEPEND 69# @variable-internal JAVA_PKG_E_DEPEND
46# 70#
47# This is a convience variable to be used from the other java eclasses. This is 71# 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 72# the version of java-config we want to use. We also need a recent version
49# portage, that includes phase hooks. 73# portage, that includes phase hooks.
50# ----------------------------------------------------------------------------- 74# -----------------------------------------------------------------------------
51JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 ${JAVA_PKG_PORTAGE_DEP}" 75JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.31 ${JAVA_PKG_PORTAGE_DEP}"
52 76
53# ----------------------------------------------------------------------------- 77# -----------------------------------------------------------------------------
54# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 78# @variable-external JAVA_PKG_ALLOW_VM_CHANGE
55# @variable-default yes 79# @variable-default yes
56# 80#
130# @note This should only be used internally or for testing. 154# @note This should only be used internally or for testing.
131# @example Use jikes and javac, in that order 155# @example Use jikes and javac, in that order
132# JAVA_PKG_FORCE_COMPILER="jikes javac" 156# JAVA_PKG_FORCE_COMPILER="jikes javac"
133# ----------------------------------------------------------------------------- 157# -----------------------------------------------------------------------------
134 158
159# -----------------------------------------------------------------------------
160# @variable-external JAVA_PKG_FORCE_ANT_TASKS
161#
162# An $IFS separated list of ant tasks. Can be set in environment before calling
163# emerge/ebuild to override variables set in ebuild, mainly for testing before
164# putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in
165# eant() call, not the dependencies specified in WANT_ANT_TASKS.
166#
167# @example JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \
168# ebuild foo.ebuild compile
169#
170# @seealso WANT_ANT_TASKS
171# -----------------------------------------------------------------------------
172
135# TODO document me 173# TODO document me
136JAVA_PKG_QA_VIOLATIONS=0 174JAVA_PKG_QA_VIOLATIONS=0
137 175
138# ----------------------------------------------------------------------------- 176# -----------------------------------------------------------------------------
139# @section-end variables 177# @section-end variables
146# 184#
147# These are used to install Java-related things, such as jars, Javadocs, JNI 185# These are used to install Java-related things, such as jars, Javadocs, JNI
148# libraries, etc. 186# libraries, etc.
149# ----------------------------------------------------------------------------- 187# -----------------------------------------------------------------------------
150 188
189# -----------------------------------------------------------------------------
190# @ebuild-function java-pkg_doexamples
191#
192# Installs given arguments to /usr/share/doc/${PF}/examples
193# If you give it only one parameter and it is a directory it will install
194# everything in that directory to the examples directory.
195#
196# @example
197# java-pkg_doexamples demo
198# java-pkg_doexamples demo/* examples/*
199#
200# @param $* - list of files to install
201# ------------------------------------------------------------------------------
202java-pkg_doexamples() {
203 debug-print-function ${FUNCNAME} $*
204
205 [[ ${#} -lt 1 ]] && die "At least one argument needed"
206
207 java-pkg_check-phase install
208
209 local dest=/usr/share/doc/${PF}/examples
210 if [[ ${#} = 1 && -d ${1} ]]; then
211 INSDESTTREE="${dest}" doins -r ${1}/* || die "Installing examples failed"
212 else
213 INSDESTTREE="${dest}" doins -r "${@}" || die "Installing examples failed"
214 fi
215}
151 216
152# ----------------------------------------------------------------------------- 217# -----------------------------------------------------------------------------
153# @ebuild-function java-pkg_dojar 218# @ebuild-function java-pkg_dojar
154# 219#
155# Installs any number of jars. 220# Installs any number of jars.
174 # Create JARDEST if it doesn't exist 239 # Create JARDEST if it doesn't exist
175 dodir ${JAVA_PKG_JARDEST} 240 dodir ${JAVA_PKG_JARDEST}
176 241
177 local jar 242 local jar
178 # for each jar 243 # for each jar
179 for jar in "$@"; do 244 for jar in "${@}"; do
180 local jar_basename=$(basename "${jar}") 245 local jar_basename=$(basename "${jar}")
181 246
182 java-pkg_check-versioned-jar ${jar_basename} 247 java-pkg_check-versioned-jar ${jar_basename}
183 248
184 # check if it exists 249 # check if it exists
185 if [[ -e "${jar}" ]] ; then 250 if [[ -e "${jar}" ]] ; then
251 # Don't overwrite if jar has already been installed with the same
252 # name
253 local dest="${D}${JAVA_PKG_JARDEST}/${jar_basename}"
254 if [[ -e "${dest}" ]]; then
255 ewarn "Overwriting ${dest}"
256 fi
257
186 # install it into JARDEST if it's a non-symlink 258 # install it into JARDEST if it's a non-symlink
187 if [[ ! -L "${jar}" ]] ; then 259 if [[ ! -L "${jar}" ]] ; then
260 #but first check class version when in strict mode.
261 is-java-strict && java-pkg_verify-classes "${jar}"
262
188 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 263 INSDESTTREE="${JAVA_PKG_JARDEST}" \
189 doins "${jar}" || die "failed to install ${jar}" 264 doins "${jar}" || die "failed to install ${jar}"
190 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 265 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
191 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}" 266 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}"
192 # make a symlink to the original jar if it's symlink 267 # make a symlink to the original jar if it's symlink
212# Using env variables keeps this eclass working with java-config versions that 287# Using env variables keeps this eclass working with java-config versions that
213# do not handle use flags. 288# do not handle use flags.
214# ------------------------------------------------------------------------------ 289# ------------------------------------------------------------------------------
215 290
216depend-java-query() { 291depend-java-query() {
292 # Used to have a which call here but it caused endless loops for some people
293 # that had some weird bashrc voodoo for which.
217 USE="${USE}" $(which depend-java-query) "${@}" 294 USE="${USE}" /usr/bin/depend-java-query "${@}"
218} 295}
219 296
220# ------------------------------------------------------------------------------ 297# ------------------------------------------------------------------------------
221# @ebuild-function java-pkg_regjar 298# @ebuild-function java-pkg_regjar
222# 299#
254 [[ ${#} -lt 1 ]] && die "at least one argument needed" 331 [[ ${#} -lt 1 ]] && die "at least one argument needed"
255 332
256 java-pkg_init_paths_ 333 java-pkg_init_paths_
257 334
258 local jar jar_dir jar_file 335 local jar jar_dir jar_file
259 for jar in "$@"; do 336 for jar in "${@}"; do
260 # TODO use java-pkg_check-versioned-jar 337 # TODO use java-pkg_check-versioned-jar
261 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then 338 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
262 [[ -d "${jar}" || -d "${D}${jar}" ]] \ 339 [[ -d "${jar}" || -d "${D}${jar}" ]] \
263 && die "Called ${FUNCNAME} on a directory $*" 340 && die "Called ${FUNCNAME} on a directory $*"
341
342 #check that class version correct when in strict mode
343 is-java-strict && java-pkg_verify-classes "${jar}"
344
264 # nelchael: we should strip ${D} in this case too, here's why: 345 # nelchael: we should strip ${D} in this case too, here's why:
265 # imagine such call: 346 # imagine such call:
266 # java-pkg_regjar ${D}/opt/java/*.jar 347 # java-pkg_regjar ${D}/opt/java/*.jar
267 # such call will fall into this case (-e ${jar}) and will 348 # such call will fall into this case (-e ${jar}) and will
268 # record paths with ${D} in package.env 349 # record paths with ${D} in package.env
292 local original_jar="${1}" 373 local original_jar="${1}"
293 local new_jar="${2:-${PN}.jar}" 374 local new_jar="${2:-${PN}.jar}"
294 local new_jar_dest="${T}/${new_jar}" 375 local new_jar_dest="${T}/${new_jar}"
295 376
296 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 377 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
297 [[ ! -f ${original_jar} ]] && die "${original_jar} does not exist!" 378 [[ ! -f ${original_jar} ]] \
379 && die "${original_jar} does not exist or is not a file!"
298 380
299 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 381 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
300 cp "${original_jar}" "${new_jar_dest}" \ 382 cp "${original_jar}" "${new_jar_dest}" \
301 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 383 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
302 java-pkg_dojar "${new_jar_dest}" 384 java-pkg_dojar "${new_jar_dest}"
351 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 433 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
352 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 434 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
353 # otherwise make a symlink to the symlink's origin 435 # otherwise make a symlink to the symlink's origin
354 else 436 else
355 # TODO use dosym 437 # TODO use dosym
438 ln -s "$(readlink "${lib}")" \
356 ln -s "$(readlink "${lib}")" "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")" 439 "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")"
357 debug-print "${lib} is a symlink, linking accordanly" 440 debug-print "${lib} is a symlink, linking accordanly"
358 fi 441 fi
359 # otherwise die 442 # otherwise die
360 else 443 else
361 die "${lib} does not exist" 444 die "${lib} does not exist"
502# FIXME apparently this fails if you give it an empty directories 585# FIXME apparently this fails if you give it an empty directories
503java-pkg_dosrc() { 586java-pkg_dosrc() {
504 debug-print-function ${FUNCNAME} $* 587 debug-print-function ${FUNCNAME} $*
505 588
506 [ ${#} -lt 1 ] && die "At least one argument needed" 589 [ ${#} -lt 1 ] && die "At least one argument needed"
507 if ! hasq source ${IUSE}; then
508 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
509 fi
510 590
511 java-pkg_check-phase install 591 java-pkg_check-phase install
512 592
513 [[ ${#} -lt 1 ]] && die "At least one argument needed" 593 [[ ${#} -lt 1 ]] && die "At least one argument needed"
594
595 if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
596 local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
597 if is-java-strict; then
598 eerror "${msg}"
599 die "${msg}"
600 else
601 echo "${msg}"
602 echo "Please report this to http://bugs.gentoo.org."
603 fi
604 fi
514 605
515 java-pkg_init_paths_ 606 java-pkg_init_paths_
516 607
517 local zip_name="${PN}-src.zip" 608 local zip_name="${PN}-src.zip"
518 local zip_path="${T}/${zip_name}" 609 local zip_path="${T}/${zip_name}"
519 local dir 610 local dir
520 for dir in ${@}; do 611 for dir in "${@}"; do
521 local dir_parent=$(dirname "${dir}") 612 local dir_parent=$(dirname "${dir}")
522 local dir_name=$(basename "${dir}") 613 local dir_name=$(basename "${dir}")
523 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 614 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
524 zip -q -r ${zip_path} ${dir_name} -i '*.java' 615 zip -q -r ${zip_path} ${dir_name} -i '*.java'
525 local result=$? 616 local result=$?
550# @param $1 - filename of launcher to create 641# @param $1 - filename of launcher to create
551# @param $2 - options, as follows: 642# @param $2 - options, as follows:
552# --main the.main.class.too.start 643# --main the.main.class.too.start
553# --jar /the/jar/too/launch.jar or just <name>.jar 644# --jar /the/jar/too/launch.jar or just <name>.jar
554# --java_args 'Extra arguments to pass to java' 645# --java_args 'Extra arguments to pass to java'
555# --pkg_args 'Extra arguments too pass to the package' 646# --pkg_args 'Extra arguments to pass to the package'
556# --pwd 647# --pwd Directory the launcher changes to before executing java
557# -into 648# -into Directory to install the launcher to, instead of /usr/bin
558# -pre 649# -pre Prepend contents of this file to the launcher
559# ------------------------------------------------------------------------------ 650# ------------------------------------------------------------------------------
560java-pkg_dolauncher() { 651java-pkg_dolauncher() {
561 debug-print-function ${FUNCNAME} $* 652 debug-print-function ${FUNCNAME} $*
562 653
563 java-pkg_check-phase install 654 java-pkg_check-phase install
604 fi 695 fi
605 fi 696 fi
606 697
607 # Write the actual script 698 # Write the actual script
608 echo "#!/bin/bash" > "${target}" 699 echo "#!/bin/bash" > "${target}"
609 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 700 if [[ -n "${pre}" ]]; then
701 if [[ -f "${pre}" ]]; then
702 cat "${pre}" >> "${target}"
703 else
704 die "-pre specified file '${pre}' does not exist"
705 fi
706 fi
610 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 707 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
611 cat "${var_tmp}" >> "${target}" 708 cat "${var_tmp}" >> "${target}"
612 rm -f "${var_tmp}" 709 rm -f "${var_tmp}"
613 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 710 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
614 711
706# Example: get a specific jar from xerces slot 2, and name it diffrently 803# 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 804# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
708# Example: get junit.jar which is needed only for building 805# Example: get junit.jar which is needed only for building
709# java-pkg_jar-from --build-only junit junit.jar 806# java-pkg_jar-from --build-only junit junit.jar
710# 807#
711# @param $1 - (optional) "--build-only" makes the jar(s) not added into 808# @param $opt
712# package.env DEPEND line. 809# --build-only - makes the jar(s) not added into package.env DEPEND line.
810# (assumed automatically when called inside src_test)
811# --with-dependencies - get jars also from requested package's dependencies
812# transitively.
813# --into $dir - symlink jar(s) into $dir (must exist) instead of .
713# @param $1 - Package to get jars from. 814# @param $1 - Package to get jars from.
714# @param $2 - jar from package. If not specified, all jars will be used. 815# @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 816# @param $3 - When a single jar is specified, destination filename of the
716# symlink. Defaults to the name of the jar. 817# symlink. Defaults to the name of the jar.
717# ------------------------------------------------------------------------------ 818# ------------------------------------------------------------------------------
718# TODO could probably be cleaned up a little 819# TODO could probably be cleaned up a little
719java-pkg_jar-from() { 820java-pkg_jar-from() {
720 debug-print-function ${FUNCNAME} $* 821 debug-print-function ${FUNCNAME} $*
721 822
722 local build_only="" 823 local build_only=""
824 local destdir="."
825 local deep=""
723 826
827 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true"
828
829 while [[ "${1}" == --* ]]; do
724 if [[ "${1}" = "--build-only" ]]; then 830 if [[ "${1}" = "--build-only" ]]; then
725 build_only="true" 831 build_only="true"
832 elif [[ "${1}" = "--with-dependencies" ]]; then
833 deep="--with-dependencies"
834 elif [[ "${1}" = "--into" ]]; then
835 destdir="${2}"
836 shift
837 else
838 die "java-pkg_jar-from called with unknown parameter: ${1}"
839 fi
726 shift 840 shift
727 fi 841 done
728 842
729 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 843 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
730 844
731 [[ -z ${target_pkg} ]] && die "Must specify a package" 845 [[ -z ${target_pkg} ]] && die "Must specify a package"
732 846
733 # default destjar to the target jar 847 # default destjar to the target jar
734 [[ -z "${destjar}" ]] && destjar="${target_jar}" 848 [[ -z "${destjar}" ]] && destjar="${target_jar}"
735 849
736 local error_msg="There was a problem getting the classpath for ${target_pkg}." 850 local error_msg="There was a problem getting the classpath for ${target_pkg}."
737 local classpath 851 local classpath
738 classpath="$(java-config --classpath=${target_pkg})" 852 classpath="$(java-config ${deep} --classpath=${target_pkg})"
739 [[ $? != 0 ]] && die ${error_msg} 853 [[ $? != 0 ]] && die ${error_msg}
854
855 pushd ${destdir} > /dev/null \
856 || die "failed to change directory to ${destdir}"
857
858 # When we have commas this functions is called to bring jars from multiple
859 # packages. This affects recording of dependencencies because that syntax uses :
860 # if we don't change them to : gjl and java-config -d -p break
861 if [[ ${target_pkg} = *,* ]]; then
862 build_only="true"
863 java-pkg_record-jar_ ${target_pkg//,/:}
864 fi
740 865
741 local jar 866 local jar
742 for jar in ${classpath//:/ }; do 867 for jar in ${classpath//:/ }; do
743 local jar_name=$(basename "${jar}") 868 local jar_name=$(basename "${jar}")
744 if [[ ! -f "${jar}" ]] ; then 869 if [[ ! -f "${jar}" ]] ; then
755 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 880 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
756 [[ -f "${destjar}" ]] && rm "${destjar}" 881 [[ -f "${destjar}" ]] && rm "${destjar}"
757 ln -snf "${jar}" "${destjar}" \ 882 ln -snf "${jar}" "${destjar}" \
758 || die "Failed to make symlink from ${jar} to ${destjar}" 883 || die "Failed to make symlink from ${jar} to ${destjar}"
759 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}" 884 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
885 popd > /dev/null
760 return 0 886 return 0
761 fi 887 fi
762 done 888 done
889 popd > /dev/null
763 # if no target was specified, we're ok 890 # if no target was specified, we're ok
764 if [[ -z "${target_jar}" ]] ; then 891 if [[ -z "${target_jar}" ]] ; then
765 return 0 892 return 0
766 # otherwise, die bitterly 893 # otherwise, die bitterly
767 else 894 else
791# Example: Get the classpath for xerces-2 and xalan, 918# Example: Get the classpath for xerces-2 and xalan,
792# java-pkg_getjars xerces-2,xalan 919# java-pkg_getjars xerces-2,xalan
793# Example Return: 920# Example Return:
794# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 921# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
795# 922#
796# @param $1 - (optional) "--build-only" makes the jar(s) not added into 923# @param $opt
797# package.env DEPEND line. 924# --build-only - makes the jar(s) not added into package.env DEPEND line.
925# (assumed automatically when called inside src_test)
926# --with-dependencies - get jars also from requested package's dependencies
927# transitively.
798# @param $2 - list of packages to get jars from 928# @param $1 - list of packages to get jars from
799# (passed to java-config --classpath) 929# (passed to java-config --classpath)
800# ------------------------------------------------------------------------------ 930# ------------------------------------------------------------------------------
801java-pkg_getjars() { 931java-pkg_getjars() {
802 debug-print-function ${FUNCNAME} $* 932 debug-print-function ${FUNCNAME} $*
803 933
934 local build_only=""
935 local deep=""
936
937 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true"
938
939 while [[ "${1}" == --* ]]; do
804 if [[ "${1}" = "--build-only" ]]; then 940 if [[ "${1}" = "--build-only" ]]; then
805 local build_only="true" 941 build_only="true"
942 elif [[ "${1}" = "--with-dependencies" ]]; then
943 deep="--with-dependencies"
944 else
945 die "java-pkg_jar-from called with unknown parameter: ${1}"
946 fi
806 shift 947 shift
807 fi 948 done
808 949
809 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --build-only" 950 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
810 951
811 local classpath pkgs="${1}" 952 local classpath pkgs="${1}"
812 jars="$(java-config --classpath=${pkgs})" 953 jars="$(java-config ${deep} --classpath=${pkgs})"
813 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed" 954 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed"
814 debug-print "${pkgs}:${jars}" 955 debug-print "${pkgs}:${jars}"
815 956
816 if [[ -z "${classpath}" ]]; then 957 if [[ -z "${classpath}" ]]; then
817 classpath="${jars}" 958 classpath="${jars}"
844# @example 985# @example
845# java-pkg_getjar xerces-2 xml-apis.jar 986# java-pkg_getjar xerces-2 xml-apis.jar
846# @example-return 987# @example-return
847# /usr/share/xerces-2/lib/xml-apis.jar 988# /usr/share/xerces-2/lib/xml-apis.jar
848# 989#
849# @param $1 - (optional) "--build-only" makes the jar not added into 990# @param $opt
850# package.env DEPEND line. 991# --build-only - makes the jar not added into package.env DEPEND line.
851# @param $1 - package to use 992# @param $1 - package to use
852# @param $2 - jar to get 993# @param $2 - jar to get
853# ------------------------------------------------------------------------------ 994# ------------------------------------------------------------------------------
854java-pkg_getjar() { 995java-pkg_getjar() {
855 debug-print-function ${FUNCNAME} $* 996 debug-print-function ${FUNCNAME} $*
856 997
857 local build_only="" 998 local build_only=""
858 999
1000 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true"
1001
1002 while [[ "${1}" == --* ]]; do
859 if [[ "${1}" = "--build-only" ]]; then 1003 if [[ "${1}" = "--build-only" ]]; then
860 build_only="true" 1004 build_only="true"
1005 else
1006 die "java-pkg_jar-from called with unknown parameter: ${1}"
1007 fi
861 shift 1008 shift
862 fi 1009 done
1010
1011 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
863 1012
864 local pkg="${1}" target_jar="${2}" jar 1013 local pkg="${1}" target_jar="${2}" jar
865 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 1014 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
866 [[ -z ${target_jar} ]] && die "Must specify jar to get" 1015 [[ -z ${target_jar} ]] && die "Must specify jar to get"
867 1016
1009# 1158#
1010# export DEPEND="${DEPEND} ${depstr}" 1159# export DEPEND="${DEPEND} ${depstr}"
1011# export RDEPEND="${RDEPEND} ${depstr}" 1160# export RDEPEND="${RDEPEND} ${depstr}"
1012#} 1161#}
1013 1162
1163# ------------------------------------------------------------------------------
1164# @ebuild-function java-pkg_find-normal-jars
1165#
1166# Find the files with suffix .jar file in the given directory or $WORKDIR
1167#
1168# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1169# ------------------------------------------------------------------------------
1170java-pkg_find-normal-jars() {
1171 local dir=$1
1172 [[ "${dir}" ]] || dir="${WORKDIR}"
1173 local found
1174 for jar in $(find "${dir}" -name "*.jar" -type f); do
1175 echo "${jar}"
1176 found="true"
1177 done
1178 [[ "${found}" ]]
1179 return $?
1180}
1181
1182# ------------------------------------------------------------------------------
1183# @ebuild-function java-pkg_ensure-no-bundled-jars
1184#
1185# 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 1186# This function should be called after WORKDIR has been populated with symlink
1015# TODO document 1187# to system jar files or bundled jars removed.
1188# ------------------------------------------------------------------------------
1016java-pkg_ensure-no-bundled-jars() { 1189java-pkg_ensure-no-bundled-jars() {
1017 debug-print-function ${FUNCNAME} $* 1190 debug-print-function ${FUNCNAME} $*
1018 pushd ${WORKDIR} >/dev/null 2>/dev/null
1019 1191
1020 local bundled_jars=$(find . -name "*.jar" -type f) 1192 local bundled_jars=$(java-pkg_find-normal-jars)
1021 if [[ -n ${bundled_jars} ]]; then 1193 if [[ -n ${bundled_jars} ]]; then
1022 echo "Bundled jars found:" 1194 echo "Bundled jars found:"
1023 local jar 1195 local jar
1024 for jar in ${bundled_jars}; do 1196 for jar in ${bundled_jars}; do
1025 echo $(pwd)${jar/./} 1197 echo $(pwd)${jar/./}
1026 done 1198 done
1027 die "Bundled jars found!" 1199 die "Bundled jars found!"
1028
1029 fi 1200 fi
1030 popd >/dev/null 2>/dev/null
1031} 1201}
1032 1202
1033# ------------------------------------------------------------------------------ 1203# ------------------------------------------------------------------------------
1034# @internal-function java-pkg_ensure-vm-version-sufficient 1204# @internal-function java-pkg_ensure-vm-version-sufficient
1035# 1205#
1297 die "Need USE=test enabled" 1467 die "Need USE=test enabled"
1298 fi 1468 fi
1299} 1469}
1300 1470
1301# ------------------------------------------------------------------------------ 1471# ------------------------------------------------------------------------------
1472# @ebuild-function java-pkg_register-ant-task
1473#
1474# Register this package as ant task, so that ant will load it when no specific
1475# ANT_TASKS are specified. Note that even without this registering, all packages
1476# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1477# packages, but can be also used by other ebuilds that used to symlink their
1478# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1479# compatibility.
1480#
1481# @param --version x.y Register only for ant version x.y (otherwise for any ant
1482# version). Used by the ant-* packages to prevent loading of mismatched
1483# ant-core ant tasks after core was updated, before the tasks are updated,
1484# without a need for blockers.
1485# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1486# ------------------------------------------------------------------------------
1487java-pkg_register-ant-task() {
1488 local TASKS_DIR="tasks"
1489
1490 # check for --version x.y parameters
1491 while [[ -n "${1}" && -n "${2}" ]]; do
1492 local var="${1#--}"
1493 local val="${2}"
1494 if [[ "${var}" == "version" ]]; then
1495 TASKS_DIR="tasks-${val}"
1496 else
1497 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1498 fi
1499 shift 2
1500 done
1501
1502 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1503
1504 dodir /usr/share/ant/${TASKS_DIR}
1505 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1506}
1507
1508# ------------------------------------------------------------------------------
1509# @internal-function java-pkg_ant-tasks-from-deps
1510#
1511# Function to determine ANT_TASKS from DEPEND variable for backwards
1512# compatibility with ebuilds that don't set ANT_TASKS before calling eant() or
1513# WANT_ANT_TASKS before inheriting java-pkg-2. If the DEPEND string contains
1514# "dev-java/ant" or "dev-java/ant-tasks", then it returns "all", otherwise
1515# "none". It's not smart enough to cope with USE flag depends but that shouldn't
1516# be a problem, the worst it can do is activace all tasks when not needed.
1517# Note that this is called only with JAVA_PKG_STRICT=1, to find ebuilds with
1518# insufficient dependencies, otherwise all available tasks are used for
1519# backwards compatilbility.
1520#
1521# @return "all" or "none"
1522# ------------------------------------------------------------------------------
1523java-pkg_ant-tasks-from-deps() {
1524 local found_ant found_ant_tasks
1525
1526 for dep in ${DEPEND}
1527 do
1528 local ant="$(awk '/(dev-java\/ant)/ { if (match($1, "(dev-java/ant)((-[0-9])+|$)", m)) print m[1] }' <<< ${dep})"
1529 [[ "${ant}" == "dev-java/ant" ]] && found_ant=true
1530 [[ "${dep}" == *"ant-tasks"* ]] && found_ant_tasks=true
1531 done
1532
1533 if [[ -n "${found_ant}" || -n "${found_ant_tasks}" ]]; then
1534 java-pkg_announce-qa-violation "The ebuild DEPENDS on deprecated ant or ant-tasks"
1535 echo "all"
1536 else
1537 # ebuild doesn't set ANT_TASKS and doesn't depend on ant-tasks or ant
1538 # so we deactivate all tasks that may be installed
1539 echo "none"
1540 fi
1541}
1542
1543# ------------------------------------------------------------------------------
1544# @internal-function java-pkg_ant-tasks-depend
1545#
1546# Translates the WANT_ANT_TASKS variable into valid dependencies.
1547# ------------------------------------------------------------------------------
1548java-pkg_ant-tasks-depend() {
1549 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1550
1551 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1552 local DEP=""
1553 for i in ${WANT_ANT_TASKS}
1554 do
1555 if [[ ${i} != ant-* ]]; then
1556 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1557 return 1
1558 fi
1559 DEP="${DEP}dev-java/${i} "
1560 done
1561 echo ${DEP}
1562 return 0
1563 else
1564 return 0
1565 fi
1566}
1567
1568# ------------------------------------------------------------------------------
1302# @section-end helper 1569# @section-end helper
1303# ------------------------------------------------------------------------------ 1570# ------------------------------------------------------------------------------
1304 1571
1305# ------------------------------------------------------------------------------ 1572# ------------------------------------------------------------------------------
1306# @section-begin build 1573# @section-begin build
1312 1579
1313# ------------------------------------------------------------------------------ 1580# ------------------------------------------------------------------------------
1314# @ebuild-function eant 1581# @ebuild-function eant
1315# 1582#
1316# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1583# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1317# compiler. 1584# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1318# 1585# variables:
1586# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1587# gentoo.classpath property. Be sure to call
1588# java-ant_rewrite-classpath in src_unpack.
1589# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1319# ------------------------------------------------------------------------------ 1590# ------------------------------------------------------------------------------
1320eant() { 1591eant() {
1321 debug-print-function ${FUNCNAME} $* 1592 debug-print-function ${FUNCNAME} $*
1322 1593
1323 # FIXME get this working 1594 # FIXME get this working
1324# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then 1595# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then
1325# java-pkg_announce-qa-violation \ 1596# java-pkg_announce-qa-violation \
1326# "Using eant, but not depending on dev-java/ant or dev-java/ant-core" 1597# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1327# fi 1598# fi
1328 1599
1329 local antflags="-Dnoget=true" 1600 if ! hasq java-ant-2 ${INHERITED} && is-java-strict; then
1601 local msg="You should inherit java-ant-2 when using eant"
1602 java-pkg_announce-qa-violation ${msg}
1603 die ${msg}
1604 fi
1605
1606 local antflags="-Dnoget=true -Dmaven.mode.offline=true"
1607
1330 java-pkg_init-compiler_ 1608 java-pkg_init-compiler_
1331 local compiler="${GENTOO_COMPILER}" 1609 local compiler="${GENTOO_COMPILER}"
1332 1610
1333 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1611 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1334 1612
1352 if is-java-strict; then 1630 if is-java-strict; then
1353 einfo "Disabling system classpath for ant" 1631 einfo "Disabling system classpath for ant"
1354 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1632 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1355 fi 1633 fi
1356 1634
1357 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1635 for arg in "${@}"; do
1358 antflags="${antflags} -debug" 1636 if [[ ${arg} = -lib ]]; then
1637 if is-java-strict; then
1638 eerror "You should not use the -lib argument to eant because it will fail"
1639 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1640 eerror "or ant properties to make dependencies available."
1641 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1642 eerror "split ant (>=dev-java/ant-core-1.7)."
1643 die "eant -lib is deprecated/forbidden"
1644 else
1645 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1646 echo "more info."
1647 fi
1648 fi
1649 done
1650
1651 if has_version ">=dev-java/ant-core-1.7.0"; then
1652 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1653 ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}"
1654
1655 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1656 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1657
1658 if is-java-strict; then
1659 # if ant-tasks were not set by ebuild or forced, try to determine them from depends
1660 if [[ -z "${ANT_TASKS}" ]]; then
1661 ANT_TASKS="$(java-pkg_ant-tasks-from-deps)"
1662 fi
1663 else
1664 # if ant-tasks is not set by ebuild or forced, activate all of them
1665 ANT_TASKS="${ANT_TASKS:-all}"
1666 fi
1667
1668 # at this point, ANT_TASKS should be "all", "none" or explicit list
1669 if [[ "${ANT_TASKS}" == "all" ]]; then
1670 einfo "Using all available ANT_TASKS"
1671 elif [[ "${ANT_TASKS}" == "none" ]]; then
1672 einfo "Disabling all optional ANT_TASKS"
1673 else
1674 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1675 fi
1676
1677 export ANT_TASKS
1678 fi
1679
1680 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1681 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1682
1683 local gcp="${EANT_GENTOO_CLASSPATH}"
1684
1685 if [[ ${EBUILD_PHASE} = "test" ]]; then
1686 antflags="${antflags} -DJunit.present=true"
1687 [[ ${gcp} && ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1688 fi
1689
1690 local cp
1691
1692 for atom in ${gcp}; do
1693 cp="${cp}:$(java-pkg_getjars ${atom})"
1694 done
1695
1696 if [[ ${cp} ]]; then
1697 # It seems ant does not like single quotes around ${cp}
1698 antflags="${antflags} -Dgentoo.classpath=\"${cp#:}\""
1359 fi 1699 fi
1360 1700
1361 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1701 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1702 debug-print "Calling ant: ${antflags} ${@}"
1362 ant ${antflags} "${@}" || die "eant failed" 1703 ant ${antflags} "${@}" || die "eant failed"
1363 1704
1364} 1705}
1365 1706
1366# ------------------------------------------------------------------------------ 1707# ------------------------------------------------------------------------------
1465# 1806#
1466# ----------------------------------------------------------------------------- 1807# -----------------------------------------------------------------------------
1467java-pkg_init() { 1808java-pkg_init() {
1468 unset JAVAC 1809 unset JAVAC
1469 unset JAVA_HOME 1810 unset JAVA_HOME
1811
1812 # People do all kinds of weird things.
1813 # http://forums.gentoo.org/viewtopic-p-3943166.html
1814 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
1815 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
1816 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
1817 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
1818 ewarn "sun-jdk vms and and as such break configure scripts that"
1819 ewarn "use it (for example app-office/openoffice) so we filter it out."
1820 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
1821 ewarn "make.conf for example) to silence this warning or"
1822 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
1823 fi
1824
1825 if [[ -z ${accept} ]]; then
1826 unset _JAVA_OPTIONS
1827 # phase hooks make this run many times without this
1828 I_WANT_GLOBAL_JAVA_OPTIONS="true"
1829 fi
1830
1470 java-pkg_init_paths_ 1831 java-pkg_init_paths_
1471 java-pkg_switch-vm 1832 java-pkg_switch-vm
1472 PATH=${JAVA_HOME}/bin:${PATH} 1833 PATH=${JAVA_HOME}/bin:${PATH}
1473 1834
1474 # TODO we will probably want to set JAVAC and JAVACFLAGS 1835 # TODO we will probably want to set JAVAC and JAVACFLAGS
1479 # When users have crazy classpaths some packages can fail to compile. 1840 # When users have crazy classpaths some packages can fail to compile.
1480 # and everything should work with empty CLASSPATH. 1841 # and everything should work with empty CLASSPATH.
1481 # This also helps prevent unexpected dependencies on random things 1842 # This also helps prevent unexpected dependencies on random things
1482 # from the CLASSPATH. 1843 # from the CLASSPATH.
1483 unset CLASSPATH 1844 unset CLASSPATH
1845
1846 # Unset external ANT_ stuff
1847 unset ANT_TASKS
1848 unset ANT_OPTS
1484} 1849}
1485 1850
1486# ------------------------------------------------------------------------------ 1851# ------------------------------------------------------------------------------
1487# @function-internal java-pkg-init-compiler_ 1852# @function-internal java-pkg-init-compiler_
1488# 1853#
1926 einfo "Classes" 2291 einfo "Classes"
1927 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR}," 2292 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1928 fi 2293 fi
1929} 2294}
1930 2295
1931# TODO document 2296# ------------------------------------------------------------------------------
2297# @internal-function java-pkg_verify-classes
2298#
1932# Verify that the classes were compiled for the right source / target 2299# Verify that the classes were compiled for the right source / target. Dies if
2300# not.
2301# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2302# ------------------------------------------------------------------------------
1933java-pkg_verify-classes() { 2303java-pkg_verify-classes() {
1934 ebegin "Verifying java class versions"
1935 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 2304 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1936 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 2305 local target=$(java-pkg_get-target)
2306 local result
2307 local log="${T}/class-version-verify.log"
2308 if [[ -n "${1}" ]]; then
2309 class-version-verify.py -v -t ${target} "${1}" > "${log}"
1937 result=$? 2310 result=$?
1938 eend ${result}
1939 if [[ ${result} == 0 ]]; then
1940 einfo "All good"
1941 else 2311 else
1942 ewarn "Possible problem" 2312 ebegin "Verifying java class versions (target: ${target})"
1943 die "Bad class files found" 2313 class-version-verify.py -v -t ${target} -r "${D}" > "${log}"
2314 result=$?
2315 eend ${result}
2316 fi
2317 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2318 if [[ ${result} != 0 ]]; then
2319 eerror "Incorrect bytecode version found"
2320 [[ -n "${1}" ]] && eerror "in file: ${1}"
2321 eerror "See ${log} for more details."
2322 die "Incorrect bytecode found"
1944 fi 2323 fi
1945} 2324}
1946 2325
1947# ------------------------------------------------------------------------------ 2326# ------------------------------------------------------------------------------
1948# @section-end internal 2327# @section-end internal

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

  ViewVC Help
Powered by ViewVC 1.1.20