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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.155 - (hide annotations) (download)
Sun Oct 6 14:37:31 2013 UTC (14 months, 2 weeks ago) by caster
Branch: MAIN
Changes since 1.154: +462 -601 lines
Convert comments for eclass manpages. Heavily based on work from ercpe, bug #476946.

1 nichoj 1.1 # Base eclass for Java packages
2     #
3     # Copyright (c) 2004-2005, Thomas Matthijs <axxo@gentoo.org>
4     # Copyright (c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
5 fauli 1.149 # Copyright (c) 2004-2011, Gentoo Foundation
6 nichoj 1.1 #
7     # Licensed under the GNU General Public License, v2
8     #
9 caster 1.155 # $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.154 2013/08/27 05:32:28 radhermit Exp $
10 nichoj 1.1
11 caster 1.155 # @ECLASS: java-utils-2.eclass
12     # @MAINTAINER:
13     # java@gentoo.org
14     # @AUTHOR:
15     # Thomas Matthijs <axxo@gentoo.org>, Karl Trygve Kalleberg <karltk@gentoo.org>
16     # @BLURB: Base eclass for Java packages
17     # @DESCRIPTION:
18     # This eclass provides functionality which is used by java-pkg-2.eclass,
19     # java-pkg-opt-2.eclass and java-ant-2 eclass, as well as from ebuilds.
20     #
21     # This eclass should not be inherited this directly from an ebuild. Instead,
22     # you should inherit java-pkg-2 for Java packages or java-pkg-opt-2 for packages
23     # that have optional Java support. In addition you can inherit java-ant-2 for
24     # Ant-based packages.
25 nichoj 1.1 inherit eutils versionator multilib
26    
27 flameeyes 1.33 IUSE="elibc_FreeBSD"
28    
29 nichoj 1.1 # Make sure we use java-config-2
30     export WANT_JAVA_CONFIG="2"
31    
32 caster 1.155 # @VARIABLE: JAVA_PKG_PORTAGE_DEP
33     # @INTERNAL
34     # @DESCRIPTION:
35 betelgeuse 1.92 # The version of portage we need to function properly. Previously it was
36     # portage with phase hooks support but now we use a version with proper env
37 betelgeuse 1.121 # saving. For EAPI 2 we have new enough stuff so let's have cleaner deps.
38 ssuominen 1.141 has "${EAPI}" 0 1 && JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1.2.7"
39 nichoj 1.7
40 caster 1.155 # @VARIABLE: JAVA_PKG_E_DEPEND
41     # @INTERNAL
42     # @DESCRIPTION:
43 nichoj 1.1 # This is a convience variable to be used from the other java eclasses. This is
44 betelgeuse 1.91 # the version of java-config we want to use. Usually the latest stable version
45     # so that ebuilds can use new features without depending on specific versions.
46 betelgeuse 1.131 JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.1.9-r1 ${JAVA_PKG_PORTAGE_DEP}"
47 ssuominen 1.141 has source ${JAVA_PKG_IUSE} && JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} source? ( app-arch/zip )"
48 nichoj 1.1
49 caster 1.155 # @ECLASS-VARIABLE: JAVA_PKG_WANT_BOOTCLASSPATH
50     # @DEFAULT_UNSET
51     # @DESCRIPTION:
52 caster 1.130 # The version of bootclasspath the package needs to work. Translates to a proper
53 caster 1.155 # dependency. The bootclasspath can then be obtained by java-ant_rewrite-bootclasspath
54 caster 1.130 if [[ -n "${JAVA_PKG_WANT_BOOTCLASSPATH}" ]]; then
55     if [[ "${JAVA_PKG_WANT_BOOTCLASSPATH}" == "1.5" ]]; then
56     JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} >=dev-java/gnu-classpath-0.98-r1:0.98"
57     else
58     eerror "Unknown value of JAVA_PKG_WANT_BOOTCLASSPATH"
59     # since die in global scope doesn't work, this will make repoman fail
60     JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} BAD_JAVA_PKG_WANT_BOOTCLASSPATH"
61     fi
62     fi
63    
64 caster 1.155 # @ECLASS-VARIABLE: JAVA_PKG_ALLOW_VM_CHANGE
65     # @DESCRIPTION:
66     # Allow this eclass to change the active VM?
67     # If your system VM isn't sufficient for the package, the build will fail
68     # instead of trying to switch to another VM.
69 nichoj 1.1 #
70 caster 1.155 # Overriding the default can be useful for testing specific VMs locally, but
71     # should not be used in the final ebuild.
72 nichoj 1.1 JAVA_PKG_ALLOW_VM_CHANGE=${JAVA_PKG_ALLOW_VM_CHANGE:="yes"}
73    
74 caster 1.155 # @ECLASS-VARIABLE: JAVA_PKG_FORCE_VM
75     # @DEFAULT_UNSET
76     # @DESCRIPTION:
77 nichoj 1.1 # Explicitly set a particular VM to use. If its not valid, it'll fall back to
78     # whatever /etc/java-config-2/build/jdk.conf would elect to use.
79     #
80     # Should only be used for testing and debugging.
81     #
82 caster 1.155 # Example: use sun-jdk-1.5 to emerge foo:
83     # @CODE
84 nichoj 1.1 # JAVA_PKG_FORCE_VM=sun-jdk-1.5 emerge foo
85 caster 1.155 # @CODE
86 nichoj 1.1
87 caster 1.155 # @ECLASS-VARIABLE: JAVA_PKG_WANT_BUILD_VM
88     # @DEFAULT_UNSET
89     # @DESCRIPTION:
90 sera 1.150 # A list of VM handles to choose a build VM from. If the list contains the
91     # currently active VM use that one, otherwise step through the list till a
92     # usable/installed VM is found.
93     #
94     # This allows to use an explicit list of JDKs in DEPEND instead of a virtual.
95     # Users of this variable must make sure at least one of the listed handles is
96     # covered by DEPEND.
97 caster 1.155 # Requires JAVA_PKG_WANT_SOURCE and JAVA_PKG_WANT_TARGET to be set as well.
98 sera 1.150
99 caster 1.155 # @ECLASS-VARIABLE: JAVA_PKG_WANT_SOURCE
100     # @DEFAULT_UNSET
101     # @DESCRIPTION:
102     # Specify a non-standard Java source version for compilation (via javac -source
103     # parameter or Ant equivalent via build.xml rewriting done by java-ant-2 eclass).
104     # Normally this is determined from the jdk version specified in DEPEND.
105 nichoj 1.1 # See java-pkg_get-source function below.
106     #
107 caster 1.155 # Should generally only be used for testing and debugging.
108 nichoj 1.1 #
109 caster 1.155 # Use 1.4 source to emerge baz
110     # @CODE
111 nichoj 1.1 # JAVA_PKG_WANT_SOURCE=1.4 emerge baz
112 caster 1.155 # @CODE
113 nichoj 1.1
114 caster 1.155 # @ECLASS-VARIABLE: JAVA_PKG_WANT_TARGET
115     # @DEFAULT_UNSET
116     # @DESCRIPTION:
117     # Same as JAVA_PKG_WANT_SOURCE (see above) but for javac -target parameter,
118     # which affects the version of generated bytecode.
119     # Normally this is determined from the jre/jdk version specified in RDEPEND.
120 nichoj 1.1 # See java-pkg_get-target function below.
121     #
122 caster 1.155 # Should generallyonly be used for testing and debugging.
123 nichoj 1.1 #
124 caster 1.155 # emerge bar to be compatible with 1.3
125     # @CODE
126 nichoj 1.1 # JAVA_PKG_WANT_TARGET=1.3 emerge bar
127 caster 1.155 # @CODE
128 nichoj 1.1
129 caster 1.155 # @VARIABLE: JAVA_PKG_COMPILER_DIR
130     # @INTERNAL
131     # @DESCRIPTION:
132 nichoj 1.1 # Directory where compiler settings are saved, without trailing slash.
133 caster 1.155 # You probably shouldn't touch this variable except local testing.
134 nichoj 1.1 JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"}
135    
136 caster 1.155 # @VARIABLE: JAVA_PKG_COMPILERS_CONF
137     # @INTERNAL
138     # @DESCRIPTION:
139 nichoj 1.1 # Path to file containing information about which compiler to use.
140 caster 1.155 # Can be overloaded, but it should be overloaded only for local testing.
141 nichoj 1.1 JAVA_PKG_COMPILERS_CONF=${JAVA_PKG_COMPILERS_CONF:="/etc/java-config-2/build/compilers.conf"}
142    
143 caster 1.155 # @ECLASS-VARIABLE: JAVA_PKG_FORCE_COMPILER
144     # @INTERNAL
145     # @DEFAULT_UNSET
146     # @DESCRIPTION:
147     # Explicitly set a list of compilers to choose from. This is normally read from
148     # JAVA_PKG_COMPILERS_CONF.
149 nichoj 1.1 #
150 caster 1.155 # Useful for local testing.
151 nichoj 1.1 #
152 caster 1.155 # Use jikes and javac, in that order
153     # @CODE
154 nichoj 1.1 # JAVA_PKG_FORCE_COMPILER="jikes javac"
155 caster 1.155 # @CODE
156 nichoj 1.1
157 caster 1.155 # @ECLASS-VARIABLE: JAVA_PKG_FORCE_ANT_TASKS
158     # @DEFAULT_UNSET
159     # @DESCRIPTION:
160 caster 1.46 # An $IFS separated list of ant tasks. Can be set in environment before calling
161     # emerge/ebuild to override variables set in ebuild, mainly for testing before
162     # putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in
163     # eant() call, not the dependencies specified in WANT_ANT_TASKS.
164     #
165 caster 1.155 # @CODE
166     # JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \
167 caster 1.46 # ebuild foo.ebuild compile
168 caster 1.155 # @CODE
169 caster 1.46
170 nichoj 1.1 # TODO document me
171     JAVA_PKG_QA_VIOLATIONS=0
172    
173 caster 1.155 # @FUNCTION: java-pkg_doexamples
174     # @USAGE: [--subdir <subdir>] <file1/dir1> [<file2> ...]
175     # @DESCRIPTION:
176 betelgeuse 1.63 # Installs given arguments to /usr/share/doc/${PF}/examples
177     # If you give it only one parameter and it is a directory it will install
178     # everything in that directory to the examples directory.
179     #
180 caster 1.155 # @CODE
181     # Parameters:
182     # --subdir - If the examples need a certain directory structure
183     # $* - list of files to install
184     #
185     # Examples:
186 betelgeuse 1.63 # java-pkg_doexamples demo
187     # java-pkg_doexamples demo/* examples/*
188 caster 1.155 # @CODE
189 betelgeuse 1.63 java-pkg_doexamples() {
190     debug-print-function ${FUNCNAME} $*
191    
192     [[ ${#} -lt 1 ]] && die "At least one argument needed"
193    
194     java-pkg_check-phase install
195    
196     local dest=/usr/share/doc/${PF}/examples
197 betelgeuse 1.93 if [[ ${1} == --subdir ]]; then
198     local dest=${dest}/${2}
199     dodir ${dest}
200     shift 2
201     fi
202    
203 betelgeuse 1.63 if [[ ${#} = 1 && -d ${1} ]]; then
204 vapier 1.69 ( # dont want to pollute calling env
205     insinto "${dest}"
206     doins -r ${1}/*
207     ) || die "Installing examples failed"
208 betelgeuse 1.63 else
209 vapier 1.69 ( # dont want to pollute calling env
210     insinto "${dest}"
211     doins -r "$@"
212     ) || die "Installing examples failed"
213 betelgeuse 1.63 fi
214 serkan 1.138
215     # Let's make a symlink to the directory we have everything else under
216     dosym "${dest}" "${JAVA_PKG_SHAREPATH}/examples" || die
217 betelgeuse 1.63 }
218 nichoj 1.1
219 caster 1.155 # @FUNCTION: java-pkg_dojar
220     # @USAGE: <jar1> [<jar2> ...]
221     # @DESCRIPTION:
222 nichoj 1.1 # Installs any number of jars.
223     # Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default.
224     # You can use java-pkg_jarinto to change this path.
225 betelgeuse 1.19 # You should never install a jar with a package version in the filename.
226 nichoj 1.1 # Instead, use java-pkg_newjar defined below.
227     #
228 caster 1.155 # @CODE
229 nichoj 1.1 # java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar
230 caster 1.155 # @CODE
231 nichoj 1.1 #
232     # @param $* - list of jars to install
233     java-pkg_dojar() {
234     debug-print-function ${FUNCNAME} $*
235    
236     [[ ${#} -lt 1 ]] && die "At least one argument needed"
237    
238     java-pkg_check-phase install
239     java-pkg_init_paths_
240    
241     # Create JARDEST if it doesn't exist
242     dodir ${JAVA_PKG_JARDEST}
243    
244     local jar
245     # for each jar
246 caster 1.50 for jar in "${@}"; do
247 nichoj 1.1 local jar_basename=$(basename "${jar}")
248    
249     java-pkg_check-versioned-jar ${jar_basename}
250    
251     # check if it exists
252     if [[ -e "${jar}" ]] ; then
253 betelgeuse 1.43 # Don't overwrite if jar has already been installed with the same
254     # name
255     local dest="${D}${JAVA_PKG_JARDEST}/${jar_basename}"
256     if [[ -e "${dest}" ]]; then
257     ewarn "Overwriting ${dest}"
258     fi
259    
260 nichoj 1.1 # install it into JARDEST if it's a non-symlink
261     if [[ ! -L "${jar}" ]] ; then
262 betelgeuse 1.55 #but first check class version when in strict mode.
263     is-java-strict && java-pkg_verify-classes "${jar}"
264    
265 nichoj 1.1 INSDESTTREE="${JAVA_PKG_JARDEST}" \
266     doins "${jar}" || die "failed to install ${jar}"
267     java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
268     debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}"
269     # make a symlink to the original jar if it's symlink
270     else
271     # TODO use dosym, once we find something that could use it
272     # -nichoj
273     ln -s "$(readlink "${jar}")" "${D}${JAVA_PKG_JARDEST}/${jar_basename}"
274     debug-print "${jar} is a symlink, linking accordingly"
275     fi
276     else
277     die "${jar} does not exist"
278     fi
279     done
280    
281     java-pkg_do_write_
282     }
283    
284 caster 1.155 # @FUNCTION: depend-java-query
285     # @INTERNAL
286     # @DESCRIPTION:
287 betelgeuse 1.35 # Wrapper for the depend-java-query binary to enable passing USE in env.
288     # Using env variables keeps this eclass working with java-config versions that
289     # do not handle use flags.
290     depend-java-query() {
291 betelgeuse 1.61 # Used to have a which call here but it caused endless loops for some people
292 betelgeuse 1.62 # that had some weird bashrc voodoo for which.
293 betelgeuse 1.61 USE="${USE}" /usr/bin/depend-java-query "${@}"
294 betelgeuse 1.35 }
295 nichoj 1.1
296 caster 1.155 # @FUNCTION: java-pkg_regjar
297     # @USAGE: </path/to/installed/jar>
298     # @DESCRIPTION:
299     # Records an already installed (in ${D}) jar in the package.env
300 nichoj 1.1 # This would mostly be used if the package has make or a custom script to
301     # install things.
302     #
303 nelchael 1.5 # WARNING:
304 caster 1.155 # if you want to use shell expansion, you have to use ${D}/... as the for in
305     # this function will not be able to expand the path, here's an example:
306 nelchael 1.5 #
307 caster 1.155 # @CODE
308 nelchael 1.5 # java-pkg_regjar ${D}/opt/my-java/lib/*.jar
309 caster 1.155 # @CODE
310 nichoj 1.1 #
311 caster 1.155
312 nichoj 1.10 # TODO should we be making sure the jar is present on ${D} or wherever?
313 nichoj 1.1 java-pkg_regjar() {
314     debug-print-function ${FUNCNAME} $*
315    
316     java-pkg_check-phase install
317    
318     [[ ${#} -lt 1 ]] && die "at least one argument needed"
319    
320     java-pkg_init_paths_
321    
322     local jar jar_dir jar_file
323 caster 1.50 for jar in "${@}"; do
324 nichoj 1.1 # TODO use java-pkg_check-versioned-jar
325 betelgeuse 1.38 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
326     [[ -d "${jar}" || -d "${D}${jar}" ]] \
327     && die "Called ${FUNCNAME} on a directory $*"
328 betelgeuse 1.55
329     #check that class version correct when in strict mode
330     is-java-strict && java-pkg_verify-classes "${jar}"
331    
332 nelchael 1.5 # nelchael: we should strip ${D} in this case too, here's why:
333     # imagine such call:
334     # java-pkg_regjar ${D}/opt/java/*.jar
335     # such call will fall into this case (-e ${jar}) and will
336     # record paths with ${D} in package.env
337     java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
338 nichoj 1.1 else
339 betelgeuse 1.68 if [[ ${jar} = *\** ]]; then
340     eerror "The argument ${jar} to ${FUNCNAME}"
341     eerror "has * in it. If you want it to glob in"
342     eerror '${D} add ${D} to the argument.'
343     fi
344 betelgeuse 1.126 debug-print "${jar} or ${D}${jar} not found"
345 nichoj 1.1 die "${jar} does not exist"
346     fi
347     done
348    
349     java-pkg_do_write_
350     }
351    
352 caster 1.155 # @FUNCTION: java-pkg_newjar
353     # @USAGE: <path/to/oldname.jar> [<newname.jar>]
354     # @DESCRIPTION:
355     # Installs a jar with a new name (defaults to $PN.jar)
356 nichoj 1.1 #
357 caster 1.155 # For example, installs a versioned jar without the version
358 nichoj 1.1 java-pkg_newjar() {
359     debug-print-function ${FUNCNAME} $*
360    
361     local original_jar="${1}"
362     local new_jar="${2:-${PN}.jar}"
363     local new_jar_dest="${T}/${new_jar}"
364    
365     [[ -z ${original_jar} ]] && die "Must specify a jar to install"
366 betelgeuse 1.44 [[ ! -f ${original_jar} ]] \
367     && die "${original_jar} does not exist or is not a file!"
368 nichoj 1.1
369     rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
370     cp "${original_jar}" "${new_jar_dest}" \
371     || die "Failed to copy ${original_jar} to ${new_jar_dest}"
372     java-pkg_dojar "${new_jar_dest}"
373     }
374    
375 caster 1.155 # @FUNCTION: java-pkg_addcp
376     # @USAGE: <classpath>
377     # @DESCRIPTION:
378 nichoj 1.1 # Add something to the package's classpath. For jars, you should use dojar,
379     # newjar, or regjar. This is typically used to add directories to the classpath.
380 caster 1.155 # The parameters of this function are appended to JAVA_PKG_CLASSPATH
381 nichoj 1.1 java-pkg_addcp() {
382     java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
383     java-pkg_do_write_
384     }
385    
386 caster 1.155 # @FUNCTION: java-pkg_doso
387     # @USAGE: <path/to/file1.so> [...]
388     # @DESCRIPTION:
389 nichoj 1.1 # Installs any number of JNI libraries
390     # They will be installed into /usr/lib by default, but java-pkg_sointo
391     # can be used change this path
392     #
393 caster 1.155 # @CODE
394 nichoj 1.1 # Example:
395     # java-pkg_doso *.so
396 caster 1.155 # @CODE
397 nichoj 1.1 java-pkg_doso() {
398     debug-print-function ${FUNCNAME} $*
399    
400     java-pkg_check-phase install
401    
402 caster 1.127 [[ ${#} -lt 1 ]] && die "${FUNCNAME} requires at least one argument"
403 nichoj 1.1
404     java-pkg_init_paths_
405    
406     local lib
407     # for each lib
408     for lib in "$@" ; do
409     # if the lib exists...
410     if [[ -e "${lib}" ]] ; then
411     # install if it isn't a symlink
412     if [[ ! -L "${lib}" ]] ; then
413     INSDESTTREE="${JAVA_PKG_LIBDEST}" \
414     INSOPTIONS="${LIBOPTIONS}" \
415 tove 1.111 doins "${lib}" || die "failed to install ${lib}"
416 nichoj 1.1 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
417     debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
418     # otherwise make a symlink to the symlink's origin
419     else
420 caster 1.127 dosym "$(readlink "${lib}")" "${JAVA_PKG_LIBDEST}/${lib##*/}"
421     debug-print "${lib} is a symlink, linking accordantly"
422 nichoj 1.1 fi
423     # otherwise die
424     else
425     die "${lib} does not exist"
426     fi
427     done
428    
429     java-pkg_do_write_
430     }
431    
432 caster 1.155 # @FUNCTION: java-pkg_regso
433     # @USAGE: <file1.so> [...]
434     # @DESCRIPTION:
435     # Registers an already installed JNI library in package.env.
436     #
437     # @CODE
438     # Parameters:
439     # $@ - JNI libraries to register
440 nichoj 1.1 #
441     # Example:
442     # java-pkg_regso *.so /path/*.so
443 caster 1.155 # @CODE
444 nichoj 1.1 java-pkg_regso() {
445     debug-print-function ${FUNCNAME} $*
446    
447     java-pkg_check-phase install
448    
449 caster 1.127 [[ ${#} -lt 1 ]] && die "${FUNCNAME} requires at least one argument"
450 nichoj 1.1
451     java-pkg_init_paths_
452 betelgeuse 1.19
453 nichoj 1.1 local lib target_dir
454     for lib in "$@" ; do
455     # Check the absolute path of the lib
456     if [[ -e "${lib}" ]] ; then
457     target_dir="$(java-pkg_expand_dir_ ${lib})"
458     java-pkg_append_ JAVA_PKG_LIBRARY "/${target_dir#${D}}"
459     # Check the path of the lib relative to ${D}
460     elif [[ -e "${D}${lib}" ]]; then
461     target_dir="$(java-pkg_expand_dir_ ${D}${lib})"
462     java-pkg_append_ JAVA_PKG_LIBRARY "${target_dir}"
463     else
464     die "${lib} does not exist"
465     fi
466     done
467    
468     java-pkg_do_write_
469     }
470    
471 caster 1.155 # @FUNCTION: java-pkg_jarinto
472     # @USAGE: </path/to/install/jars/into>
473     # @DESCRIPTION:
474     # Changes the path jars are installed into via subsequent java-pkg_dojar calls.
475 nichoj 1.1 java-pkg_jarinto() {
476     debug-print-function ${FUNCNAME} $*
477    
478     JAVA_PKG_JARDEST="${1}"
479     }
480    
481 caster 1.155 # @FUNCTION: java-pkg_sointo
482     # @USAGE: </path/to/install/sofiles/into>
483     # @DESCRIPTION:
484     # Changes the path that JNI libraries are installed into via subsequent
485     # java-pkg_doso calls.
486 nichoj 1.1 java-pkg_sointo() {
487     debug-print-function ${FUNCNAME} $*
488    
489     JAVA_PKG_LIBDEST="${1}"
490     }
491    
492 caster 1.155 # @FUNCTION: java-pkg_dohtml
493     # @USAGE: <path/to/javadoc/documentation> [...]
494     # @DESCRIPTION:
495     # Install Javadoc HTML documentation. Usage of java-pkg_dojavadoc is preferred.
496 nichoj 1.1 #
497 caster 1.155 # @CODE
498 nichoj 1.1 # java-pkg_dohtml dist/docs/
499 caster 1.155 # @CODE
500 nichoj 1.1 java-pkg_dohtml() {
501     debug-print-function ${FUNCNAME} $*
502    
503     [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
504 betelgeuse 1.27
505 betelgeuse 1.31 # from /usr/lib/portage/bin/dohtml -h
506     # -f Set list of allowed extensionless file names.
507 nichoj 1.1 dohtml -f package-list "$@"
508 betelgeuse 1.31
509 nichoj 1.1 # this probably shouldn't be here but it provides
510     # a reasonable way to catch # docs for all of the
511     # old ebuilds.
512     java-pkg_recordjavadoc
513     }
514    
515 caster 1.155 # @FUNCTION: java-pkg_dojavadoc
516     # @USAGE: [--symlink destination] <path/to/javadocs/root>
517     # @DESCRIPTION:
518 betelgeuse 1.30 # Installs javadoc documentation. This should be controlled by the doc use flag.
519     #
520 caster 1.155 # @CODE
521     # Parameters:
522     # $1: optional --symlink creates to symlink like this for html
523 betelgeuse 1.99 # documentation bundles.
524 caster 1.155 # $2: - The javadoc root directory.
525 betelgeuse 1.30 #
526 caster 1.155 # Examples:
527 betelgeuse 1.30 # java-pkg_dojavadoc docs/api
528 caster 1.155 # java-pkg_dojavadoc --symlink apidocs docs/api
529     # @CODE
530 nichoj 1.1 java-pkg_dojavadoc() {
531 betelgeuse 1.74 debug-print-function ${FUNCNAME} $*
532 betelgeuse 1.99
533     # For html documentation bundles that link to Javadoc
534     local symlink
535     if [[ ${1} = --symlink ]]; then
536     symlink=${2}
537     shift 2
538     fi
539    
540 nichoj 1.1 local dir="$1"
541 betelgeuse 1.99 local dest=/usr/share/doc/${PF}/html
542 nichoj 1.1
543 betelgeuse 1.74 # QA checks
544    
545 nichoj 1.1 java-pkg_check-phase install
546    
547     [[ -z "${dir}" ]] && die "Must specify a directory!"
548     [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!"
549 betelgeuse 1.74 if [[ ! -e "${dir}/index.html" ]]; then
550     local msg="No index.html in javadoc directory"
551     ewarn "${msg}"
552     is-java-strict && die "${msg}"
553     fi
554    
555 betelgeuse 1.99 if [[ -e ${D}/${dest}/api ]]; then
556     eerror "${dest} already exists. Will not overwrite."
557     die "${dest}"
558     fi
559    
560 betelgeuse 1.74 # Renaming to match our directory layout
561 nichoj 1.1
562     local dir_to_install="${dir}"
563     if [[ "$(basename "${dir}")" != "api" ]]; then
564     dir_to_install="${T}/api"
565     # TODO use doins
566     cp -r "${dir}" "${dir_to_install}" || die "cp failed"
567     fi
568    
569 betelgeuse 1.74 # Actual installation
570    
571 betelgeuse 1.99 java-pkg_dohtml -r "${dir_to_install}"
572    
573     # Let's make a symlink to the directory we have everything else under
574 betelgeuse 1.100 dosym ${dest}/api "${JAVA_PKG_SHAREPATH}/api" || die
575 betelgeuse 1.99
576     if [[ ${symlink} ]]; then
577 betelgeuse 1.106 debug-print "symlinking ${dest}/{api,${symlink}}"
578 betelgeuse 1.99 dosym ${dest}/{api,${symlink}} || die
579     fi
580 nichoj 1.1 }
581    
582 caster 1.155 # @FUNCTION: java-pkg_dosrc
583     # @USAGE: <path/to/sources> [...]
584     # @DESCRIPTION:
585 betelgeuse 1.19 # Installs a zip containing the source for a package, so it can used in
586 nichoj 1.1 # from IDEs like eclipse and netbeans.
587 caster 1.155 # Ebuild needs to DEPEND on app-arch/zip to use this. It also should be controlled by USE=source.
588 nichoj 1.1 #
589 caster 1.155 # @CODE
590     # Example:
591     # java-pkg_dosrc src/*
592     # @CODE
593    
594     # TODO change so it the arguments it takes are the base directories containing
595     # source -nichoj
596 nichoj 1.1 #
597 caster 1.155 # TODO should we be able to handle multiple calls to dosrc? -nichoj
598 nichoj 1.1 #
599 caster 1.155 # TODO maybe we can take an existing zip/jar? -nichoj
600 nichoj 1.1 #
601     # FIXME apparently this fails if you give it an empty directories
602     java-pkg_dosrc() {
603     debug-print-function ${FUNCNAME} $*
604    
605 betelgeuse 1.19 [ ${#} -lt 1 ] && die "At least one argument needed"
606 nichoj 1.1
607     java-pkg_check-phase install
608    
609 betelgeuse 1.19 [[ ${#} -lt 1 ]] && die "At least one argument needed"
610 nichoj 1.1
611 betelgeuse 1.66 if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
612     local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
613 betelgeuse 1.104 java-pkg_announce-qa-violation ${msg}
614 betelgeuse 1.66 fi
615    
616 nichoj 1.1 java-pkg_init_paths_
617    
618     local zip_name="${PN}-src.zip"
619     local zip_path="${T}/${zip_name}"
620     local dir
621 caster 1.50 for dir in "${@}"; do
622 nichoj 1.1 local dir_parent=$(dirname "${dir}")
623     local dir_name=$(basename "${dir}")
624     pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
625     zip -q -r ${zip_path} ${dir_name} -i '*.java'
626     local result=$?
627     # 12 means zip has nothing to do
628     if [[ ${result} != 12 && ${result} != 0 ]]; then
629     die "failed to zip ${dir_name}"
630     fi
631     popd >/dev/null
632     done
633    
634     # Install the zip
635     INSDESTTREE=${JAVA_PKG_SOURCESPATH} \
636     doins ${zip_path} || die "Failed to install source"
637    
638     JAVA_SOURCES="${JAVA_PKG_SOURCESPATH}/${zip_name}"
639     java-pkg_do_write_
640     }
641    
642 caster 1.155 # @FUNCTION: java-pkg_dolauncher
643     # @USAGE: <filename> [options]
644     # @DESCRIPTION:
645 nichoj 1.1 # Make a wrapper script to lauch/start this package
646     # If necessary, the wrapper will switch to the appropriate VM.
647     #
648 betelgeuse 1.25 # Can be called without parameters if the package installs only one jar
649     # that has the Main-class attribute set. The wrapper will be named ${PN}.
650     #
651 caster 1.155 # @CODE
652     # Parameters:
653     # $1 - filename of launcher to create
654     # $2 - options, as follows:
655     # --main the.main.class.to.start
656 betelgeuse 1.25 # --jar /the/jar/too/launch.jar or just <name>.jar
657 betelgeuse 1.20 # --java_args 'Extra arguments to pass to java'
658 caster 1.42 # --pkg_args 'Extra arguments to pass to the package'
659     # --pwd Directory the launcher changes to before executing java
660     # -into Directory to install the launcher to, instead of /usr/bin
661     # -pre Prepend contents of this file to the launcher
662 caster 1.155 # @CODE
663 nichoj 1.1 java-pkg_dolauncher() {
664     debug-print-function ${FUNCNAME} $*
665    
666     java-pkg_check-phase install
667 betelgeuse 1.25 java-pkg_init_paths_
668 nichoj 1.1
669 betelgeuse 1.25 if [[ ${#} = 0 ]]; then
670     local name="${PN}"
671     else
672     local name="${1}"
673     shift
674     fi
675 nichoj 1.1
676     # TODO rename to launcher
677     local target="${T}/${name}"
678 betelgeuse 1.20 local var_tmp="${T}/launcher_variables_tmp"
679 nichoj 1.1 local target_dir pre
680    
681 betelgeuse 1.20 # Process the other the rest of the arguments
682 nichoj 1.1 while [[ -n "${1}" && -n "${2}" ]]; do
683 betelgeuse 1.38 local var="${1}" value="${2}"
684 betelgeuse 1.19 if [[ "${var:0:2}" == "--" ]]; then
685 betelgeuse 1.25 local var=${var:2}
686     echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
687 betelgeuse 1.26 local gjl_${var}="${value}"
688 nichoj 1.1 elif [[ "${var}" == "-into" ]]; then
689     target_dir="${value}"
690     elif [[ "${var}" == "-pre" ]]; then
691     pre="${value}"
692     fi
693     shift 2
694     done
695 betelgeuse 1.20
696 betelgeuse 1.25 # Test if no --jar and --main arguments were given and
697     # in that case check if the package only installs one jar
698     # and use that jar.
699     if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
700     local cp="${JAVA_PKG_CLASSPATH}"
701     if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
702     echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
703     else
704     local msg="Not enough information to create a launcher given."
705     msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
706     die "${msg}"
707     fi
708     fi
709    
710 betelgeuse 1.20 # Write the actual script
711     echo "#!/bin/bash" > "${target}"
712 caster 1.42 if [[ -n "${pre}" ]]; then
713     if [[ -f "${pre}" ]]; then
714     cat "${pre}" >> "${target}"
715     else
716     die "-pre specified file '${pre}' does not exist"
717     fi
718     fi
719 nichoj 1.1 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
720 betelgeuse 1.20 cat "${var_tmp}" >> "${target}"
721 caster 1.21 rm -f "${var_tmp}"
722 nichoj 1.1 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
723 betelgeuse 1.19
724 nichoj 1.17 if [[ -n "${target_dir}" ]]; then
725 nichoj 1.1 DESTTREE="${target_dir}" dobin "${target}"
726     local ret=$?
727     return ${ret}
728     else
729     dobin "${target}"
730     fi
731     }
732    
733 caster 1.155 # @FUNCTION: java-pkg_dowar
734     # @DESCRIPTION:
735 nichoj 1.1 # Install war files.
736     # TODO document
737     java-pkg_dowar() {
738     debug-print-function ${FUNCNAME} $*
739    
740     # Check for arguments
741     [[ ${#} -lt 1 ]] && die "At least one argument needed"
742     java-pkg_check-phase install
743    
744     java-pkg_init_paths_
745    
746     local war
747     for war in $* ; do
748     local warpath
749     # TODO evaluate if we want to handle symlinks differently -nichoj
750     # Check for symlink
751     if [[ -L "${war}" ]] ; then
752     cp "${war}" "${T}"
753     warpath="${T}$(basename "${war}")"
754     # Check for directory
755     # TODO evaluate if we want to handle directories differently -nichoj
756     elif [[ -d "${war}" ]] ; then
757     echo "dowar: warning, skipping directory ${war}"
758     continue
759     else
760     warpath="${war}"
761     fi
762 betelgeuse 1.18
763 nichoj 1.1 # Install those files like you mean it
764     INSOPTIONS="-m 0644" \
765     INSDESTTREE=${JAVA_PKG_WARDEST} \
766     doins ${warpath}
767     done
768     }
769    
770 caster 1.155 # @FUNCTION: java-pkg_recordjavadoc
771     # @INTERNAL
772     # @DESCRIPTION:
773 nichoj 1.1 # Scan for JavaDocs, and record their existence in the package.env file
774 caster 1.155
775 nichoj 1.1 # TODO make sure this in the proper section
776     java-pkg_recordjavadoc()
777     {
778     debug-print-function ${FUNCNAME} $*
779     # the find statement is important
780     # as some packages include multiple trees of javadoc
781     JAVADOC_PATH="$(find ${D}/usr/share/doc/ -name allclasses-frame.html -printf '%h:')"
782     # remove $D - TODO: check this is ok with all cases of the above
783     JAVADOC_PATH="${JAVADOC_PATH//${D}}"
784     if [[ -n "${JAVADOC_PATH}" ]] ; then
785     debug-print "javadocs found in ${JAVADOC_PATH%:}"
786     java-pkg_do_write_
787     else
788     debug-print "No javadocs found"
789     fi
790     }
791    
792    
793 caster 1.155 # @FUNCTION: java-pkg_jar-from
794     # @USAGE: [--build-only] [--with-dependencies] [--virtual] [--into dir] <package> [<package.jar>] [<destination.jar>]
795     # @DESCRIPTION:
796 nichoj 1.1 # Makes a symlink to a jar from a certain package
797     # A lot of java packages include dependencies in a lib/ directory
798     # You can use this function to replace these bundled dependencies.
799 nichoj 1.16 # The dependency is recorded into package.env DEPEND line, unless "--build-only"
800     # is passed as the very first argument, for jars that have to be present only
801     # at build time and are not needed on runtime (junit testing etc).
802 nichoj 1.1 #
803 caster 1.155 # @CODE
804 nichoj 1.1 # Example: get all jars from xerces slot 2
805     # java-pkg_jar-from xerces-2
806 caster 1.155 #
807 nichoj 1.1 # Example: get a specific jar from xerces slot 2
808     # java-pkg_jar-from xerces-2 xml-apis.jar
809 caster 1.155 #
810 nichoj 1.16 # Example: get a specific jar from xerces slot 2, and name it diffrently
811 nichoj 1.1 # java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
812 caster 1.155 #
813 nichoj 1.16 # Example: get junit.jar which is needed only for building
814     # java-pkg_jar-from --build-only junit junit.jar
815 caster 1.155 # @CODE
816 nichoj 1.1 #
817 caster 1.155 # @CODE
818     # Parameters
819 caster 1.49 # --build-only - makes the jar(s) not added into package.env DEPEND line.
820     # (assumed automatically when called inside src_test)
821     # --with-dependencies - get jars also from requested package's dependencies
822     # transitively.
823 ali_bush 1.94 # --virtual - Packages passed to this function are to be handled as virtuals
824     # and will not have individual jar dependencies recorded.
825 caster 1.49 # --into $dir - symlink jar(s) into $dir (must exist) instead of .
826 caster 1.155 # $1 - Package to get jars from, or comma-separated list of packages in
827 caster 1.79 # case other parameters are not used.
828 caster 1.155 # $2 - jar from package. If not specified, all jars will be used.
829     # $3 - When a single jar is specified, destination filename of the
830 nichoj 1.1 # symlink. Defaults to the name of the jar.
831 caster 1.155 # @CODE
832    
833 nichoj 1.1 # TODO could probably be cleaned up a little
834     java-pkg_jar-from() {
835     debug-print-function ${FUNCNAME} $*
836    
837 nichoj 1.16 local build_only=""
838 caster 1.49 local destdir="."
839     local deep=""
840 ali_bush 1.94 local virtual=""
841 ali_bush 1.129 local record_jar=""
842 betelgeuse 1.59
843 caster 1.78 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
844 nichoj 1.16
845 caster 1.49 while [[ "${1}" == --* ]]; do
846     if [[ "${1}" = "--build-only" ]]; then
847 caster 1.77 build_only="build"
848 caster 1.49 elif [[ "${1}" = "--with-dependencies" ]]; then
849     deep="--with-dependencies"
850 ali_bush 1.94 elif [[ "${1}" = "--virtual" ]]; then
851     virtual="true"
852 caster 1.49 elif [[ "${1}" = "--into" ]]; then
853     destdir="${2}"
854     shift
855     else
856     die "java-pkg_jar-from called with unknown parameter: ${1}"
857     fi
858 nichoj 1.16 shift
859 caster 1.49 done
860 betelgeuse 1.43
861 betelgeuse 1.18 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
862    
863 nichoj 1.1 [[ -z ${target_pkg} ]] && die "Must specify a package"
864    
865 ali_bush 1.105 if [[ "${EAPI}" == "1" ]]; then
866     target_pkg="${target_pkg//:/-}"
867     fi
868    
869 nichoj 1.1 # default destjar to the target jar
870     [[ -z "${destjar}" ]] && destjar="${target_jar}"
871    
872 betelgeuse 1.18 local error_msg="There was a problem getting the classpath for ${target_pkg}."
873     local classpath
874 betelgeuse 1.43 classpath="$(java-config ${deep} --classpath=${target_pkg})"
875 betelgeuse 1.18 [[ $? != 0 ]] && die ${error_msg}
876 nichoj 1.1
877 betelgeuse 1.60 # When we have commas this functions is called to bring jars from multiple
878 caster 1.79 # packages. This affects recording of dependencencies performed later
879     # which expects one package only, so we do it here.
880 betelgeuse 1.60 if [[ ${target_pkg} = *,* ]]; then
881 caster 1.79 for pkg in ${target_pkg//,/ }; do
882     java-pkg_ensure-dep "${build_only}" "${pkg}"
883     [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
884     done
885     # setting this disables further record-jar_ calls later
886 ali_bush 1.129 record_jar="true"
887 caster 1.79 else
888     java-pkg_ensure-dep "${build_only}" "${target_pkg}"
889 betelgeuse 1.60 fi
890    
891 ali_bush 1.94 # Record the entire virtual as a dependency so that
892     # no jars are missed.
893     if [[ -z "${build_only}" && -n "${virtual}" ]]; then
894     java-pkg_record-jar_ "${target_pkg}"
895     # setting this disables further record-jars_ calls later
896 ali_bush 1.129 record_jar="true"
897 ali_bush 1.94 fi
898    
899 caster 1.79 pushd ${destdir} > /dev/null \
900     || die "failed to change directory to ${destdir}"
901    
902 nichoj 1.1 local jar
903     for jar in ${classpath//:/ }; do
904     local jar_name=$(basename "${jar}")
905     if [[ ! -f "${jar}" ]] ; then
906     debug-print "${jar} from ${target_pkg} does not exist"
907     die "Installation problems with jars in ${target_pkg} - is it installed?"
908     fi
909     # If no specific target jar was indicated, link it
910     if [[ -z "${target_jar}" ]] ; then
911     [[ -f "${target_jar}" ]] && rm "${target_jar}"
912     ln -snf "${jar}" \
913     || die "Failed to make symlink from ${jar} to ${jar_name}"
914 ali_bush 1.129 if [[ -z "${record_jar}" ]]; then
915     if [[ -z "${build_only}" ]]; then
916     java-pkg_record-jar_ "${target_pkg}" "${jar}"
917     else
918     java-pkg_record-jar_ --build-only "${target_pkg}" "${jar}"
919     fi
920     fi
921     # otherwise, if the current jar is the target jar, link it
922 nichoj 1.1 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
923     [[ -f "${destjar}" ]] && rm "${destjar}"
924     ln -snf "${jar}" "${destjar}" \
925     || die "Failed to make symlink from ${jar} to ${destjar}"
926 ali_bush 1.129 if [[ -z "${record_jar}" ]]; then
927     if [[ -z "${build_only}" ]]; then
928     java-pkg_record-jar_ "${target_pkg}" "${jar}"
929     else
930     java-pkg_record-jar_ --build-only "${target_jar}" "${jar}"
931     fi
932     fi
933 betelgeuse 1.54 popd > /dev/null
934 nichoj 1.1 return 0
935     fi
936     done
937 caster 1.49 popd > /dev/null
938 nichoj 1.1 # if no target was specified, we're ok
939     if [[ -z "${target_jar}" ]] ; then
940     return 0
941     # otherwise, die bitterly
942     else
943     die "Failed to find ${target_jar:-jar} in ${target_pkg}"
944     fi
945     }
946    
947 caster 1.155 # @FUNCTION: java-pkg_jarfrom
948     # @DESCRIPTION:
949 nichoj 1.1 # See java-pkg_jar-from
950     java-pkg_jarfrom() {
951     java-pkg_jar-from "$@"
952     }
953    
954 caster 1.155 # @FUNCTION: java-pkg_getjars
955     # @USAGE: [--build-only] [--with-dependencies] <package1>[,<package2>...]
956     # @DESCRIPTION:
957 nichoj 1.1 # Get the classpath provided by any number of packages
958     # Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
959 nichoj 1.16 # The providing packages are recorded as dependencies into package.env DEPEND
960     # line, unless "--build-only" is passed as the very first argument, for jars
961     # that have to be present only at build time and are not needed on runtime
962     # (junit testing etc).
963 betelgeuse 1.19 #
964 caster 1.155 # @CODE
965 betelgeuse 1.30 # Example: Get the classpath for xerces-2 and xalan,
966     # java-pkg_getjars xerces-2,xalan
967 caster 1.155 #
968 nichoj 1.1 # Example Return:
969     # /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
970 betelgeuse 1.19 #
971 caster 1.155 #
972     # Parameters:
973 caster 1.49 # --build-only - makes the jar(s) not added into package.env DEPEND line.
974     # (assumed automatically when called inside src_test)
975     # --with-dependencies - get jars also from requested package's dependencies
976     # transitively.
977 caster 1.155 # $1 - list of packages to get jars from
978 betelgeuse 1.30 # (passed to java-config --classpath)
979 caster 1.155 # @CODE
980 nichoj 1.1 java-pkg_getjars() {
981     debug-print-function ${FUNCNAME} $*
982    
983 caster 1.49 local build_only=""
984     local deep=""
985 betelgeuse 1.59
986 caster 1.78 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
987 nichoj 1.16
988 caster 1.49 while [[ "${1}" == --* ]]; do
989     if [[ "${1}" = "--build-only" ]]; then
990 caster 1.77 build_only="build"
991 caster 1.49 elif [[ "${1}" = "--with-dependencies" ]]; then
992     deep="--with-dependencies"
993     else
994     die "java-pkg_jar-from called with unknown parameter: ${1}"
995     fi
996 betelgeuse 1.43 shift
997 caster 1.49 done
998 betelgeuse 1.43
999 caster 1.49 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
1000 betelgeuse 1.38
1001 ali_bush 1.70
1002 betelgeuse 1.106 local pkgs="${1}"
1003 ali_bush 1.105
1004     if [[ "${EAPI}" == "1" ]]; then
1005     pkgs="${pkgs//:/-}"
1006     fi
1007    
1008 betelgeuse 1.43 jars="$(java-config ${deep} --classpath=${pkgs})"
1009 betelgeuse 1.106 [[ $? != 0 ]] && die "java-config --classpath=${pkgs} failed"
1010 betelgeuse 1.30 debug-print "${pkgs}:${jars}"
1011    
1012 betelgeuse 1.73 for pkg in ${pkgs//,/ }; do
1013 ali_bush 1.70 java-pkg_ensure-dep "${build_only}" "${pkg}"
1014     done
1015    
1016 ali_bush 1.129 for pkg in ${pkgs//,/ }; do
1017     if [[ -z "${build_only}" ]]; then
1018 betelgeuse 1.30 java-pkg_record-jar_ "${pkg}"
1019 ali_bush 1.129 else
1020     java-pkg_record-jar_ --build-only "${pkg}"
1021     fi
1022     done
1023 betelgeuse 1.18
1024 betelgeuse 1.106 echo "${jars}"
1025 nichoj 1.1 }
1026    
1027 caster 1.155 # @FUNCTION: java-pkg_getjar
1028     # @USAGE: [--build-only] [--virtual] <package> <jarfile>
1029     # @DESCRIPTION:
1030     # Get the complete path of a single jar from a package
1031 nichoj 1.16 # The providing package is recorded as runtime dependency into package.env
1032     # DEPEND line, unless "--build-only" is passed as the very first argument, for
1033     # jars that have to be present only at build time and are not needed on runtime
1034     # (junit testing etc).
1035 nichoj 1.1 #
1036 caster 1.155 # @CODE
1037     # Example:
1038 nichoj 1.1 # java-pkg_getjar xerces-2 xml-apis.jar
1039 caster 1.155 # returns
1040 nichoj 1.1 # /usr/share/xerces-2/lib/xml-apis.jar
1041 betelgeuse 1.19 #
1042 caster 1.155 # Parameters:
1043 caster 1.49 # --build-only - makes the jar not added into package.env DEPEND line.
1044 ali_bush 1.94 # --virtual - Packages passed to this function are to be handled as virtuals
1045     # and will not have individual jar dependencies recorded.
1046 caster 1.155 # $1 - package to use
1047     # $2 - jar to get
1048     # @CODE
1049 nichoj 1.1 java-pkg_getjar() {
1050     debug-print-function ${FUNCNAME} $*
1051    
1052 nichoj 1.16 local build_only=""
1053 ali_bush 1.94 local virtual=""
1054 ali_bush 1.129 local record_jar=""
1055 betelgeuse 1.59
1056 caster 1.78 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1057 nichoj 1.16
1058 caster 1.49 while [[ "${1}" == --* ]]; do
1059     if [[ "${1}" = "--build-only" ]]; then
1060 caster 1.77 build_only="build"
1061 caster 1.101 elif [[ "${1}" == "--virtual" ]]; then
1062 ali_bush 1.94 virtual="true"
1063 caster 1.49 else
1064 caster 1.102 die "java-pkg_getjar called with unknown parameter: ${1}"
1065 caster 1.49 fi
1066 nichoj 1.16 shift
1067 caster 1.49 done
1068    
1069     [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
1070 nichoj 1.16
1071 nichoj 1.1 local pkg="${1}" target_jar="${2}" jar
1072 ali_bush 1.105
1073     if [[ "${EAPI}" == "1" ]]; then
1074     pkg="${pkg//:/-}"
1075     fi
1076    
1077 nichoj 1.1 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
1078     [[ -z ${target_jar} ]] && die "Must specify jar to get"
1079    
1080 betelgeuse 1.18 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
1081     local classpath
1082     classpath=$(java-config --classpath=${pkg})
1083     [[ $? != 0 ]] && die ${error_msg}
1084    
1085 ali_bush 1.70 java-pkg_ensure-dep "${build_only}" "${pkg}"
1086    
1087 ali_bush 1.94 # Record the package(Virtual) as a dependency and then set build_only
1088     # So that individual jars are not recorded.
1089     if [[ -n "${virtual}" ]]; then
1090 ali_bush 1.129 if [[ -z "${build_only}" ]]; then
1091     java-pkg_record-jar_ "${pkg}"
1092     else
1093     java-pkg_record-jar_ --build-only "${pkg}"
1094     fi
1095     record_jar="true"
1096 ali_bush 1.94 fi
1097    
1098 nichoj 1.1 for jar in ${classpath//:/ }; do
1099     if [[ ! -f "${jar}" ]] ; then
1100 nichoj 1.16 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
1101 nichoj 1.1 fi
1102    
1103     if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
1104 nichoj 1.16 # Only record jars that aren't build-only
1105 ali_bush 1.129 if [[ -z "${record_jar}" ]]; then
1106     if [[ -z "${build_only}" ]]; then
1107     java-pkg_record-jar_ "${pkg}" "${jar}"
1108     else
1109     java-pkg_record-jar_ --build-only "${pkg}" "${jar}"
1110     fi
1111     fi
1112 nichoj 1.1 echo "${jar}"
1113     return 0
1114     fi
1115     done
1116 betelgeuse 1.19
1117 nichoj 1.1 die "Could not find ${target_jar} in ${pkg}"
1118     return 1
1119     }
1120    
1121 caster 1.155 # @FUNCTION: java-pkg_register-dependency
1122     # @USAGE: <package>[,<package2>...] [<jarfile>]
1123     # @DESCRIPTION:
1124 caster 1.77 # Registers runtime dependency on a package, list of packages, or a single jar
1125     # from a package, into package.env DEPEND line. Can only be called in
1126     # src_install phase.
1127     # Intended for binary packages where you don't need to symlink the jars or get
1128     # their classpath during build. As such, the dependencies only need to be
1129     # specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1130     #
1131 caster 1.155 # @CODE
1132     # Parameters:
1133     # $1 - comma-separated list of packages, or a single package
1134     # $2 - if param $1 is a single package, optionally specify the jar
1135 caster 1.77 # to depend on
1136     #
1137 caster 1.155 # Examples:
1138     # Record the dependency on whole xerces-2 and xalan,
1139 caster 1.77 # java-pkg_register-dependency xerces-2,xalan
1140 caster 1.155 #
1141     # Record the dependency on ant.jar from ant-core
1142 caster 1.77 # java-pkg_register-dependency ant-core ant.jar
1143 caster 1.155 # @CODE
1144 caster 1.77 #
1145     # Note: Passing both list of packages as the first parameter AND specifying the
1146     # jar as the second is not allowed and will cause the function to die. We assume
1147     # that there's more chance one passes such combination as a mistake, than that
1148     # there are more packages providing identically named jar without class
1149     # collisions.
1150     java-pkg_register-dependency() {
1151     debug-print-function ${FUNCNAME} $*
1152    
1153     java-pkg_check-phase install
1154    
1155     [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1156    
1157     local pkgs="${1}"
1158     local jar="${2}"
1159    
1160     [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1161    
1162 ali_bush 1.105 if [[ "${EAPI}" == "1" ]]; then
1163     pkgs="${pkgs//:/-}"
1164     fi
1165    
1166 caster 1.77 if [[ -z "${jar}" ]]; then
1167     for pkg in ${pkgs//,/ }; do
1168     java-pkg_ensure-dep runtime "${pkg}"
1169     java-pkg_record-jar_ "${pkg}"
1170     done
1171     else
1172     [[ ${pkgs} == *,* ]] && \
1173     die "${FUNCNAME} called with both package list and jar name"
1174     java-pkg_ensure-dep runtime "${pkgs}"
1175     java-pkg_record-jar_ "${pkgs}" "${jar}"
1176     fi
1177    
1178 caster 1.85 java-pkg_do_write_
1179     }
1180    
1181 caster 1.155 # @FUNCTION: java-pkg_register-optional-dependency
1182     # @USAGE: <package>[,<package2>...] [<jarfile>]
1183     # @DESCRIPTION:
1184 caster 1.88 # Registers optional runtime dependency on a package, list of packages, or a
1185     # single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be
1186     # called in src_install phase.
1187     # Intended for packages that can use other packages when those are in classpath.
1188     # Will be put on classpath by launcher if they are installed. Typical case is
1189     # JDBC implementations for various databases. It's better than having USE flag
1190     # for each implementation triggering hard dependency.
1191     #
1192 caster 1.155 # @CODE
1193     # Parameters:
1194     # $1 - comma-separated list of packages, or a single package
1195     # $2 - if param $1 is a single package, optionally specify the jar to depend on
1196 caster 1.88 #
1197 caster 1.155 # Example:
1198     # Record the optional dependency on some jdbc providers
1199 caster 1.88 # java-pkg_register-optional-dependency jdbc-jaybird,jtds-1.2,jdbc-mysql
1200 caster 1.155 # @CODE
1201 caster 1.88 #
1202     # Note: Passing both list of packages as the first parameter AND specifying the
1203     # jar as the second is not allowed and will cause the function to die. We assume
1204     # that there's more chance one passes such combination as a mistake, than that
1205     # there are more packages providing identically named jar without class
1206     # collisions.
1207     java-pkg_register-optional-dependency() {
1208     debug-print-function ${FUNCNAME} $*
1209    
1210     java-pkg_check-phase install
1211    
1212     [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1213    
1214     local pkgs="${1}"
1215     local jar="${2}"
1216    
1217     [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1218    
1219 ali_bush 1.105 if [[ "${EAPI}" == "1" ]]; then
1220     pkgs="${pkgs//:/-}"
1221     fi
1222    
1223 caster 1.88 if [[ -z "${jar}" ]]; then
1224     for pkg in ${pkgs//,/ }; do
1225     java-pkg_record-jar_ --optional "${pkg}"
1226     done
1227     else
1228     [[ ${pkgs} == *,* ]] && \
1229     die "${FUNCNAME} called with both package list and jar name"
1230     java-pkg_record-jar_ --optional "${pkgs}" "${jar}"
1231     fi
1232    
1233     java-pkg_do_write_
1234     }
1235    
1236 caster 1.155 # @FUNCTION: java-pkg_register-environment-variable
1237     # @USAGE: <name> <value>
1238     # @DESCRIPTION:
1239 caster 1.85 # Register an arbitrary environment variable into package.env. The gjl launcher
1240     # for this package or any package depending on this will export it into
1241     # environement before executing java command.
1242     # Must only be called in src_install phase.
1243     JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
1244     JAVA_PKG_EXTRA_ENV_VARS=""
1245     java-pkg_register-environment-variable() {
1246     debug-print-function ${FUNCNAME} $*
1247    
1248     java-pkg_check-phase install
1249    
1250     [[ ${#} != 2 ]] && die "${FUNCNAME} takes two arguments"
1251    
1252     echo "${1}=\"${2}\"" >> ${JAVA_PKG_EXTRA_ENV}
1253     JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
1254    
1255     java-pkg_do_write_
1256 caster 1.77 }
1257    
1258 caster 1.155 # @FUNCTION: java-pkg_get-bootclasspath
1259     # @USAGE: <version>
1260     # @DESCRIPTION:
1261 caster 1.132 # Returns classpath of a given bootclasspath-providing package version.
1262     #
1263     # @param $1 - the version of bootclasspath (e.g. 1.5), 'auto' for bootclasspath
1264     # of the current JDK
1265     java-pkg_get-bootclasspath() {
1266     local version="${1}"
1267    
1268     local bcp
1269 vapier 1.142 case "${version}" in
1270 caster 1.132 auto)
1271     bcp="$(java-config -g BOOTCLASSPATH)"
1272     ;;
1273     1.5)
1274     bcp="$(java-pkg_getjars --build-only gnu-classpath-0.98)"
1275     ;;
1276     *)
1277     eerror "unknown parameter of java-pkg_get-bootclasspath"
1278     die "unknown parameter of java-pkg_get-bootclasspath"
1279     ;;
1280     esac
1281    
1282     echo "${bcp}"
1283     }
1284    
1285    
1286 nichoj 1.1 # This function reads stdin, and based on that input, figures out how to
1287     # populate jars from the filesystem.
1288     # Need to figure out a good way of making use of this, ie be able to use a
1289     # string that was built instead of stdin
1290     # NOTE: this isn't quite ready for primetime.
1291     #java-pkg_populate-jars() {
1292     # local line
1293     #
1294     # read line
1295     # while [[ -n "${line}" ]]; do
1296     # # Ignore comments
1297     # [[ ${line%%#*} == "" ]] && continue
1298     #
1299     # # get rid of any spaces
1300     # line="${line// /}"
1301     #
1302     # # format: path=jarinfo
1303     # local path=${line%%=*}
1304     # local jarinfo=${line##*=}
1305 betelgeuse 1.19 #
1306 nichoj 1.1 # # format: jar@package
1307     # local jar=${jarinfo%%@*}.jar
1308     # local package=${jarinfo##*@}
1309     # if [[ -n ${replace_only} ]]; then
1310     # [[ ! -f $path ]] && die "No jar exists at ${path}"
1311     # fi
1312     # if [[ -n ${create_parent} ]]; then
1313     # local parent=$(dirname ${path})
1314     # mkdir -p "${parent}"
1315     # fi
1316     # java-pkg_jar-from "${package}" "${jar}" "${path}"
1317     #
1318     # read line
1319     # done
1320     #}
1321    
1322 caster 1.155 # @FUNCTION: java-pkg_find-normal-jars
1323     # @USAGE: [<path/to/directory>]
1324     # @DESCRIPTION:
1325     # Find the files with suffix .jar file in the given directory (default: $WORKDIR)
1326 betelgeuse 1.40 java-pkg_find-normal-jars() {
1327     local dir=$1
1328     [[ "${dir}" ]] || dir="${WORKDIR}"
1329     local found
1330     for jar in $(find "${dir}" -name "*.jar" -type f); do
1331     echo "${jar}"
1332     found="true"
1333     done
1334     [[ "${found}" ]]
1335     return $?
1336     }
1337    
1338 caster 1.155 # @FUNCTION: java-pkg_ensure-no-bundled-jars
1339     # @DESCRIPTION:
1340 betelgeuse 1.40 # Try to locate bundled jar files in ${WORKDIR} and die if found.
1341     # This function should be called after WORKDIR has been populated with symlink
1342     # to system jar files or bundled jars removed.
1343 nichoj 1.1 java-pkg_ensure-no-bundled-jars() {
1344     debug-print-function ${FUNCNAME} $*
1345    
1346 betelgeuse 1.40 local bundled_jars=$(java-pkg_find-normal-jars)
1347 nichoj 1.1 if [[ -n ${bundled_jars} ]]; then
1348     echo "Bundled jars found:"
1349     local jar
1350     for jar in ${bundled_jars}; do
1351     echo $(pwd)${jar/./}
1352     done
1353     die "Bundled jars found!"
1354     fi
1355     }
1356    
1357 caster 1.155 # @FUNCTION: java-pkg_ensure-vm-version-sufficient
1358     # @INTERNAL
1359     # @DESCRIPTION:
1360 nichoj 1.1 # Checks if we have a sufficient VM and dies if we don't.
1361     java-pkg_ensure-vm-version-sufficient() {
1362     debug-print-function ${FUNCNAME} $*
1363    
1364     if ! java-pkg_is-vm-version-sufficient; then
1365     debug-print "VM is not suffient"
1366     eerror "Current Java VM cannot build this package"
1367     einfo "Please use java-config -S to set the correct one"
1368     die "Active Java VM cannot build this package"
1369     fi
1370     }
1371    
1372 caster 1.155 # @FUNCTION: java-pkg_is-vm-version-sufficient
1373     # @INTERNAL
1374     # @DESCRIPTION:
1375     # @RETURN: zero - VM is sufficient; non-zero - VM is not sufficient
1376 nichoj 1.1 java-pkg_is-vm-version-sufficient() {
1377     debug-print-function ${FUNCNAME} $*
1378    
1379     depend-java-query --is-sufficient "${DEPEND}" > /dev/null
1380     return $?
1381     }
1382    
1383 caster 1.155 # @FUNCTION: java-pkg_ensure-vm-version-eq
1384     # @INTERNAL
1385     # @DESCRIPTION:
1386 nichoj 1.1 # Die if the current VM is not equal to the argument passed.
1387     #
1388     # @param $@ - Desired VM version to ensure
1389     java-pkg_ensure-vm-version-eq() {
1390     debug-print-function ${FUNCNAME} $*
1391    
1392     if ! java-pkg_is-vm-version-eq $@ ; then
1393     debug-print "VM is not suffient"
1394     eerror "This package requires a Java VM version = $@"
1395     einfo "Please use java-config -S to set the correct one"
1396     die "Active Java VM too old"
1397     fi
1398     }
1399    
1400 caster 1.155 # @FUNCTION: java-pkg_is-vm-version-eq
1401     # @USAGE: <version>
1402     # @INTERNAL
1403     # @RETURN: zero - VM versions are equal; non-zero - VM version are not equal
1404 nichoj 1.1 java-pkg_is-vm-version-eq() {
1405     debug-print-function ${FUNCNAME} $*
1406    
1407     local needed_version="$@"
1408    
1409     [[ -z "${needed_version}" ]] && die "need an argument"
1410    
1411     local vm_version="$(java-pkg_get-vm-version)"
1412    
1413     vm_version="$(get_version_component_range 1-2 "${vm_version}")"
1414     needed_version="$(get_version_component_range 1-2 "${needed_version}")"
1415    
1416     if [[ -z "${vm_version}" ]]; then
1417     debug-print "Could not get JDK version from DEPEND"
1418     return 1
1419     else
1420     if [[ "${vm_version}" == "${needed_version}" ]]; then
1421     debug-print "Detected a JDK(${vm_version}) = ${needed_version}"
1422     return 0
1423     else
1424     debug-print "Detected a JDK(${vm_version}) != ${needed_version}"
1425     return 1
1426     fi
1427     fi
1428     }
1429    
1430 caster 1.155 # @FUNCTION: java-pkg_ensure-vm-version-ge
1431     # @INTERNAL
1432     # @DESCRIPTION:
1433 nichoj 1.1 # Die if the current VM is not greater than the desired version
1434     #
1435     # @param $@ - VM version to compare current to
1436     java-pkg_ensure-vm-version-ge() {
1437     debug-print-function ${FUNCNAME} $*
1438 betelgeuse 1.19
1439 nichoj 1.1 if ! java-pkg_is-vm-version-ge "$@" ; then
1440     debug-print "vm is not suffient"
1441     eerror "This package requires a Java VM version >= $@"
1442     einfo "Please use java-config -S to set the correct one"
1443     die "Active Java VM too old"
1444     fi
1445     }
1446    
1447 caster 1.155 # @FUNCTION: java-pkg_is-vm-version-ge
1448     # @INTERNAL
1449     # @DESCRIPTION:
1450     # @CODE
1451     # Parameters:
1452     # $@ - VM version to compare current VM to
1453     # @CODE
1454     # @RETURN: zero - current VM version is greater than checked version;
1455     # non-zero - current VM version is not greater than checked version
1456 nichoj 1.1 java-pkg_is-vm-version-ge() {
1457     debug-print-function ${FUNCNAME} $*
1458    
1459     local needed_version=$@
1460     local vm_version=$(java-pkg_get-vm-version)
1461     if [[ -z "${vm_version}" ]]; then
1462     debug-print "Could not get JDK version from DEPEND"
1463     return 1
1464     else
1465     if version_is_at_least "${needed_version}" "${vm_version}"; then
1466     debug-print "Detected a JDK(${vm_version}) >= ${needed_version}"
1467     return 0
1468     else
1469     debug-print "Detected a JDK(${vm_version}) < ${needed_version}"
1470     return 1
1471     fi
1472     fi
1473     }
1474    
1475 nichoj 1.12 java-pkg_set-current-vm() {
1476     export GENTOO_VM=${1}
1477     }
1478    
1479     java-pkg_get-current-vm() {
1480     echo ${GENTOO_VM}
1481     }
1482    
1483     java-pkg_current-vm-matches() {
1484 ssuominen 1.141 has $(java-pkg_get-current-vm) ${@}
1485 nichoj 1.12 return $?
1486     }
1487    
1488 caster 1.155 # @FUNCTION: java-pkg_get-source
1489     # @DESCRIPTION:
1490 nichoj 1.1 # Determines what source version should be used, for passing to -source.
1491     # Unless you want to break things you probably shouldn't set _WANT_SOURCE
1492     #
1493 caster 1.155 # @RETURN: string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1494 nichoj 1.1 java-pkg_get-source() {
1495     echo ${JAVA_PKG_WANT_SOURCE:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1496     }
1497    
1498 caster 1.155 # @FUNCTION: java-pkg_get-target
1499     # @DESCRIPTION:
1500 nichoj 1.1 # Determines what target version should be used, for passing to -target.
1501     # If you don't care about lower versions, you can set _WANT_TARGET to the
1502 betelgeuse 1.19 # version of your JDK.
1503 nichoj 1.1 #
1504 caster 1.155 # @RETURN: string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1505 nichoj 1.1 java-pkg_get-target() {
1506 caster 1.37 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1507 nichoj 1.1 }
1508    
1509 caster 1.155 # @FUNCTION: java-pkg_get-javac
1510     # @DESCRIPTION:
1511     # Returns the compiler executable
1512 nichoj 1.1 java-pkg_get-javac() {
1513     debug-print-function ${FUNCNAME} $*
1514    
1515 caster 1.24
1516 nichoj 1.1 local compiler="${GENTOO_COMPILER}"
1517    
1518     local compiler_executable
1519     if [[ "${compiler}" = "javac" ]]; then
1520     # nothing fancy needs to be done for javac
1521     compiler_executable="javac"
1522     else
1523     # for everything else, try to determine from an env file
1524    
1525     local compiler_env="/usr/share/java-config-2/compiler/${compiler}"
1526     if [[ -f ${compiler_env} ]]; then
1527     local old_javac=${JAVAC}
1528     unset JAVAC
1529     # try to get value of JAVAC
1530     compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1531     export JAVAC=${old_javac}
1532    
1533 caster 1.24 if [[ -z ${compiler_executable} ]]; then
1534     echo "JAVAC is empty or undefined in ${compiler_env}"
1535     return 1
1536     fi
1537 betelgeuse 1.19
1538 nichoj 1.1 # check that it's executable
1539     if [[ ! -x ${compiler_executable} ]]; then
1540 caster 1.24 echo "${compiler_executable} doesn't exist, or isn't executable"
1541     return 1
1542 nichoj 1.1 fi
1543     else
1544 caster 1.24 echo "Could not find environment file for ${compiler}"
1545     return 1
1546 nichoj 1.1 fi
1547     fi
1548     echo ${compiler_executable}
1549     }
1550    
1551 caster 1.155 # @FUNCTION: java-pkg_javac-args
1552     # @DESCRIPTION:
1553 nichoj 1.1 # If an ebuild uses javac directly, instead of using ejavac, it should call this
1554     # to know what -source/-target to use.
1555     #
1556 caster 1.155 # @RETURN: string - arguments to pass to javac, complete with -target and -source
1557 nichoj 1.1 java-pkg_javac-args() {
1558     debug-print-function ${FUNCNAME} $*
1559    
1560     local want_source="$(java-pkg_get-source)"
1561     local want_target="$(java-pkg_get-target)"
1562    
1563 betelgeuse 1.19 local source_str="-source ${want_source}"
1564 nichoj 1.1 local target_str="-target ${want_target}"
1565    
1566     debug-print "want source: ${want_source}"
1567     debug-print "want target: ${want_target}"
1568    
1569     if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1570 caster 1.24 debug-print "could not find valid -source/-target values for javac"
1571     echo "Could not find valid -source/-target values for javac"
1572     return 1
1573 nichoj 1.1 else
1574     if java-pkg_is-vm-version-ge "1.4"; then
1575     echo "${source_str} ${target_str}"
1576     else
1577     echo "${target_str}"
1578     fi
1579     fi
1580     }
1581    
1582 caster 1.155 # @FUNCTION: java-pkg_get-jni-cflags
1583     # @DESCRIPTION:
1584     # Echos the CFLAGS for JNI compilations
1585 nichoj 1.1 java-pkg_get-jni-cflags() {
1586     local flags="-I${JAVA_HOME}/include"
1587    
1588 flameeyes 1.33 local platform="linux"
1589     use elibc_FreeBSD && platform="freebsd"
1590    
1591 nichoj 1.10 # TODO do a check that the directories are valid
1592 flameeyes 1.33 flags="${flags} -I${JAVA_HOME}/include/${platform}"
1593 nichoj 1.1
1594     echo ${flags}
1595     }
1596    
1597 nichoj 1.10 java-pkg_ensure-gcj() {
1598 sera 1.151 # was enforcing sys-devel/gcc[gcj]
1599     die "${FUNCNAME} was removed. Use use-deps available as of EAPI 2 instead. #261562"
1600 nichoj 1.10 }
1601    
1602 nichoj 1.13 java-pkg_ensure-test() {
1603 sera 1.151 # was enforcing USE=test if FEATURES=test
1604     die "${FUNCNAME} was removed. Package mangers handle this already. #278965"
1605 nichoj 1.13 }
1606    
1607 caster 1.155 # @FUNCTION: java-pkg_register-ant-task
1608     # @USAGE: [--version x.y] [<name>]
1609     # @DESCRIPTION:
1610 caster 1.46 # Register this package as ant task, so that ant will load it when no specific
1611     # ANT_TASKS are specified. Note that even without this registering, all packages
1612     # specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1613     # packages, but can be also used by other ebuilds that used to symlink their
1614     # .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1615     # compatibility.
1616     #
1617 caster 1.155 # @CODE
1618     # Parameters
1619     # --version x.y Register only for ant version x.y (otherwise for any ant
1620 caster 1.46 # version). Used by the ant-* packages to prevent loading of mismatched
1621     # ant-core ant tasks after core was updated, before the tasks are updated,
1622     # without a need for blockers.
1623 caster 1.155 # $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1624     # @CODE
1625 caster 1.46 java-pkg_register-ant-task() {
1626     local TASKS_DIR="tasks"
1627    
1628     # check for --version x.y parameters
1629     while [[ -n "${1}" && -n "${2}" ]]; do
1630     local var="${1#--}"
1631     local val="${2}"
1632     if [[ "${var}" == "version" ]]; then
1633     TASKS_DIR="tasks-${val}"
1634     else
1635     die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1636     fi
1637     shift 2
1638     done
1639    
1640     local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1641    
1642     dodir /usr/share/ant/${TASKS_DIR}
1643     touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1644     }
1645    
1646 caster 1.155 # @FUNCTION: java-pkg_ant-tasks-depend
1647     # @INTERNAL
1648     # @DESCRIPTION:
1649 caster 1.46 # Translates the WANT_ANT_TASKS variable into valid dependencies.
1650     java-pkg_ant-tasks-depend() {
1651     debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1652    
1653     if [[ -n "${WANT_ANT_TASKS}" ]]; then
1654     local DEP=""
1655     for i in ${WANT_ANT_TASKS}
1656     do
1657 betelgeuse 1.110 if [[ ${i} = ant-* ]]; then
1658     DEP="${DEP}dev-java/${i} "
1659     elif [[ ${i} = */*:* ]]; then
1660     DEP="${DEP}${i} "
1661     else
1662 caster 1.46 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1663     return 1
1664     fi
1665     done
1666     echo ${DEP}
1667     return 0
1668     else
1669     return 0
1670     fi
1671     }
1672    
1673 serkan 1.136
1674 caster 1.155 # @FUNCTION: ejunit_
1675     # @INTERNAL
1676     # @DESCRIPTION:
1677 serkan 1.136 # Internal Junit wrapper function. Makes it easier to run the tests and checks for
1678 betelgeuse 1.84 # dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner.
1679 caster 1.155 # @CODE
1680     # Parameters:
1681     # $1 - junit package (junit or junit-4)
1682     # $2 - -cp or -classpath
1683     # $3 - classpath; junit and recorded dependencies get appended
1684     # $@ - the rest of the parameters are passed to java
1685     # @CODE
1686 serkan 1.136 ejunit_() {
1687 betelgeuse 1.84 debug-print-function ${FUNCNAME} $*
1688    
1689 betelgeuse 1.87 local pkgs
1690 betelgeuse 1.106 if [[ -f ${JAVA_PKG_DEPEND_FILE} ]]; then
1691     for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
1692     pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
1693     done
1694     fi
1695 betelgeuse 1.87
1696 serkan 1.136 local junit=${1}
1697     shift 1
1698    
1699     local cp=$(java-pkg_getjars --with-dependencies ${junit}${pkgs})
1700 betelgeuse 1.84 if [[ ${1} = -cp || ${1} = -classpath ]]; then
1701 betelgeuse 1.87 cp="${2}:${cp}"
1702 betelgeuse 1.84 shift 2
1703     else
1704 betelgeuse 1.87 cp=".:${cp}"
1705 betelgeuse 1.84 fi
1706    
1707     local runner=junit.textui.TestRunner
1708 serkan 1.138 if [[ "${junit}" == "junit-4" ]] ; then
1709     runner=org.junit.runner.JUnitCore
1710     fi
1711 betelgeuse 1.84 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}"
1712     java -cp "${cp}" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
1713     }
1714    
1715 caster 1.155 # @FUNCTION: ejunit
1716     # @DESCRIPTION:
1717 serkan 1.136 # Junit wrapper function. Makes it easier to run the tests and checks for
1718 serkan 1.139 # dev-java/junit in DEPEND. Launches the tests using org.junit.runner.JUnitCore.
1719 serkan 1.136 #
1720 caster 1.155 # @CODE
1721     # Parameters:
1722     # $1 - -cp or -classpath
1723     # $2 - classpath; junit and recorded dependencies get appended
1724     # $@ - the rest of the parameters are passed to java
1725     #
1726 serkan 1.136 # Examples:
1727     # ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1728     # ejunit org.blinkenlights.jid3.test.AllTests
1729 caster 1.155 # ejunit org.blinkenlights.jid3.test.FirstTest org.blinkenlights.jid3.test.SecondTest
1730     # @CODE
1731 serkan 1.136 ejunit() {
1732     debug-print-function ${FUNCNAME} $*
1733    
1734     ejunit_ "junit" "${@}"
1735     }
1736    
1737 caster 1.155 # @FUNCTION: ejunit4
1738     # @DESCRIPTION:
1739 serkan 1.136 # Junit4 wrapper function. Makes it easier to run the tests and checks for
1740     # dev-java/junit:4 in DEPEND. Launches the tests using junit.textui.TestRunner.
1741     #
1742 caster 1.155 # @CODE
1743     # Parameters:
1744     # $1 - -cp or -classpath
1745     # $2 - classpath; junit and recorded dependencies get appended
1746     # $@ - the rest of the parameters are passed to java
1747     #
1748 serkan 1.136 # Examples:
1749 serkan 1.137 # ejunit4 -cp build/classes org.blinkenlights.jid3.test.AllTests
1750     # ejunit4 org.blinkenlights.jid3.test.AllTests
1751 serkan 1.138 # ejunit4 org.blinkenlights.jid3.test.FirstTest \
1752     # org.blinkenlights.jid3.test.SecondTest
1753 caster 1.155 # @CODE
1754 serkan 1.136 ejunit4() {
1755     debug-print-function ${FUNCNAME} $*
1756    
1757     ejunit_ "junit-4" "${@}"
1758     }
1759    
1760 caster 1.155 # @FUNCTION: java-utils-2_src_prepare
1761     # @DESCRIPTION:
1762 betelgeuse 1.113 # src_prepare Searches for bundled jars
1763 caster 1.117 # Don't call directly, but via java-pkg-2_src_prepare!
1764 betelgeuse 1.113 java-utils-2_src_prepare() {
1765 betelgeuse 1.125 [[ ${EBUILD_PHASE} == prepare ]] &&
1766     java-pkg_func-exists java_prepare && java_prepare
1767    
1768 betelgeuse 1.113 # Remember that eant will call this unless called via Portage
1769     if [[ ! -e "${T}/java-utils-2_src_prepare-run" ]] && is-java-strict; then
1770     echo "Searching for bundled jars:"
1771     java-pkg_find-normal-jars || echo "None found."
1772     echo "Searching for bundled classes (no output if none found):"
1773     find "${WORKDIR}" -name "*.class"
1774     echo "Search done."
1775     fi
1776     touch "${T}/java-utils-2_src_prepare-run"
1777     }
1778    
1779 caster 1.155 # @FUNCTION: java-utils-2_pkg_preinst
1780     # @DESCRIPTION:
1781 serkan 1.122 # pkg_preinst Searches for missing and unneeded dependencies
1782     # Don't call directly, but via java-pkg-2_pkg_preinst!
1783     java-utils-2_pkg_preinst() {
1784     if is-java-strict; then
1785     if has_version dev-java/java-dep-check; then
1786     [[ -e "${JAVA_PKG_ENV}" ]] || return
1787     local output=$(GENTOO_VM= java-dep-check --image "${D}" "${JAVA_PKG_ENV}")
1788     if [[ ${output} && has_version <=dev-java/java-dep-check-0.2 ]]; then
1789     ewarn "Possibly unneeded dependencies found in package.env:"
1790     for dep in ${output}; do
1791     ewarn "\t${dep}"
1792     done
1793     fi
1794     if [[ ${output} && has_version >dev-java/java-dep-check-0.2 ]]; then
1795     ewarn "${output}"
1796     fi
1797     else
1798     eerror "Install dev-java/java-dep-check for dependency checking"
1799     fi
1800     fi
1801     }
1802    
1803 caster 1.155 # @FUNCTION: eant
1804     # @USAGE: <ant_build_target(s)>
1805     # @DESCRIPTION:
1806 nichoj 1.1 # Ant wrapper function. Will use the appropriate compiler, based on user-defined
1807 caster 1.46 # compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1808 betelgeuse 1.41 # variables:
1809 caster 1.155 #
1810     # @CODE
1811     # Variables:
1812 betelgeuse 1.41 # EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1813 caster 1.155 # gentoo.classpath property. Be sure to call java-ant_rewrite-classpath in src_unpack.
1814 caster 1.120 # EANT_NEEDS_TOOLS - add tools.jar to the gentoo.classpath. Should only be used
1815 caster 1.155 # for build-time purposes, the dependency is not recorded to
1816     # package.env!
1817     # ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1818     # @CODE
1819 nichoj 1.1 eant() {
1820     debug-print-function ${FUNCNAME} $*
1821    
1822 betelgeuse 1.92 if [[ ${EBUILD_PHASE} = compile ]]; then
1823 betelgeuse 1.113 java-ant-2_src_configure
1824     java-utils-2_src_prepare
1825 betelgeuse 1.92 fi
1826    
1827 ssuominen 1.141 if ! has java-ant-2 ${INHERITED}; then
1828 betelgeuse 1.52 local msg="You should inherit java-ant-2 when using eant"
1829 caster 1.82 java-pkg_announce-qa-violation "${msg}"
1830 betelgeuse 1.51 fi
1831    
1832 caster 1.96 local antflags="-Dnoget=true -Dmaven.mode.offline=true -Dbuild.sysclasspath=ignore"
1833 betelgeuse 1.57
1834 nichoj 1.1 java-pkg_init-compiler_
1835     local compiler="${GENTOO_COMPILER}"
1836    
1837     local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1838     local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})"
1839     if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1840     die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1841     fi
1842    
1843     if [[ ${compiler} != "javac" ]]; then
1844 caster 1.36 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1845 nichoj 1.1 # Figure out any extra stuff to put on the classpath for compilers aside
1846     # from javac
1847     # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1848     # java-config -p
1849     local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})"
1850     if [[ -n ${build_compiler_deps} ]]; then
1851     antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1852     fi
1853     fi
1854 nichoj 1.9
1855 betelgeuse 1.52 for arg in "${@}"; do
1856     if [[ ${arg} = -lib ]]; then
1857     if is-java-strict; then
1858     eerror "You should not use the -lib argument to eant because it will fail"
1859 betelgeuse 1.53 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1860 betelgeuse 1.52 eerror "or ant properties to make dependencies available."
1861     eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1862     eerror "split ant (>=dev-java/ant-core-1.7)."
1863     die "eant -lib is deprecated/forbidden"
1864     else
1865     echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1866     echo "more info."
1867     fi
1868     fi
1869     done
1870    
1871 betelgeuse 1.110 # parse WANT_ANT_TASKS for atoms
1872     local want_ant_tasks
1873     for i in ${WANT_ANT_TASKS}; do
1874     if [[ ${i} = */*:* ]]; then
1875     i=${i#*/}
1876     i=${i%:0}
1877     want_ant_tasks+="${i/:/-} "
1878     else
1879     want_ant_tasks+="${i} "
1880     fi
1881     done
1882 caster 1.103 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1883 betelgeuse 1.110 ANT_TASKS="${ANT_TASKS:-${want_ant_tasks% }}"
1884 caster 1.46
1885 caster 1.103 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1886     ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1887 caster 1.46
1888 caster 1.103 # if ant-tasks is not set by ebuild or forced, use none
1889     ANT_TASKS="${ANT_TASKS:-none}"
1890 betelgeuse 1.52
1891 caster 1.103 # at this point, ANT_TASKS should be "all", "none" or explicit list
1892     if [[ "${ANT_TASKS}" == "all" ]]; then
1893     einfo "Using all available ANT_TASKS"
1894     elif [[ "${ANT_TASKS}" == "none" ]]; then
1895     einfo "Disabling all optional ANT_TASKS"
1896     else
1897     einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1898 caster 1.46 fi
1899    
1900 caster 1.103 export ANT_TASKS
1901    
1902 caster 1.46 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1903 betelgeuse 1.45 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1904 betelgeuse 1.19
1905 betelgeuse 1.41 local gcp="${EANT_GENTOO_CLASSPATH}"
1906 caster 1.76 local getjarsarg=""
1907 betelgeuse 1.41
1908 betelgeuse 1.57 if [[ ${EBUILD_PHASE} = "test" ]]; then
1909     antflags="${antflags} -DJunit.present=true"
1910 betelgeuse 1.109 [[ ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1911 caster 1.76 getjarsarg="--with-dependencies"
1912 caster 1.147 else
1913     antflags="${antflags} -Dmaven.test.skip=true"
1914 betelgeuse 1.57 fi
1915    
1916     local cp
1917    
1918     for atom in ${gcp}; do
1919 betelgeuse 1.75 cp="${cp}:$(java-pkg_getjars ${getjarsarg} ${atom})"
1920 betelgeuse 1.57 done
1921    
1922 caster 1.120 [[ -n "${EANT_NEEDS_TOOLS}" ]] && cp="${cp}:$(java-config --tools)"
1923    
1924 betelgeuse 1.57 if [[ ${cp} ]]; then
1925 betelgeuse 1.41 # It seems ant does not like single quotes around ${cp}
1926 betelgeuse 1.112 cp=${cp#:}
1927     [[ ${EANT_GENTOO_CLASSPATH_EXTRA} ]] && \
1928     cp="${cp}:${EANT_GENTOO_CLASSPATH_EXTRA}"
1929     antflags="${antflags} -Dgentoo.classpath=\"${cp}\""
1930 betelgeuse 1.41 fi
1931    
1932 nichoj 1.1 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1933 betelgeuse 1.75 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
1934 nichoj 1.1 ant ${antflags} "${@}" || die "eant failed"
1935     }
1936    
1937 caster 1.155 # @FUNCTION: ejavac
1938     # @USAGE: <javac_arguments>
1939     # @DESCRIPTION:
1940 betelgeuse 1.19 # Javac wrapper function. Will use the appropriate compiler, based on
1941 nichoj 1.1 # /etc/java-config/compilers.conf
1942     ejavac() {
1943     debug-print-function ${FUNCNAME} $*
1944    
1945 caster 1.24 java-pkg_init-compiler_
1946 nichoj 1.1
1947 caster 1.24 local compiler_executable
1948     compiler_executable=$(java-pkg_get-javac)
1949     if [[ ${?} != 0 ]]; then
1950     eerror "There was a problem determining compiler: ${compiler_executable}"
1951     die "get-javac failed"
1952     fi
1953    
1954     local javac_args
1955     javac_args="$(java-pkg_javac-args)"
1956     if [[ ${?} != 0 ]]; then
1957     eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
1958     die "java-pkg_javac-args failed"
1959     fi
1960    
1961     [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1962     ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1963 nichoj 1.1 }
1964    
1965 caster 1.155 # @FUNCTION: java-pkg_filter-compiler
1966     # @USAGE: <compiler(s)_to_filter>
1967     # @DESCRIPTION:
1968 nichoj 1.1 # Used to prevent the use of some compilers. Should be used in src_compile.
1969     # Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
1970     java-pkg_filter-compiler() {
1971     JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@"
1972     }
1973    
1974 caster 1.155 # @FUNCTION: java-pkg_force-compiler
1975     # @USAGE: <compiler(s)_to_force>
1976     # @DESCRIPTION:
1977 nichoj 1.8 # Used to force the use of particular compilers. Should be used in src_compile.
1978     # A common use of this would be to force ecj-3.1 to be used on amd64, to avoid
1979     # OutOfMemoryErrors that may come up.
1980     java-pkg_force-compiler() {
1981     JAVA_PKG_FORCE_COMPILER="$@"
1982     }
1983    
1984 caster 1.155 # @FUNCTION: use_doc
1985     # @DESCRIPTION:
1986 nichoj 1.1 #
1987     # Helper function for getting ant to build javadocs. If the user has USE=doc,
1988     # then 'javadoc' or the argument are returned. Otherwise, there is no return.
1989 betelgeuse 1.19 #
1990 nichoj 1.1 # The output of this should be passed to ant.
1991 caster 1.155 # @CODE
1992     # Parameters:
1993     # $@ - Option value to return. Defaults to 'javadoc'
1994 nichoj 1.1 #
1995 caster 1.155 # Examples:
1996     # build javadocs by calling 'javadoc' target
1997 nichoj 1.1 # eant $(use_doc)
1998 caster 1.155 #
1999     # build javadocs by calling 'apidoc' target
2000 nichoj 1.1 # eant $(use_doc apidoc)
2001 caster 1.155 # @CODE
2002     # @RETURN string - Name of the target to create javadocs
2003 nichoj 1.1 use_doc() {
2004     use doc && echo ${@:-javadoc}
2005     }
2006    
2007 betelgeuse 1.38
2008 caster 1.155 # @FUNCTION: java-pkg_init
2009     # @INTERNAL
2010     # @DESCRIPTION:
2011 nichoj 1.1 # The purpose of this function, as the name might imply, is to initialize the
2012     # Java environment. It ensures that that there aren't any environment variables
2013     # that'll muss things up. It initializes some variables, which are used
2014     # internally. And most importantly, it'll switch the VM if necessary.
2015     #
2016     # This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will
2017     # call it during each of the phases of the merge process.
2018     java-pkg_init() {
2019 betelgeuse 1.97 debug-print-function ${FUNCNAME} $*
2020 sera 1.148
2021     # Don't set up build environment if installing from binary. #206024 #258423
2022     [[ "${MERGE_TYPE}" == "binary" ]] && return
2023     # Also try Portage's nonstandard EMERGE_FROM for old EAPIs, if it doesn't
2024     # work nothing is lost.
2025     has ${EAPI:-0} 0 1 2 3 && [[ "${EMERGE_FROM}" == "binary" ]] && return
2026    
2027 nichoj 1.1 unset JAVAC
2028     unset JAVA_HOME
2029 betelgeuse 1.64
2030 betelgeuse 1.116 java-config --help >/dev/null || {
2031     eerror ""
2032     eerror "Can't run java-config --help"
2033     eerror "Have you upgraded python recently but haven't"
2034     eerror "run python-updater yet?"
2035     die "Can't run java-config --help"
2036     }
2037    
2038 betelgeuse 1.64 # People do all kinds of weird things.
2039     # http://forums.gentoo.org/viewtopic-p-3943166.html
2040 betelgeuse 1.65 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
2041 betelgeuse 1.64 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
2042 betelgeuse 1.65 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
2043 betelgeuse 1.64 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
2044     ewarn "sun-jdk vms and and as such break configure scripts that"
2045     ewarn "use it (for example app-office/openoffice) so we filter it out."
2046     ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
2047     ewarn "make.conf for example) to silence this warning or"
2048     ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
2049     fi
2050    
2051     if [[ -z ${accept} ]]; then
2052 betelgeuse 1.98 # export _JAVA_OPTIONS= doesn't work because it will show up in java
2053     # -version output
2054     unset _JAVA_OPTIONS
2055 betelgeuse 1.64 # phase hooks make this run many times without this
2056     I_WANT_GLOBAL_JAVA_OPTIONS="true"
2057     fi
2058    
2059 betelgeuse 1.92 if java-pkg_func-exists ant_src_unpack; then
2060     java-pkg_announce-qa-violation "Using old ant_src_unpack. Should be src_unpack"
2061     fi
2062    
2063 nichoj 1.1 java-pkg_init_paths_
2064     java-pkg_switch-vm
2065     PATH=${JAVA_HOME}/bin:${PATH}
2066    
2067     # TODO we will probably want to set JAVAC and JAVACFLAGS
2068    
2069     # Do some QA checks
2070     java-pkg_check-jikes
2071    
2072 betelgeuse 1.97 # Can't use unset here because Portage does not save the unset
2073     # see https://bugs.gentoo.org/show_bug.cgi?id=189417#c11
2074    
2075 betelgeuse 1.19 # When users have crazy classpaths some packages can fail to compile.
2076 nichoj 1.1 # and everything should work with empty CLASSPATH.
2077     # This also helps prevent unexpected dependencies on random things
2078     # from the CLASSPATH.
2079 betelgeuse 1.97 export CLASSPATH=
2080 betelgeuse 1.59
2081 caster 1.46 # Unset external ANT_ stuff
2082 betelgeuse 1.97 export ANT_TASKS=
2083     export ANT_OPTS=
2084 caster 1.118 export ANT_RESPECT_JAVA_HOME=
2085 nichoj 1.1 }
2086    
2087 caster 1.155 # @FUNCTION: java-pkg-init-compiler_
2088     # @INTERNAL
2089     # @DESCRIPTION:
2090 nichoj 1.1 # This function attempts to figure out what compiler should be used. It does
2091 betelgeuse 1.19 # this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
2092 nichoj 1.1 # COMPILERS variable defined there.
2093     # This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
2094 betelgeuse 1.19 #
2095 nichoj 1.1 # It will go through the list of compilers, and verify that it supports the
2096     # target and source that are needed. If it is not suitable, then the next
2097     # compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
2098     # isn't done.
2099     #
2100     # Once the which compiler to use has been figured out, it is set to
2101     # GENTOO_COMPILER.
2102     #
2103     # If you hadn't guessed, JAVA_PKG_FORCE_COMPILER is for testing only.
2104     #
2105     # If the user doesn't defined anything in JAVA_PKG_COMPILERS_CONF, or no
2106     # suitable compiler was found there, then the default is to use javac provided
2107     # by the current VM.
2108     #
2109     #
2110 caster 1.155 # @RETURN name of the compiler to use
2111 nichoj 1.1 java-pkg_init-compiler_() {
2112     debug-print-function ${FUNCNAME} $*
2113    
2114     if [[ -n ${GENTOO_COMPILER} ]]; then
2115     debug-print "GENTOO_COMPILER already set"
2116     return
2117     fi
2118    
2119 nichoj 1.3 local compilers;
2120     if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
2121     compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
2122     else
2123     compilers=${JAVA_PKG_FORCE_COMPILER}
2124     fi
2125 betelgeuse 1.19
2126 nichoj 1.1 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
2127    
2128     # Figure out if we should announce what compiler we're using
2129     local compiler
2130     for compiler in ${compilers}; do
2131     debug-print "Checking ${compiler}..."
2132     # javac should always be alright
2133     if [[ ${compiler} = "javac" ]]; then
2134     debug-print "Found javac... breaking"
2135     export GENTOO_COMPILER="javac"
2136     break
2137     fi
2138 betelgeuse 1.19
2139 nichoj 1.1 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
2140     if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
2141     einfo "Filtering ${compiler}"
2142     continue
2143     fi
2144     fi
2145 betelgeuse 1.19
2146 nichoj 1.1 # for non-javac, we need to make sure it supports the right target and
2147     # source
2148     local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
2149     if [[ -f ${compiler_env} ]]; then
2150     local desired_target="$(java-pkg_get-target)"
2151     local desired_source="$(java-pkg_get-source)"
2152    
2153    
2154     # Verify that the compiler supports target
2155     local supported_target=$(source ${compiler_env} 1>/dev/null 2>&1; echo ${SUPPORTED_TARGET})
2156     if ! has ${desired_target} ${supported_target}; then
2157     ewarn "${compiler} does not support -target ${desired_target}, skipping"
2158     continue
2159     fi
2160    
2161     # -source was introduced in 1.3, so only check 1.3 and on
2162     if version_is_at_least "${desired_soure}" "1.3"; then
2163     # Verify that the compiler supports source
2164     local supported_source=$(source ${compiler_env} 1>/dev/null 2>&1; echo ${SUPPORTED_SOURCE})
2165     if ! has ${desired_source} ${supported_source}; then
2166     ewarn "${compiler} does not support -source ${desired_source}, skipping"
2167     continue
2168     fi
2169     fi
2170    
2171     # if you get here, then the compiler should be good to go
2172     export GENTOO_COMPILER="${compiler}"
2173     break
2174     else
2175     ewarn "Could not find configuration for ${compiler}, skipping"
2176     ewarn "Perhaps it is not installed?"
2177     continue
2178     fi
2179     done
2180    
2181     # If it hasn't been defined already, default to javac
2182     if [[ -z ${GENTOO_COMPILER} ]]; then
2183     if [[ -n ${compilers} ]]; then
2184 betelgeuse 1.104 einfo "No suitable compiler found: defaulting to JDK default for compilation"
2185 nichoj 1.1 else
2186     # probably don't need to notify users about the default.
2187     :;#einfo "Defaulting to javac for compilation"
2188     fi
2189 betelgeuse 1.104 if java-config -g GENTOO_COMPILER 2> /dev/null; then
2190     export GENTOO_COMPILER=$(java-config -g GENTOO_COMPILER)
2191     else
2192     export GENTOO_COMPILER=javac
2193     fi
2194 nichoj 1.1 else
2195     einfo "Using ${GENTOO_COMPILER} for compilation"
2196     fi
2197    
2198     }
2199    
2200 caster 1.155 # @FUNCTION: init_paths_
2201     # @INTERNAL
2202     # @DESCRIPTION:
2203 nichoj 1.1 # Initializes some variables that will be used. These variables are mostly used
2204     # to determine where things will eventually get installed.
2205     java-pkg_init_paths_() {
2206     debug-print-function ${FUNCNAME} $*
2207    
2208     local pkg_name
2209 radhermit 1.154 if [[ "${SLOT%/*}" == "0" ]] ; then
2210 nichoj 1.1 JAVA_PKG_NAME="${PN}"
2211     else
2212 radhermit 1.154 JAVA_PKG_NAME="${PN}-${SLOT%/*}"
2213 nichoj 1.1 fi
2214    
2215     JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}"
2216     JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/"
2217     JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env"
2218 ali_bush 1.94 JAVA_PKG_VIRTUALS_PATH="${DESTTREE}/share/java-config-2/virtuals"
2219     JAVA_PKG_VIRTUAL_PROVIDER="${D}/${JAVA_PKG_VIRTUALS_PATH}/${JAVA_PKG_NAME}"
2220 nichoj 1.1
2221     [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib"
2222     [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}"
2223     [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps"
2224    
2225    
2226     # TODO maybe only print once?
2227     debug-print "JAVA_PKG_SHAREPATH: ${JAVA_PKG_SHAREPATH}"
2228     debug-print "JAVA_PKG_ENV: ${JAVA_PKG_ENV}"
2229     debug-print "JAVA_PKG_JARDEST: ${JAVA_PKG_JARDEST}"
2230     debug-print "JAVA_PKG_LIBDEST: ${JAVA_PKG_LIBDEST}"
2231     debug-print "JAVA_PKG_WARDEST: ${JAVA_PKG_WARDEST}"
2232     }
2233    
2234 caster 1.155 # @FUNCTION: java-pkg_do_write_
2235     # @INTERNAL
2236     # @DESCRIPTION:
2237 nichoj 1.1 # Writes the package.env out to disk.
2238     #
2239     # TODO change to do-write, to match everything else
2240     java-pkg_do_write_() {
2241 betelgeuse 1.87 debug-print-function ${FUNCNAME} $*
2242 betelgeuse 1.28 java-pkg_init_paths_
2243 nichoj 1.1 # Create directory for package.env
2244     dodir "${JAVA_PKG_SHAREPATH}"
2245 betelgeuse 1.87 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f \
2246 caster 1.88 "${JAVA_PKG_DEPEND_FILE}" || -f \
2247     "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]]; then
2248 nichoj 1.1 # Create package.env
2249     (
2250     echo "DESCRIPTION=\"${DESCRIPTION}\""
2251     echo "GENERATION=\"2\""
2252 betelgeuse 1.104 echo "SLOT=\"${SLOT}\""
2253 ali_bush 1.129 echo "CATEGORY=\"${CATEGORY}\""
2254     echo "PVR=\"${PVR}\""
2255 nichoj 1.1
2256     [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
2257     [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
2258     [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
2259 betelgeuse 1.87 [[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
2260 betelgeuse 1.133 && echo "DEPEND=\"$(sort -u "${JAVA_PKG_DEPEND_FILE}" | tr '\n' ':')\""
2261 caster 1.88 [[ -f "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]] \
2262 betelgeuse 1.133 && echo "OPTIONAL_DEPEND=\"$(sort -u "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" | tr '\n' ':')\""
2263 nichoj 1.1 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
2264 ali_bush 1.129 [[ -f "${JAVA_PKG_BUILD_DEPEND_FILE}" ]] \
2265 betelgeuse 1.133 && echo "BUILD_DEPEND=\"$(sort -u "${JAVA_PKG_BUILD_DEPEND_FILE}" | tr '\n' ':')\""
2266 nichoj 1.1 ) > "${JAVA_PKG_ENV}"
2267 betelgeuse 1.19
2268 nichoj 1.1 # register target/source
2269     local target="$(java-pkg_get-target)"
2270     local source="$(java-pkg_get-source)"
2271     [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
2272     [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
2273    
2274     # register javadoc info
2275     [[ -n ${JAVADOC_PATH} ]] && echo "JAVADOC_PATH=\"${JAVADOC_PATH}\"" \
2276     >> ${JAVA_PKG_ENV}
2277     # register source archives
2278     [[ -n ${JAVA_SOURCES} ]] && echo "JAVA_SOURCES=\"${JAVA_SOURCES}\"" \
2279     >> ${JAVA_PKG_ENV}
2280    
2281    
2282     echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
2283     [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
2284    
2285 caster 1.85 # extra env variables
2286     if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
2287     cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}" || die
2288     # nested echo to remove leading/trailing spaces
2289     echo "ENV_VARS=\"$(echo ${JAVA_PKG_EXTRA_ENV_VARS})\"" \
2290     >> "${JAVA_PKG_ENV}" || die
2291     fi
2292    
2293 nichoj 1.1 # Strip unnecessary leading and trailing colons
2294     # TODO try to cleanup if possible
2295     sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
2296 betelgeuse 1.87 else
2297 caster 1.88 debug-print "JAVA_PKG_CLASSPATH, JAVA_PKG_LIBRARY, JAVA_PKG_DEPEND_FILE"
2298     debug-print "or JAVA_PKG_OPTIONAL_DEPEND_FILE not defined so can't"
2299 betelgeuse 1.87 debug-print "write package.env."
2300 nichoj 1.1 fi
2301     }
2302    
2303 caster 1.155 # @FUNCTION: java-pkg_record-jar_
2304     # @INTERNAL
2305     # @DESCRIPTION:
2306 caster 1.88 # Record an (optional) dependency to the package.env
2307 caster 1.155 # @CODE
2308     # Parameters:
2309     # --optional - record dependency as optional
2310     # --build - record dependency as build_only
2311     # $1 - package to record
2312     # $2 - (optional) jar of package to record
2313     # @CODE
2314 betelgeuse 1.87 JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2315 caster 1.88 JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
2316 ali_bush 1.129 JAVA_PKG_BUILD_DEPEND_FILE="${T}/java-pkg-build-depend"
2317 nichoj 1.1
2318     java-pkg_record-jar_() {
2319     debug-print-function ${FUNCNAME} $*
2320    
2321 caster 1.88 local depend_file="${JAVA_PKG_DEPEND_FILE}"
2322 ali_bush 1.129 case "${1}" in
2323     "--optional") depend_file="${JAVA_PKG_OPTIONAL_DEPEND_FILE}"; shift;;
2324     "--build-only") depend_file="${JAVA_PKG_BUILD_DEPEND_FILE}"; shift;;
2325     esac
2326 caster 1.88
2327 nichoj 1.1 local pkg=${1} jar=${2} append
2328     if [[ -z "${jar}" ]]; then
2329     append="${pkg}"
2330     else
2331     append="$(basename ${jar})@${pkg}"
2332     fi
2333    
2334 caster 1.88 echo "${append}" >> "${depend_file}"
2335 nichoj 1.1 }
2336    
2337 caster 1.155 # @FUNCTION: java-pkg_append_
2338     # @INTERNAL
2339     # @DESCRIPTION:
2340     # Appends a value to a variable
2341 nichoj 1.1 #
2342 caster 1.155 # @CODE
2343     # Parameters:
2344     # $1 variable name to modify
2345     # $2 value to append
2346 nichoj 1.1 #
2347 caster 1.155 # Examples:
2348     # java-pkg_append_ CLASSPATH foo.jar
2349     # @CODE
2350 nichoj 1.1 java-pkg_append_() {
2351     debug-print-function ${FUNCNAME} $*
2352    
2353     local var="${1}" value="${2}"
2354     if [[ -z "${!var}" ]] ; then
2355     export ${var}="${value}"
2356     else
2357     local oldIFS=${IFS} cur haveit
2358     IFS=':'
2359     for cur in ${!var}; do
2360     if [[ ${cur} == ${value} ]]; then
2361     haveit="yes"
2362     break
2363     fi
2364     done
2365     [[ -z ${haveit} ]] && export ${var}="${!var}:${value}"
2366     IFS=${oldIFS}
2367     fi
2368     }
2369    
2370 caster 1.155 # @FUNCTION: java-pkg_expand_dir_
2371     # @INTERNAL
2372     # @DESCRIPTION:
2373 nichoj 1.1 # Gets the full path of the file/directory's parent.
2374 caster 1.155 # @CODE
2375     # Parameters:
2376     # $1 - file/directory to find parent directory for
2377     # @CODE
2378     # @RETURN: path to $1's parent directory
2379 nichoj 1.1 java-pkg_expand_dir_() {
2380     pushd "$(dirname "${1}")" >/dev/null 2>&1
2381     pwd
2382     popd >/dev/null 2>&1
2383     }
2384    
2385 caster 1.155 # @FUNCTION: java-pkg_func-exists
2386     # @INTERNAL
2387     # @DESCRIPTION:
2388 nichoj 1.1 # Does the indicated function exist?
2389 caster 1.155 # @RETURN: 0 - function is declared, 1 - function is undeclared
2390 nichoj 1.1 java-pkg_func-exists() {
2391 betelgeuse 1.126 declare -F ${1} > /dev/null
2392 nichoj 1.1 }
2393    
2394 caster 1.155 # @FUNCTION: java-pkg_setup-vm
2395     # @INTERNAL
2396     # @DESCRIPTION:
2397 nichoj 1.1 # Sets up the environment for a specific VM
2398     java-pkg_setup-vm() {
2399     debug-print-function ${FUNCNAME} $*
2400    
2401     local vendor="$(java-pkg_get-vm-vendor)"
2402 caster 1.23 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
2403 nichoj 1.1 addpredict "/dev/random"
2404     elif [[ "${vendor}" == "ibm" ]]; then
2405     addpredict "/proc/self/maps"
2406     addpredict "/proc/cpuinfo"
2407 serkan 1.143 addpredict "/proc/self/coredump_filter"
2408     elif [[ "${vendor}" == "oracle" ]]; then
2409     addpredict "/dev/random"
2410     addpredict "/proc/self/coredump_filter"
2411 serkan 1.145 elif [[ "${vendor}" == icedtea* ]] && java-pkg_is-vm-version-ge "1.7" ; then
2412 serkan 1.144 addpredict "/dev/random"
2413     addpredict "/proc/self/coredump_filter"
2414 nichoj 1.1 elif [[ "${vendor}" == "jrockit" ]]; then
2415     addpredict "/proc/cpuinfo"
2416     fi
2417     }
2418    
2419 caster 1.155 # @FUNCTION: java-pkg_needs-vm
2420     # @INTERNAL
2421     # @DESCRIPTION:
2422 sera 1.150 # Does the current package depend on virtual/jdk or does it set
2423     # JAVA_PKG_WANT_BUILD_VM?
2424 nichoj 1.1 #
2425 caster 1.155 # @RETURN: 0 - Package depends on virtual/jdk; 1 - Package does not depend on virtual/jdk
2426 nichoj 1.1 java-pkg_needs-vm() {
2427     debug-print-function ${FUNCNAME} $*
2428    
2429 caster 1.134 if [[ -n "$(echo ${JAVA_PKG_NV_DEPEND:-${DEPEND}} | sed -e '\:virtual/jdk:!d')" ]]; then
2430 nichoj 1.1 return 0
2431     fi
2432    
2433 sera 1.150 [[ -n "${JAVA_PKG_WANT_BUILD_VM}" ]] && return 0
2434    
2435 nichoj 1.1 return 1
2436     }
2437    
2438 caster 1.155 # @FUNCTION: java-pkg_get-current-vm
2439     # @INTERNAL
2440     # @RETURN - The current VM being used
2441 nichoj 1.1 java-pkg_get-current-vm() {
2442     java-config -f
2443     }
2444    
2445 caster 1.155 # @FUNCTION: java-pkg_get-vm-vendor
2446     # @INTERNAL
2447     # @RETURN - The vendor of the current VM
2448 nichoj 1.1 java-pkg_get-vm-vendor() {
2449     debug-print-function ${FUNCNAME} $*
2450    
2451     local vm="$(java-pkg_get-current-vm)"
2452     vm="${vm/-*/}"
2453     echo "${vm}"
2454     }
2455    
2456 caster 1.155 # @FUNCTION: java-pkg_get-vm-version
2457     # @INTERNAL
2458     # @RETURN - The version of the current VM
2459 nichoj 1.1 java-pkg_get-vm-version() {
2460     debug-print-function ${FUNCNAME} $*
2461    
2462 caster 1.22 java-config -g PROVIDES_VERSION
2463 nichoj 1.1 }
2464    
2465 caster 1.155 # @FUNCTION: java-pkg_build-vm-from-handle
2466     # @INTERNAL
2467     # @DESCRIPTION:
2468 sera 1.150 # Selects a build vm from a list of vm handles. First checks for the system-vm
2469     # beeing usable, then steps through the listed handles till a suitable vm is
2470     # found.
2471     #
2472 caster 1.155 # @RETURN - VM handle of an available JDK
2473 sera 1.150 java-pkg_build-vm-from-handle() {
2474     debug-print-function ${FUNCNAME} "$*"
2475    
2476     local vm
2477 sera 1.152 vm=$(java-pkg_get-current-vm 2>/dev/null)
2478     if [[ $? -eq 0 ]]; then
2479     if has ${vm} ${JAVA_PKG_WANT_BUILD_VM}; then
2480     echo ${vm}
2481     return 0
2482     fi
2483 sera 1.150 fi
2484    
2485     for vm in ${JAVA_PKG_WANT_BUILD_VM}; do
2486     if java-config-2 --select-vm=${vm} 2>/dev/null; then
2487     echo ${vm}
2488     return 0
2489     fi
2490     done
2491    
2492     eerror "${FUNCNAME}: No vm found for handles: ${JAVA_PKG_WANT_BUILD_VM}"
2493     return 1
2494     }
2495    
2496 caster 1.155 # @FUNCTION: java-pkg_switch-vm
2497     # @INTERNAL
2498     # @DESCRIPTION:
2499 betelgeuse 1.19 # Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
2500 nichoj 1.1 # verify that the current VM is sufficient.
2501     # Setup the environment for the VM being used.
2502     java-pkg_switch-vm() {
2503 betelgeuse 1.38 debug-print-function ${FUNCNAME} $*
2504    
2505 nichoj 1.1 if java-pkg_needs-vm; then
2506     # Use the VM specified by JAVA_PKG_FORCE_VM
2507 betelgeuse 1.38 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
2508 nichoj 1.1 # If you're forcing the VM, I hope you know what your doing...
2509 betelgeuse 1.38 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
2510 nichoj 1.1 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
2511     # if we're allowed to switch the vm...
2512     elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
2513 sera 1.150 # if there is an explicit list of handles to choose from
2514     if [[ -n "${JAVA_PKG_WANT_BUILD_VM}" ]]; then
2515     debug-print "JAVA_PKG_WANT_BUILD_VM used: ${JAVA_PKG_WANT_BUILD_VM}"
2516     GENTOO_VM=$(java-pkg_build-vm-from-handle)
2517     if [[ $? != 0 ]]; then
2518     eerror "${FUNCNAME}: No VM found for handles: ${JAVA_PKG_WANT_BUILD_VM}"
2519     die "${FUNCNAME}: Failed to determine VM for building"
2520     fi
2521     # JAVA_PKG_WANT_SOURCE and JAVA_PKG_WANT_TARGET are required as
2522     # they can't be deduced from handles.
2523     if [[ -z "${JAVA_PKG_WANT_SOURCE}" ]]; then
2524     eerror "JAVA_PKG_WANT_BUILD_VM specified but not JAVA_PKG_WANT_SOURCE"
2525     die "Specify JAVA_PKG_WANT_SOURCE"
2526     fi
2527     if [[ -z "${JAVA_PKG_WANT_TARGET}" ]]; then
2528     eerror "JAVA_PKG_WANT_BUILD_VM specified but not JAVA_PKG_WANT_TARGET"
2529     die "Specify JAVA_PKG_WANT_TARGET"
2530     fi
2531     # otherwise determine a vm from dep string
2532 caster 1.24 else
2533 sera 1.150 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
2534     GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
2535     if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
2536     eerror "Unable to determine VM for building from dependencies:"
2537     echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
2538     die "Failed to determine VM for building."
2539     fi
2540 nichoj 1.1 fi
2541 sera 1.150 export GENTOO_VM
2542 nichoj 1.1 # otherwise just make sure the current VM is sufficient
2543     else
2544     java-pkg_ensure-vm-version-sufficient
2545     fi
2546     debug-print "Using: $(java-config -f)"
2547 betelgeuse 1.19
2548 nichoj 1.1 java-pkg_setup-vm
2549    
2550 nichoj 1.4 export JAVA=$(java-config --java)
2551     export JAVAC=$(java-config --javac)
2552 caster 1.24 JAVACFLAGS="$(java-pkg_javac-args)"
2553     if [[ ${?} != 0 ]]; then
2554     eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
2555     die "java-pkg_javac-args failed"
2556     fi
2557     [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
2558     export JAVACFLAGS
2559 nichoj 1.1
2560     export JAVA_HOME="$(java-config -g JAVA_HOME)"
2561     export JDK_HOME=${JAVA_HOME}
2562    
2563     #TODO If you know a better solution let us know.
2564     java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
2565 betelgeuse 1.19
2566 nichoj 1.1 local tann="${T}/announced-vm"
2567 betelgeuse 1.92 # With the hooks we should only get here once from pkg_setup but better safe than sorry
2568     # if people have for example modified eclasses some where
2569 nichoj 1.1 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
2570 betelgeuse 1.92 einfo "Using: $(java-config -f)"
2571     [[ ! -f "${tann}" ]] && touch "${tann}"
2572 nichoj 1.1 fi
2573    
2574     else
2575     [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!"
2576     fi
2577     }
2578    
2579 caster 1.155 # @FUNCTION: java-pkg_die
2580     # @INTERNAL
2581     # @DESCRIPTION:
2582 nichoj 1.1 # Enhanced die for Java packages, which displays some information that may be
2583     # useful for debugging bugs on bugzilla.
2584     #register_die_hook java-pkg_die
2585 ssuominen 1.141 if ! has java-pkg_die ${EBUILD_DEATH_HOOKS}; then
2586 nichoj 1.1 EBUILD_DEATH_HOOKS="${EBUILD_DEATH_HOOKS} java-pkg_die"
2587     fi
2588    
2589     java-pkg_die() {
2590     echo "!!! When you file a bug report, please include the following information:" >&2
2591     echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2
2592     echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2
2593 sera 1.153 echo "and of course, the output of emerge --info =${P}" >&2
2594 nichoj 1.1 }
2595    
2596 nichoj 1.7
2597     # TODO document
2598     # List jars in the source directory, ${S}
2599     java-pkg_jar-list() {
2600     if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
2601     einfo "Linked Jars"
2602     find "${S}" -type l -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2603     einfo "Jars"
2604     find "${S}" -type f -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2605     einfo "Classes"
2606     find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2607     fi
2608     }
2609    
2610 caster 1.155 # @FUNCTION: java-pkg_verify-classes
2611     # @INTERNAL
2612     # @DESCRIPTION:
2613 caster 1.56 # Verify that the classes were compiled for the right source / target. Dies if
2614     # not.
2615 caster 1.155 # @CODE
2616     # $1 (optional) - the file to check, otherwise checks whole ${D}
2617     # @CODE
2618 nichoj 1.7 java-pkg_verify-classes() {
2619     #$(find ${D} -type f -name '*.jar' -o -name '*.class')
2620 ali_bush 1.108
2621     local version_verify="/usr/bin/class-version-verify.py"
2622    
2623     if [[ ! -x "${version_verify}" ]]; then
2624     version_verify="/usr/$(get_libdir)/javatoolkit/bin/class-version-verify.py"
2625     fi
2626    
2627     if [[ ! -x "${version_verify}" ]]; then
2628     ewarn "Unable to perform class version checks as"
2629     ewarn "class-version-verify.py is unavailable"
2630     ewarn "Please install dev-java/javatoolkit."
2631     return
2632     fi
2633    
2634 betelgeuse 1.55 local target=$(java-pkg_get-target)
2635 caster 1.56 local result
2636     local log="${T}/class-version-verify.log"
2637 betelgeuse 1.55 if [[ -n "${1}" ]]; then
2638 ali_bush 1.108 ${version_verify} -v -t ${target} "${1}" > "${log}"
2639 caster 1.56 result=$?
2640 betelgeuse 1.55 else
2641 caster 1.56 ebegin "Verifying java class versions (target: ${target})"
2642 ali_bush 1.108 ${version_verify} -v -t ${target} -r "${D}" > "${log}"
2643 caster 1.56 result=$?
2644     eend ${result}
2645 betelgeuse 1.55 fi
2646 caster 1.56 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2647 betelgeuse 1.55 if [[ ${result} != 0 ]]; then
2648 caster 1.56 eerror "Incorrect bytecode version found"
2649     [[ -n "${1}" ]] && eerror "in file: ${1}"
2650     eerror "See ${log} for more details."
2651     die "Incorrect bytecode found"
2652 nichoj 1.7 fi
2653     }
2654    
2655 caster 1.155 # @FUNCTION: java-pkg_ensure-dep
2656     # @INTERNAL
2657     # @DESCRIPTION:
2658 ali_bush 1.70 # Check that a package being used in jarfrom, getjars and getjar is contained
2659     # within DEPEND or RDEPEND.
2660 caster 1.155 # @CODE
2661     # Parameters:
2662     # $1 - empty - check both vars; "runtime" or "build" - check only
2663 caster 1.77 # RDEPEND, resp. DEPEND
2664 caster 1.155 # $2 - Package name and slot.
2665     # @CODE
2666 ali_bush 1.70 java-pkg_ensure-dep() {
2667     debug-print-function ${FUNCNAME} $*
2668    
2669 caster 1.77 local limit_to="${1}"
2670 ali_bush 1.70 local target_pkg="${2}"
2671     local dev_error=""
2672    
2673 fauli 1.149 # remove the version specification, which may include globbing (* and [123])
2674 ali_bush 1.70 local stripped_pkg=$(echo "${target_pkg}" | sed \
2675 caster 1.135 's/-\([0-9*]*\(\[[0-9]*\]\)*\)*\(\.\([0-9*]*\(\[[0-9]*\]\)*\)*\)*$//')
2676 ali_bush 1.70
2677 betelgeuse 1.87 debug-print "Matching against: ${stripped_pkg}"
2678    
2679 caster 1.77 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2680 ali_bush 1.70 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2681     dev_error="${dev_error} declared in DEPEND."
2682     if is-java-strict; then
2683 betelgeuse 1.87 eerror "${dev_error}"
2684 ali_bush 1.70 die "${dev_error}"
2685 betelgeuse 1.71 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2686 ali_bush 1.70 eerror "${dev_error}"
2687 betelgeuse 1.72 elog "Because you have this package installed the package will"
2688     elog "build without problems, but please report this to"
2689     elog "http://bugs.gentoo.org"
2690 ali_bush 1.70 fi
2691     fi
2692    
2693 ali_bush 1.86 if [[ ${limit_to} != build ]]; then
2694     if [[ ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2695     if [[ ! ( ${PDEPEND} =~ "${stripped_pkg}" ) ]]; then
2696     dev_error="The ebuild is attempting to use ${target_pkg},"
2697     dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND"
2698     dev_error="${dev_error} or PDEPEND."
2699     if is-java-strict; then
2700 betelgeuse 1.87 eerror "${dev_error}"
2701 ali_bush 1.86 die "${dev_error}"
2702     elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2703     eerror "${dev_error}"
2704     elog "The package will build without problems, but may fail to run"
2705     elog "if you don't have ${target_pkg} installed, so please report"
2706     elog "this to http://bugs.gentoo.org"
2707     fi
2708     fi
2709 ali_bush 1.70 fi
2710     fi
2711     }
2712    
2713 nichoj 1.1 java-pkg_check-phase() {
2714     local phase=${1}
2715 caster 1.82 local funcname=${FUNCNAME[1]}
2716     if [[ ${EBUILD_PHASE} != ${phase} ]]; then
2717     local msg="${funcname} used outside of src_${phase}"
2718     java-pkg_announce-qa-violation "${msg}"
2719 nichoj 1.1 fi
2720     }
2721    
2722     java-pkg_check-versioned-jar() {
2723     local jar=${1}
2724    
2725     if [[ ${jar} =~ ${PV} ]]; then
2726     java-pkg_announce-qa-violation "installing versioned jar '${jar}'"
2727     fi
2728     }
2729    
2730     java-pkg_check-jikes() {
2731 ssuominen 1.141 if has jikes ${IUSE}; then
2732 nichoj 1.1 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
2733     fi
2734     }
2735    
2736     java-pkg_announce-qa-violation() {
2737 caster 1.82 local nodie
2738     if [[ ${1} == "--nodie" ]]; then
2739     nodie="true"
2740     shift
2741 nichoj 1.1 fi
2742 caster 1.82 echo "Java QA Notice: $@" >&2
2743     increment-qa-violations
2744     [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
2745 nichoj 1.1 }
2746    
2747     increment-qa-violations() {
2748     let "JAVA_PKG_QA_VIOLATIONS+=1"
2749     export JAVA_PKG_QA_VIOLATIONS
2750     }
2751    
2752 nichoj 1.9 is-java-strict() {
2753 nichoj 1.14 [[ -n ${JAVA_PKG_STRICT} ]]
2754 nichoj 1.9 return $?
2755     }

  ViewVC Help
Powered by ViewVC 1.1.20