/[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.143 - (hide annotations) (download)
Sat Sep 10 14:32:58 2011 UTC (2 years, 11 months ago) by serkan
Branch: MAIN
Changes since 1.142: +5 -1 lines
Fix sandbox violations reported in bugs #371827 and #382465.

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

  ViewVC Help
Powered by ViewVC 1.1.20