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

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

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

Revision 1.56 Revision 1.57
12# and xml-rewrite.py because they were so slow 12# and xml-rewrite.py because they were so slow
13# Petteri Räty (betelgeuse@gentoo.org) 13# Petteri Räty (betelgeuse@gentoo.org)
14# 14#
15# Licensed under the GNU General Public License, v2 15# Licensed under the GNU General Public License, v2
16# 16#
17# $Header: /var/cvsroot/gentoo-x86/eclass/java-ant-2.eclass,v 1.56 2013/04/20 18:23:57 sera Exp $ 17# $Header: /var/cvsroot/gentoo-x86/eclass/java-ant-2.eclass,v 1.57 2013/10/05 13:40:57 caster Exp $
18
19# @ECLASS: java-ant-2.eclass
20# @MAINTAINER:
21# java@gentoo.org
22# @AUTHOR:
23# kiorky (kiorky@cryptelium.net), Petteri Räty (betelgeuse@gentoo.org)
24# @BLURB: eclass for ant based Java packages
25# @DESCRIPTION:
26# Eclass for Ant-based Java packages. Provides support for both automatic and
27# manual manipulation of build.xml files. Should be inherited after java-pkg-2
28# or java-pkg-opt-2 eclass.
18 29
19inherit java-utils-2 multilib 30inherit java-utils-2 multilib
20 31
21# This eclass provides functionality for Java packages which use 32# This eclass provides functionality for Java packages which use
22# ant to build. In particular, it will attempt to fix build.xml files, so that 33# ant to build. In particular, it will attempt to fix build.xml files, so that
23# they use the appropriate 'target' and 'source' attributes. 34# they use the appropriate 'target' and 'source' attributes.
24 35
25# ----------------------------------------------------------------------------- 36# @ECLASS-VARIABLE: WANT_ANT_TASKS
26# @variable-preinherit WANT_ANT_TASKS 37# @DEFAULT_UNSET
27# @variable-default "" 38# @DESCRIPTION:
39# An $IFS separated list of ant tasks.
40# Ebuild can specify this variable before inheriting java-ant-2 eclass to
41# determine ANT_TASKS it needs. They will be automatically translated to
42# DEPEND variable and ANT_TASKS variable. JAVA_PKG_FORCE_ANT_TASKS can override
43# ANT_TASKS set by WANT_ANT_TASKS, but not the DEPEND due to caching.
44# Ebuilds that need to depend conditionally on certain tasks and specify them
45# differently for different eant calls can't use this simplified approach.
46# You also cannot specify version or anything else than ant-*.
28# 47#
29# Please see the description in java-utils-2.eclass. 48# @CODE
49# WANT_ANT_TASKS="ant-junit ant-trax"
50# @CODE
51
52#The implementation of dependencies is handled by java-utils-2.eclass
30#WANT_ANT_TASKS 53#WANT_ANT_TASKS
31 54
32# ----------------------------------------------------------------------------- 55# @ECLASS-VARIABLE: JAVA_ANT_DISABLE_ANT_CORE_DEP
33# @variable-preinherit JAVA_ANT_DISABLE_ANT_CORE_DEP 56# @DEFAULT_UNSET
34# @variable-default unset for java-pkg-2, true for java-pkg-opt-2 57# @DESCRIPTION:
35#
36# Setting this variable non-empty before inheriting java-ant-2 disables adding 58# Setting this variable non-empty before inheriting java-ant-2 disables adding
37# dev-java/ant-core into DEPEND. 59# dev-java/ant-core into DEPEND.
38
39# construct ant-speficic DEPEND
40# add ant-core into DEPEND, unless disabled
41if [[ -z "${JAVA_ANT_DISABLE_ANT_CORE_DEP}" ]]; then 60if [[ -z "${JAVA_ANT_DISABLE_ANT_CORE_DEP}" ]]; then
42 JAVA_ANT_E_DEPEND="${JAVA_ANT_E_DEPEND} >=dev-java/ant-core-1.8.2" 61 JAVA_ANT_E_DEPEND="${JAVA_ANT_E_DEPEND} >=dev-java/ant-core-1.8.2"
43fi 62fi
44 63
45# add ant tasks specified in WANT_ANT_TASKS to DEPEND 64# add ant tasks specified in WANT_ANT_TASKS to DEPEND
68 eerror "java-ant-2 eclass can only be inherited AFTER java-pkg-2 or java-pkg-opt-2" 87 eerror "java-ant-2 eclass can only be inherited AFTER java-pkg-2 or java-pkg-opt-2"
69fi 88fi
70 89
71DEPEND="${JAVA_ANT_E_DEPEND}" 90DEPEND="${JAVA_ANT_E_DEPEND}"
72 91
73# ------------------------------------------------------------------------------ 92# @ECLASS-VARIABLE: JAVA_PKG_BSFIX
74# @global JAVA_PKG_BSFIX 93# @DESCRIPTION:
75#
76# Should we attempt to 'fix' ant build files to include the source/target 94# Should we attempt to 'fix' ant build files to include the source/target
77# attributes when calling javac? 95# attributes when calling javac?
78#
79# default: on
80# ------------------------------------------------------------------------------
81JAVA_PKG_BSFIX=${JAVA_PKG_BSFIX:-"on"} 96JAVA_PKG_BSFIX=${JAVA_PKG_BSFIX:-"on"}
82 97
83# ------------------------------------------------------------------------------ 98# @ECLASS-VARIABLE: JAVA_PKG_BSFIX_ALL
84# @global JAVA_PKG_BSFIX_ALL 99# @DESCRIPTION:
85#
86# If we're fixing build files, should we try to fix all the ones we can find? 100# If we're fixing build files, should we try to fix all the ones we can find?
87#
88# default: yes
89# ------------------------------------------------------------------------------
90JAVA_PKG_BSFIX_ALL=${JAVA_PKG_BSFIX_ALL:-"yes"} 101JAVA_PKG_BSFIX_ALL=${JAVA_PKG_BSFIX_ALL:-"yes"}
91 102
92# ------------------------------------------------------------------------------ 103# @ECLASS-VARIABLE: JAVA_PKG_BSFIX_NAME
93# @global JAVA_PKG_BSFIX_NAME 104# @DESCRIPTION:
94#
95# Filename of build files to fix/search for 105# Filename of build files to fix/search for
96#
97# default: build.xml
98# ------------------------------------------------------------------------------
99JAVA_PKG_BSFIX_NAME=${JAVA_PKG_BSFIX_NAME:-"build.xml"} 106JAVA_PKG_BSFIX_NAME=${JAVA_PKG_BSFIX_NAME:-"build.xml"}
100 107
101# ------------------------------------------------------------------------------ 108# @ECLASS-VARIABLE: JAVA_PKG_BSFIX_TARGET_TAGS
102# @global JAVA_PKG_BSFIX_TARGETS_TAGS 109# @DESCRIPTION:
103#
104# Targets to fix the 'source' attribute in 110# Targets to fix the 'source' attribute in
105#
106# default: javac xjavac javac.preset
107# ------------------------------------------------------------------------------
108JAVA_PKG_BSFIX_TARGET_TAGS=${JAVA_PKG_BSFIX_TARGET_TAGS:-"javac xjavac javac.preset"} 111JAVA_PKG_BSFIX_TARGET_TAGS=${JAVA_PKG_BSFIX_TARGET_TAGS:-"javac xjavac javac.preset"}
109 112
110# ------------------------------------------------------------------------------ 113# @ECLASS-VARIABLE: JAVA_PKG_BSFIX_SOURCE_TAGS
111# @global JAVA_PKG_BSFIX_SOURCE_TAGS 114# @DESCRIPTION:
112#
113# Targets to fix the 'target' attribute in 115# Targets to fix the 'target' attribute in
114#
115# default: javacdoc javac xjavac javac.preset
116# ------------------------------------------------------------------------------
117JAVA_PKG_BSFIX_SOURCE_TAGS=${JAVA_PKG_BSFIX_SOURCE_TAGS:-"javadoc javac xjavac javac.preset"} 116JAVA_PKG_BSFIX_SOURCE_TAGS=${JAVA_PKG_BSFIX_SOURCE_TAGS:-"javadoc javac xjavac javac.preset"}
118 117
119# ------------------------------------------------------------------------------ 118# @ECLASS-VARIABLE: JAVA_ANT_CLASSPATH_TAGS
120# @global JAVA_ANT_CLASSPATH_TAGS 119# @DESCRIPTION:
121#
122# Targets to add the classpath attribute to 120# Targets to add the classpath attribute to
123#
124# default: javac xjavac
125# ------------------------------------------------------------------------------
126JAVA_ANT_CLASSPATH_TAGS="javac xjavac" 121JAVA_ANT_CLASSPATH_TAGS="javac xjavac"
127 122
128# ------------------------------------------------------------------------------
129# @global JAVA_ANT_IGNORE_SYSTEM_CLASSES 123# @ECLASS-VARIABLE: JAVA_ANT_IGNORE_SYSTEM_CLASSES
130# 124# @DEFAULT_UNSET
131# Rewrites available tasks to ignore ant classpath. 125# @DESCRIPTION:
132# 126# When set, <available> Ant tasks are rewritten to ignore Ant's runtime classpath.
133# default: off
134# ------------------------------------------------------------------------------
135 127
136case "${EAPI:-0}" in 128case "${EAPI:-0}" in
137 0|1) : ;; 129 0|1) : ;;
138 *) EXPORT_FUNCTIONS src_configure ;; 130 *) EXPORT_FUNCTIONS src_configure ;;
139esac 131esac
140 132
141# ------------------------------------------------------------------------------ 133# @FUNCTION: java-ant-2_src_configure
142# @eclass-src_configure 134# @DESCRIPTION:
143# 135# src_configure rewrites the build.xml files automatically, unless EAPI is undefined, 0 or 1.
144# src_configure rewrites the build.xml files
145# ------------------------------------------------------------------------------
146java-ant-2_src_configure() { 136java-ant-2_src_configure() {
147 # if java support is optional, don't perform this when the USE flag is off 137 # if java support is optional, don't perform this when the USE flag is off
148 if has java-pkg-opt-2 ${INHERITED}; then 138 if has java-pkg-opt-2 ${INHERITED}; then
149 use ${JAVA_PKG_OPT_USE} || return 139 use ${JAVA_PKG_OPT_USE} || return
150 fi 140 fi
157 147
158 java-ant_bsfix 148 java-ant_bsfix
159 touch "${T}/java-ant-2_src_configure-run" 149 touch "${T}/java-ant-2_src_configure-run"
160} 150}
161 151
162# ------------------------------------------------------------------------------ 152# @FUNCTION: java-ant_bsfix
163# @private java-ant_bsfix 153# @INTERNAL
154# @DESCRIPTION:
155# Attempts to fix build files.
164# 156#
165# Attempts to fix build files. The following variables will affect its behavior 157# @CODE
166# as listed above: 158# Affected by variables:
167# JAVA_PKG_BSFIX 159# JAVA_PKG_BSFIX
168# JAVA_PKG_BSFIX_ALL 160# JAVA_PKG_BSFIX_ALL
169# JAVA_PKG_BSFIX_NAME, 161# JAVA_PKG_BSFIX_NAME,
170# ------------------------------------------------------------------------------ 162# @CODE
171java-ant_bsfix() { 163java-ant_bsfix() {
172 debug-print-function ${FUNCNAME} $* 164 debug-print-function ${FUNCNAME} $*
173 165
174 [[ "${JAVA_PKG_BSFIX}" != "on" ]] && return 166 [[ "${JAVA_PKG_BSFIX}" != "on" ]] && return
175 if ! java-pkg_needs-vm; then 167 if ! java-pkg_needs-vm; then
208 else 200 else
209 die ${1} 201 die ${1}
210 fi 202 fi
211} 203}
212 204
213# ------------------------------------------------------------------------------
214# @public java-ant_bsfix_files 205# @FUNCTION: java-ant_bsfix_files
206# @USAGE: <path/to/first/build.xml> [path/to/second.build.xml ...]
207# @DESCRIPTION:
208# Attempts to fix named build files.
215# 209#
216# Attempts to fix named build files. The following variables will affect its behavior 210# @CODE
217# as listed above: 211# Affected by variables:
218# JAVA_PKG_BSFIX_SOURCE_TAGS 212# JAVA_PKG_BSFIX_SOURCE_TAGS
219# JAVA_PKG_BSFIX_TARGET_TAGS 213# JAVA_PKG_BSFIX_TARGET_TAGS
220# JAVA_ANT_REWRITE_CLASSPATH 214# JAVA_ANT_REWRITE_CLASSPATH
221# JAVA_ANT_JAVADOC_INPUT_DIRS: Where we can find java sources for javadoc 215# JAVA_ANT_JAVADOC_INPUT_DIRS: Where we can find java sources for javadoc
222# input. Can be a space separated list of 216# input. Can be a space separated list of
223# directories 217# directories
224# JAVA_ANT_BSFIX_EXTRA_ARGS: You can use this to pass extra variables to the 218# JAVA_ANT_BSFIX_EXTRA_ARGS: You can use this to pass extra variables to the
225# rewriter if you know what you are doing. 219# rewriter if you know what you are doing.
220# @CODE
226# 221#
227# If JAVA_ANT_JAVADOC_INPUT_DIRS is set, we will turn on the adding of a basic 222# If JAVA_ANT_JAVADOC_INPUT_DIRS is set, we will turn on the adding of a basic
228# javadoc target to the ant's build.xml with the javadoc xml-rewriter feature. 223# javadoc target to the ant's build.xml with the javadoc xml-rewriter feature.
229# Then we will set EANT DOC TARGET to the added javadoc target 224# Then we will set EANT DOC TARGET to the added javadoc target
230# NOTE: the variable JAVA_ANT_JAVADOC_OUTPUT_DIR points where we will 225# NOTE: the variable JAVA_ANT_JAVADOC_OUTPUT_DIR points where we will
231# generate the javadocs. This is a read-only variable, dont change it. 226# generate the javadocs. This is a read-only variable, dont change it.
232 227
233# When changing this function, make sure that it works with paths with spaces in 228# When changing this function, make sure that it works with paths with spaces in
234# them. 229# them.
235# ------------------------------------------------------------------------------
236java-ant_bsfix_files() { 230java-ant_bsfix_files() {
237 debug-print-function ${FUNCNAME} $* 231 debug-print-function ${FUNCNAME} $*
238 232
239 [[ ${#} = 0 ]] && die "${FUNCNAME} called without arguments" 233 [[ ${#} = 0 ]] && die "${FUNCNAME} called without arguments"
240 234
372 fi 366 fi
373 return 0 # so that the 1 for diff doesn't get reported 367 return 0 # so that the 1 for diff doesn't get reported
374} 368}
375 369
376 370
377# ------------------------------------------------------------------------------ 371# @FUNCTION: java-ant_bsfix_one
378# @public java-ant_bsfix_one 372# @USAGE: <path/to/build.xml>
379# 373# @DESCRIPTION:
380# Attempts to fix named build file. The following variables will affect its behavior 374# Attempts to fix named build file.
381# as listed above: 375#
376# @CODE
377# Affected by variables:
382# JAVA_PKG_BSFIX_SOURCE_TAGS 378# JAVA_PKG_BSFIX_SOURCE_TAGS
383# JAVA_PKG_BSFIX_TARGET_TAGS 379# JAVA_PKG_BSFIX_TARGET_TAGS
384# ------------------------------------------------------------------------------ 380# @CODE
385java-ant_bsfix_one() { 381java-ant_bsfix_one() {
386 debug-print-function ${FUNCNAME} $* 382 debug-print-function ${FUNCNAME} $*
387 383
388 if [ -z "${1}" ]; then 384 if [ -z "${1}" ]; then
389 eerror "${FUNCNAME} needs one argument" 385 eerror "${FUNCNAME} needs one argument"
391 fi 387 fi
392 388
393 java-ant_bsfix_files "${1}" 389 java-ant_bsfix_files "${1}"
394} 390}
395 391
396# ------------------------------------------------------------------------------
397# @public java-ant_rewrite-classpath 392# @FUNCTION: java-ant_rewrite-classpath
398# 393# @USAGE: [path/to/build.xml]
394# @DESCRIPTION:
399# Adds 'classpath="${gentoo.classpath}"' to specified build file. 395# Adds 'classpath="${gentoo.classpath}"' to specified build file.
396#
400# Affected by: 397# Affected by:
401# JAVA_ANT_CLASSPATH_TAGS 398# JAVA_ANT_CLASSPATH_TAGS
402# @param $1 - the file to rewrite (defaults to build.xml) 399#
403# ------------------------------------------------------------------------------ 400# Parameter defaults to build.xml when not specified
404java-ant_rewrite-classpath() { 401java-ant_rewrite-classpath() {
405 debug-print-function ${FUNCNAME} $* 402 debug-print-function ${FUNCNAME} $*
406 403
407 local file="${1}" 404 local file="${1}"
408 [[ -z "${1}" ]] && file=build.xml 405 [[ -z "${1}" ]] && file=build.xml
421 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then 418 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
422 diff -NurbB "${file}.orig" "${file}" 419 diff -NurbB "${file}.orig" "${file}"
423 fi 420 fi
424} 421}
425 422
426# ------------------------------------------------------------------------------
427# @public java-ant_remove-taskdefs 423# @FUNCTION: java-ant_remove-taskdefs
428# 424# @USAGE: [--name NAME] [path/to/build.xml]
425# @DESCRIPTION:
429# Removes (named) taskdef elements from the file. 426# Removes (named) taskdef elements from the build.xml file.
430# Options:
431# --name NAME : only remove taskdef with name NAME. 427# When --name NAME is specified, only remove taskdef with name NAME. Otherwise,
432# @param $1 - the file to rewrite (defaults to build.xml) 428# all taskdefs are removed.
433# ------------------------------------------------------------------------------ 429# The file to rewrite defaults to build.xml when not specified.
434java-ant_remove-taskdefs() { 430java-ant_remove-taskdefs() {
435 debug-print-function ${FUNCNAME} $* 431 debug-print-function ${FUNCNAME} $*
436 local task_name 432 local task_name
437 if [[ "${1}" == --name ]]; then 433 if [[ "${1}" == --name ]]; then
438 task_name="${2}" 434 task_name="${2}"
453f.close() 449f.close()
454EOF 450EOF
455 [[ $? != 0 ]] && die "Removing taskdefs failed" 451 [[ $? != 0 ]] && die "Removing taskdefs failed"
456} 452}
457 453
458# ------------------------------------------------------------------------------
459# @public java-ant_ignore-system-classes 454# @FUNCTION: java-ant_ignore-system-classes
460# 455# @USAGE: [path/to/build.xml]
456# @DESCRIPTION:
461# Makes the available task ignore classes in the system classpath 457# Makes the available task ignore classes in the system classpath
462# @param $1 - the file to rewrite (defaults to build.xml) 458# Parameter defaults to build.xml when not specified
463# ------------------------------------------------------------------------------
464java-ant_ignore-system-classes() { 459java-ant_ignore-system-classes() {
465 debug-print-function ${FUNCNAME} $* 460 debug-print-function ${FUNCNAME} $*
466 local file=${1:-build.xml} 461 local file=${1:-build.xml}
467 echo "Changing ignoresystemclasses to true for available tasks in ${file}" 462 echo "Changing ignoresystemclasses to true for available tasks in ${file}"
468 java-ant_xml-rewrite -f "${file}" --change \ 463 java-ant_xml-rewrite -f "${file}" --change \
469 -e available -a ignoresystemclasses -v "true" 464 -e available -a ignoresystemclasses -v "true"
470} 465}
471 466
472# ------------------------------------------------------------------------------
473# @public java-ant_xml-rewrite 467# @FUNCTION: java-ant_xml-rewrite
468# @USAGE: <xml rewriter arguments>
469# @DESCRIPTION:
474# Run the right xml-rewrite binary with the given arguments 470# Run the right xml-rewrite binary with the given arguments
475# ------------------------------------------------------------------------------
476java-ant_xml-rewrite() { 471java-ant_xml-rewrite() {
477 local gen2="/usr/bin/xml-rewrite-2.py" 472 local gen2="/usr/bin/xml-rewrite-2.py"
478 local gen2_1="/usr/$(get_libdir)/javatoolkit/bin/xml-rewrite-2.py" 473 local gen2_1="/usr/$(get_libdir)/javatoolkit/bin/xml-rewrite-2.py"
479 # gen1 is deprecated 474 # gen1 is deprecated
480 if [[ -x "${gen2}" ]]; then 475 if [[ -x "${gen2}" ]]; then
486 eerror "Do you have dev-java/javatoolkit installed?" 481 eerror "Do you have dev-java/javatoolkit installed?"
487 die "xml-rewrite not found" 482 die "xml-rewrite not found"
488 fi 483 fi
489} 484}
490 485
491# ------------------------------------------------------------------------------
492# @public java-ant_rewrite-bootclasspath 486# @FUNCTION: java-ant_rewrite-bootclasspath
493# 487# @USAGE: <version> [path/to/build.xml] [prepend] [append]
488# @DESCRIPTION:
494# Adds bootclasspath to javac-like tasks in build.xml filled with jars of a 489# Adds bootclasspath to javac-like tasks in build.xml filled with jars of a
495# bootclasspath package of given version. 490# bootclasspath package of given version.
496# 491#
492# @CODE
497# Affected by: 493# Affected by:
498# JAVA_PKG_BSFIX_TARGET_TAGS - the tags of javac tasks 494# JAVA_PKG_BSFIX_TARGET_TAGS - the tags of javac tasks
499# 495#
496# Parameters:
500# @param $1 - the version of bootclasspath (e.g. 1.5), 'auto' for bootclasspath 497# $1 - the version of bootclasspath (e.g. 1.5), 'auto' for bootclasspath
501# of the current JDK 498# of the current JDK
502# @param $2 - path to desired build.xml file, defaults to 'build.xml' 499# $2 - path to desired build.xml file, defaults to 'build.xml'
503# @param $3 - (optional) what to prepend the bootclasspath with (to override) 500# $3 - (optional) what to prepend the bootclasspath with (to override)
504# @param $4 - (optional) what to append to the bootclasspath 501# $4 - (optional) what to append to the bootclasspath
505# ------------------------------------------------------------------------------ 502# @CODE
506
507java-ant_rewrite-bootclasspath() { 503java-ant_rewrite-bootclasspath() {
508 local version="${1}" 504 local version="${1}"
509 local file="${2-build.xml}" 505 local file="${2-build.xml}"
510 local extra_before="${3}" 506 local extra_before="${3}"
511 local extra_after="${4}" 507 local extra_after="${4}"

Legend:
Removed from v.1.56  
changed lines
  Added in v.1.57

  ViewVC Help
Powered by ViewVC 1.1.20