/[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.126 - (show annotations) (download)
Tue Mar 31 19:19:20 2009 UTC (5 years, 10 months ago) by betelgeuse
Branch: MAIN
Changes since 1.125: +3 -6 lines
Simply java-pkg_func-exists using suggestions by ciaranm and dberkholz on gentoo-dev.

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

  ViewVC Help
Powered by ViewVC 1.1.20