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