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