/[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.78 - (show annotations) (download)
Tue Apr 24 21:11:41 2007 UTC (7 years, 3 months ago) by caster
Branch: MAIN
Changes since 1.77: +5 -5 lines
Fix automatic build-only in src_test that I broke with previously.

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

  ViewVC Help
Powered by ViewVC 1.1.20