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