java-pkg-2.eclass 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. # Copyright 2004-2015 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # @ECLASS: java-pkg-2.eclass
  4. # @MAINTAINER:
  5. # java@gentoo.org
  6. # @AUTHOR:
  7. # Thomas Matthijs <axxo@gentoo.org>
  8. # @BLURB: Eclass for Java Packages
  9. # @DESCRIPTION:
  10. # This eclass should be inherited for pure Java packages, or by packages which
  11. # need to use Java.
  12. inherit java-utils-2
  13. # @ECLASS-VARIABLE: JAVA_PKG_IUSE
  14. # @DEFAULT_UNSET
  15. # @DESCRIPTION:
  16. # Use JAVA_PKG_IUSE instead of IUSE for doc, source and examples so that
  17. # the eclass can automatically add the needed dependencies for the java-pkg_do*
  18. # functions.
  19. IUSE="${JAVA_PKG_IUSE}"
  20. # Java packages need java-config, and a fairly new release of Portage.
  21. # JAVA_PKG_E_DEPEND is defined in java-utils.eclass.
  22. DEPEND="${JAVA_PKG_E_DEPEND}"
  23. # Nothing special for RDEPEND... just the same as DEPEND.
  24. RDEPEND="${DEPEND}"
  25. # Commons packages follow the same rules so do it here
  26. if [[ ${CATEGORY} = dev-java && ${PN} = commons-* ]]; then
  27. HOMEPAGE="http://commons.apache.org/${PN#commons-}/"
  28. SRC_URI="mirror://apache/${PN/-///}/source/${P}-src.tar.gz"
  29. fi
  30. case "${EAPI:-0}" in
  31. 0|1) EXPORT_FUNCTIONS pkg_setup src_compile pkg_preinst ;;
  32. *) EXPORT_FUNCTIONS pkg_setup src_prepare src_compile pkg_preinst ;;
  33. esac
  34. # @FUNCTION: java-pkg-2_pkg_setup
  35. # @DESCRIPTION:
  36. # pkg_setup initializes the Java environment
  37. java-pkg-2_pkg_setup() {
  38. java-pkg_init
  39. }
  40. # @FUNCTION: java-pkg-2_src_prepare
  41. # @DESCRIPTION:
  42. # wrapper for java-utils-2_src_prepare
  43. java-pkg-2_src_prepare() {
  44. java-utils-2_src_prepare
  45. }
  46. # @FUNCTION: java-pkg-2_src_compile
  47. # @DESCRIPTION:
  48. # Default src_compile for java packages
  49. #
  50. # @CODE
  51. # Variables:
  52. # EANT_BUILD_XML - controls the location of the build.xml (default: ./build.xml)
  53. # EANT_FILTER_COMPILER - Calls java-pkg_filter-compiler with the value
  54. # EANT_BUILD_TARGET - the ant target/targets to execute (default: jar)
  55. # EANT_DOC_TARGET - the target to build extra docs under the doc use flag
  56. # (default: javadoc; declare empty to disable completely)
  57. # EANT_GENTOO_CLASSPATH - @see eant documention in java-utils-2.eclass
  58. # EANT_EXTRA_ARGS - extra arguments to pass to eant
  59. # EANT_ANT_TASKS - modifies the ANT_TASKS variable in the eant environment
  60. # @CODE
  61. java-pkg-2_src_compile() {
  62. if [[ -e "${EANT_BUILD_XML:=build.xml}" ]]; then
  63. # auto generate classpath
  64. java-pkg_gen-cp EANT_GENTOO_CLASSPATH
  65. [[ "${EANT_FILTER_COMPILER}" ]] && \
  66. java-pkg_filter-compiler ${EANT_FILTER_COMPILER}
  67. local antflags="${EANT_BUILD_TARGET:=jar}"
  68. if has doc ${IUSE} && [[ -n "${EANT_DOC_TARGET=javadoc}" ]]; then
  69. antflags="${antflags} $(use_doc ${EANT_DOC_TARGET})"
  70. fi
  71. local tasks
  72. [[ ${EANT_ANT_TASKS} ]] && tasks="${ANT_TASKS} ${EANT_ANT_TASKS}"
  73. ANT_TASKS="${tasks:-${ANT_TASKS}}" \
  74. eant ${antflags} -f "${EANT_BUILD_XML}" ${EANT_EXTRA_ARGS} "${@}"
  75. else
  76. echo "${FUNCNAME}: ${EANT_BUILD_XML} not found so nothing to do."
  77. fi
  78. }
  79. # @FUNCTION: java-pkg-2_src_test
  80. # @DESCRIPTION:
  81. # src_test, not exported.
  82. java-pkg-2_src_test() {
  83. [[ -e "${EANT_BUILD_XML:=build.xml}" ]] || return
  84. if [[ ${EANT_TEST_TARGET} ]] || < "${EANT_BUILD_XML}" tr -d "\n" | grep -Eq "<target\b[^>]*\bname=[\"']test[\"']"; then
  85. local opts task_re junit_re pkg
  86. if [[ ${EANT_TEST_JUNIT_INTO} ]]; then
  87. java-pkg_jar-from --into "${EANT_TEST_JUNIT_INTO}" junit
  88. fi
  89. if [[ ${EANT_TEST_GENTOO_CLASSPATH} ]]; then
  90. EANT_GENTOO_CLASSPATH="${EANT_TEST_GENTOO_CLASSPATH}"
  91. fi
  92. ANT_TASKS=${EANT_TEST_ANT_TASKS:-${ANT_TASKS:-${EANT_ANT_TASKS}}}
  93. task_re="\bdev-java/ant-junit(4)?(-[^:]+)?(:\S+)\b"
  94. junit_re="\bdev-java/junit(-[^:]+)?(:\S+)\b"
  95. if [[ ${DEPEND} =~ ${task_re} ]]; then
  96. pkg="ant-junit${BASH_REMATCH[1]}${BASH_REMATCH[3]}"
  97. pkg="${pkg%:0}"
  98. if [[ ${ANT_TASKS} && "${ANT_TASKS}" != none ]]; then
  99. ANT_TASKS="${ANT_TASKS} ${pkg}"
  100. else
  101. ANT_TASKS="${pkg}"
  102. fi
  103. elif [[ ${DEPEND} =~ ${junit_re} ]]; then
  104. pkg="junit${BASH_REMATCH[2]}"
  105. pkg="${pkg%:0}"
  106. opts="-Djunit.jar=\"$(java-pkg_getjar ${pkg} junit.jar)\""
  107. if [[ ${EANT_GENTOO_CLASSPATH} ]]; then
  108. EANT_GENTOO_CLASSPATH+=",${pkg}"
  109. else
  110. EANT_GENTOO_CLASSPATH="${pkg}"
  111. fi
  112. fi
  113. eant ${opts} -f "${EANT_BUILD_XML}" \
  114. ${EANT_EXTRA_ARGS} ${EANT_TEST_EXTRA_ARGS} ${EANT_TEST_TARGET:-test}
  115. else
  116. echo "${FUNCNAME}: No test target in ${EANT_BUILD_XML}"
  117. fi
  118. }
  119. # @FUNCTION: java-pkg-2_pkg_preinst
  120. # @DESCRIPTION:
  121. # wrapper for java-utils-2_pkg_preinst
  122. java-pkg-2_pkg_preinst() {
  123. java-utils-2_pkg_preinst
  124. }