/[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.93 - (hide annotations) (download)
Thu Sep 27 19:47:08 2007 UTC (6 years, 9 months ago) by betelgeuse
Branch: MAIN
Changes since 1.92: +8 -1 lines
Add --subdir option to java-pkg_doexamples.

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

  ViewVC Help
Powered by ViewVC 1.1.20