/[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.135 - (hide annotations) (download)
Wed Apr 28 19:40:40 2010 UTC (4 years, 5 months ago) by caster
Branch: MAIN
Changes since 1.134: +3 -2 lines
Support version globbing when checking dependencies, bug #315123.

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

  ViewVC Help
Powered by ViewVC 1.1.20