diff options
| author | Robin H. Johnson <robbat2@gentoo.org> | 2015-08-08 13:49:04 -0700 |
|---|---|---|
| committer | Robin H. Johnson <robbat2@gentoo.org> | 2015-08-08 17:38:18 -0700 |
| commit | 56bd759df1d0c750a065b8c845e93d5dfa6b549d (patch) | |
| tree | 3f91093cdb475e565ae857f1c5a7fd339e2d781e /eclass/java-utils-2.eclass | |
| download | gentoo-56bd759df1d0c750a065b8c845e93d5dfa6b549d.tar.gz gentoo-56bd759df1d0c750a065b8c845e93d5dfa6b549d.tar.bz2 gentoo-56bd759df1d0c750a065b8c845e93d5dfa6b549d.zip | |
proj/gentoo: Initial commit
This commit represents a new era for Gentoo:
Storing the gentoo-x86 tree in Git, as converted from CVS.
This commit is the start of the NEW history.
Any historical data is intended to be grafted onto this point.
Creation process:
1. Take final CVS checkout snapshot
2. Remove ALL ChangeLog* files
3. Transform all Manifests to thin
4. Remove empty Manifests
5. Convert all stale $Header$/$Id$ CVS keywords to non-expanded Git $Id$
5.1. Do not touch files with -kb/-ko keyword flags.
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
X-Thanks: Alec Warner <antarus@gentoo.org> - did the GSoC 2006 migration tests
X-Thanks: Robin H. Johnson <robbat2@gentoo.org> - infra guy, herding this project
X-Thanks: Nguyen Thai Ngoc Duy <pclouds@gentoo.org> - Former Gentoo developer, wrote Git features for the migration
X-Thanks: Brian Harring <ferringb@gentoo.org> - wrote much python to improve cvs2svn
X-Thanks: Rich Freeman <rich0@gentoo.org> - validation scripts
X-Thanks: Patrick Lauer <patrick@gentoo.org> - Gentoo dev, running new 2014 work in migration
X-Thanks: Michał Górny <mgorny@gentoo.org> - scripts, QA, nagging
X-Thanks: All of other Gentoo developers - many ideas and lots of paint on the bikeshed
Diffstat (limited to 'eclass/java-utils-2.eclass')
| -rw-r--r-- | eclass/java-utils-2.eclass | 2826 |
1 files changed, 2826 insertions, 0 deletions
diff --git a/eclass/java-utils-2.eclass b/eclass/java-utils-2.eclass new file mode 100644 index 000000000000..0a1a8a38b470 --- /dev/null +++ b/eclass/java-utils-2.eclass @@ -0,0 +1,2826 @@ +# Base eclass for Java packages +# +# Copyright (c) 2004-2005, Thomas Matthijs <axxo@gentoo.org> +# Copyright (c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org> +# Copyright (c) 2004-2015, Gentoo Foundation +# +# Licensed under the GNU General Public License, v2 +# +# $Id$ + +# @ECLASS: java-utils-2.eclass +# @MAINTAINER: +# java@gentoo.org +# @AUTHOR: +# Thomas Matthijs <axxo@gentoo.org>, Karl Trygve Kalleberg <karltk@gentoo.org> +# @BLURB: Base eclass for Java packages +# @DESCRIPTION: +# This eclass provides functionality which is used by java-pkg-2.eclass, +# java-pkg-opt-2.eclass and java-ant-2 eclass, as well as from ebuilds. +# +# This eclass should not be inherited this directly from an ebuild. Instead, +# you should inherit java-pkg-2 for Java packages or java-pkg-opt-2 for packages +# that have optional Java support. In addition you can inherit java-ant-2 for +# Ant-based packages. +inherit eutils versionator multilib + +IUSE="elibc_FreeBSD" + +# Make sure we use java-config-2 +export WANT_JAVA_CONFIG="2" + +# @VARIABLE: JAVA_PKG_PORTAGE_DEP +# @INTERNAL +# @DESCRIPTION: +# The version of portage we need to function properly. Previously it was +# portage with phase hooks support but now we use a version with proper env +# saving. For EAPI 2 we have new enough stuff so let's have cleaner deps. +has "${EAPI}" 0 1 && JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1.2.7" + +# @VARIABLE: JAVA_PKG_E_DEPEND +# @INTERNAL +# @DESCRIPTION: +# This is a convience variable to be used from the other java eclasses. This is +# the version of java-config we want to use. Usually the latest stable version +# so that ebuilds can use new features without depending on specific versions. +JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.2.0 ${JAVA_PKG_PORTAGE_DEP}" +has source ${JAVA_PKG_IUSE} && JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} source? ( app-arch/zip )" + +# @ECLASS-VARIABLE: JAVA_PKG_WANT_BOOTCLASSPATH +# @DEFAULT_UNSET +# @DESCRIPTION: +# The version of bootclasspath the package needs to work. Translates to a proper +# dependency. The bootclasspath can then be obtained by java-ant_rewrite-bootclasspath +if [[ -n "${JAVA_PKG_WANT_BOOTCLASSPATH}" ]]; then + if [[ "${JAVA_PKG_WANT_BOOTCLASSPATH}" == "1.5" ]]; then + JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} >=dev-java/gnu-classpath-0.98-r1:0.98" + else + eerror "Unknown value of JAVA_PKG_WANT_BOOTCLASSPATH" + # since die in global scope doesn't work, this will make repoman fail + JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} BAD_JAVA_PKG_WANT_BOOTCLASSPATH" + fi +fi + +# @ECLASS-VARIABLE: JAVA_PKG_ALLOW_VM_CHANGE +# @DESCRIPTION: +# Allow this eclass to change the active VM? +# If your system VM isn't sufficient for the package, the build will fail +# instead of trying to switch to another VM. +# +# Overriding the default can be useful for testing specific VMs locally, but +# should not be used in the final ebuild. +JAVA_PKG_ALLOW_VM_CHANGE=${JAVA_PKG_ALLOW_VM_CHANGE:="yes"} + +# @ECLASS-VARIABLE: JAVA_PKG_FORCE_VM +# @DEFAULT_UNSET +# @DESCRIPTION: +# Explicitly set a particular VM to use. If its not valid, it'll fall back to +# whatever /etc/java-config-2/build/jdk.conf would elect to use. +# +# Should only be used for testing and debugging. +# +# Example: use sun-jdk-1.5 to emerge foo: +# @CODE +# JAVA_PKG_FORCE_VM=sun-jdk-1.5 emerge foo +# @CODE + +# @ECLASS-VARIABLE: JAVA_PKG_WANT_BUILD_VM +# @DEFAULT_UNSET +# @DESCRIPTION: +# A list of VM handles to choose a build VM from. If the list contains the +# currently active VM use that one, otherwise step through the list till a +# usable/installed VM is found. +# +# This allows to use an explicit list of JDKs in DEPEND instead of a virtual. +# Users of this variable must make sure at least one of the listed handles is +# covered by DEPEND. +# Requires JAVA_PKG_WANT_SOURCE and JAVA_PKG_WANT_TARGET to be set as well. + +# @ECLASS-VARIABLE: JAVA_PKG_WANT_SOURCE +# @DEFAULT_UNSET +# @DESCRIPTION: +# Specify a non-standard Java source version for compilation (via javac -source +# parameter or Ant equivalent via build.xml rewriting done by java-ant-2 eclass). +# Normally this is determined from the jdk version specified in DEPEND. +# See java-pkg_get-source function below. +# +# Should generally only be used for testing and debugging. +# +# Use 1.4 source to emerge baz +# @CODE +# JAVA_PKG_WANT_SOURCE=1.4 emerge baz +# @CODE + +# @ECLASS-VARIABLE: JAVA_PKG_WANT_TARGET +# @DEFAULT_UNSET +# @DESCRIPTION: +# Same as JAVA_PKG_WANT_SOURCE (see above) but for javac -target parameter, +# which affects the version of generated bytecode. +# Normally this is determined from the jre/jdk version specified in RDEPEND. +# See java-pkg_get-target function below. +# +# Should generallyonly be used for testing and debugging. +# +# emerge bar to be compatible with 1.3 +# @CODE +# JAVA_PKG_WANT_TARGET=1.3 emerge bar +# @CODE + +# @ECLASS-VARIABLE: JAVA_RM_FILES +# @DEFAULT_UNSET +# @DESCRIPTION: +# An array containing a list of files to remove. If defined, this array will be +# automatically handed over to java-pkg_rm_files for processing during the +# src_prepare phase. +# +# @CODE +# JAVA_RM_FILES=( +# path/to/File1.java +# DELETEME.txt +# ) +# @CODE + +# @VARIABLE: JAVA_PKG_COMPILER_DIR +# @INTERNAL +# @DESCRIPTION: +# Directory where compiler settings are saved, without trailing slash. +# You probably shouldn't touch this variable except local testing. +JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"} + +# @VARIABLE: JAVA_PKG_COMPILERS_CONF +# @INTERNAL +# @DESCRIPTION: +# Path to file containing information about which compiler to use. +# Can be overloaded, but it should be overloaded only for local testing. +JAVA_PKG_COMPILERS_CONF=${JAVA_PKG_COMPILERS_CONF:="/etc/java-config-2/build/compilers.conf"} + +# @ECLASS-VARIABLE: JAVA_PKG_FORCE_COMPILER +# @INTERNAL +# @DEFAULT_UNSET +# @DESCRIPTION: +# Explicitly set a list of compilers to choose from. This is normally read from +# JAVA_PKG_COMPILERS_CONF. +# +# Useful for local testing. +# +# Use jikes and javac, in that order +# @CODE +# JAVA_PKG_FORCE_COMPILER="jikes javac" +# @CODE + +# @ECLASS-VARIABLE: JAVA_PKG_FORCE_ANT_TASKS +# @DEFAULT_UNSET +# @DESCRIPTION: +# An $IFS separated list of ant tasks. Can be set in environment before calling +# emerge/ebuild to override variables set in ebuild, mainly for testing before +# putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in +# eant() call, not the dependencies specified in WANT_ANT_TASKS. +# +# @CODE +# JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \ +# ebuild foo.ebuild compile +# @CODE + +# TODO document me +JAVA_PKG_QA_VIOLATIONS=0 + +# @FUNCTION: java-pkg_doexamples +# @USAGE: [--subdir <subdir>] <file1/dir1> [<file2> ...] +# @DESCRIPTION: +# Installs given arguments to /usr/share/doc/${PF}/examples +# If you give it only one parameter and it is a directory it will install +# everything in that directory to the examples directory. +# +# @CODE +# Parameters: +# --subdir - If the examples need a certain directory structure +# $* - list of files to install +# +# Examples: +# java-pkg_doexamples demo +# java-pkg_doexamples demo/* examples/* +# @CODE +java-pkg_doexamples() { + debug-print-function ${FUNCNAME} $* + + [[ ${#} -lt 1 ]] && die "At least one argument needed" + + java-pkg_check-phase install + java-pkg_init_paths_ + + local dest=/usr/share/doc/${PF}/examples + if [[ ${1} == --subdir ]]; then + local dest=${dest}/${2} + dodir ${dest} + shift 2 + fi + + if [[ ${#} = 1 && -d ${1} ]]; then + ( # dont want to pollute calling env + insinto "${dest}" + doins -r ${1}/* + ) || die "Installing examples failed" + else + ( # dont want to pollute calling env + insinto "${dest}" + doins -r "$@" + ) || die "Installing examples failed" + fi + + # Let's make a symlink to the directory we have everything else under + dosym "${dest}" "${JAVA_PKG_SHAREPATH}/examples" || die +} + +# @FUNCTION: java-pkg_addres +# @USAGE: <jar> <dir> [<find arguments> ...] +# @DESCRIPTION: +# Adds resource files to an existing jar. +# It is important that the directory given is actually the root of the +# corresponding resource tree. The target directory as well as +# sources.lst, MANIFEST.MF, *.class, *.jar, and *.java files are +# automatically excluded. Symlinks are always followed. Additional +# arguments are passed through to find. +# +# @CODE +# java-pkg_addres ${PN}.jar resources ! -name "*.html" +# @CODE +# +# @param $1 - jar file +# @param $2 - resource tree directory +# @param $* - arguments to pass to find +java-pkg_addres() { + debug-print-function ${FUNCNAME} $* + + [[ ${#} -lt 2 ]] && die "at least two arguments needed" + + local jar=$(realpath "$1" || die "realpath $1 failed") + local dir="$2" + shift 2 + + pushd "${dir}" > /dev/null || die "pushd ${dir} failed" + find -L -type f ! -path "./target/*" ! -path "./sources.lst" ! -name "MANIFEST.MF" ! -regex ".*\.\(class\|jar\|java\)" "${@}" -print0 | xargs -0 jar uf "${jar}" || die "jar failed" + popd > /dev/null || die "popd failed" +} + +# @FUNCTION: java-pkg_rm_files +# @USAGE: java-pkg_rm_files File1.java File2.java ... +# @DESCRIPTION: +# Remove unneeded files in ${S}. +# +# Every now and then, you'll run into situations whereby a file needs removing, +# be it a unit test or a regular java class. +# +# You can use this function by either: +# - calling it yourself in java_prepare() and feeding java-pkg_rm_files with +# the list of files you wish to remove. +# - defining an array in the ebuild named JAVA_RM_FILES with the list of files +# you wish to remove. +# +# Both way work and it is left to the developer's preferences. If the +# JAVA_RM_FILES array is defined, it will be automatically handed over to +# java-pkg_rm_files during the src_prepare phase. +# +# See java-utils-2_src_prepare. +# +# @CODE +# java-pkg_rm_files File1.java File2.java +# @CODE +# +# @param $* - list of files to remove. +java-pkg_rm_files() { + debug-print-function ${FUNCNAME} $* + local IFS="\n" + for filename in "$@"; do + [[ ! -f "${filename}" ]] && die "${filename} is not a regular file. Aborting." + einfo "Removing unneeded file ${filename}" + rm -f "${S}/${filename}" || die "cannot remove ${filename}" + eend $? + done +} + +# @FUNCTION: java-pkg_dojar +# @USAGE: <jar1> [<jar2> ...] +# @DESCRIPTION: +# Installs any number of jars. +# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default. +# You can use java-pkg_jarinto to change this path. +# You should never install a jar with a package version in the filename. +# Instead, use java-pkg_newjar defined below. +# +# @CODE +# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar +# @CODE +# +# @param $* - list of jars to install +java-pkg_dojar() { + debug-print-function ${FUNCNAME} $* + + [[ ${#} -lt 1 ]] && die "At least one argument needed" + + java-pkg_check-phase install + java-pkg_init_paths_ + + # Create JARDEST if it doesn't exist + dodir ${JAVA_PKG_JARDEST} + + local jar + # for each jar + for jar in "${@}"; do + local jar_basename=$(basename "${jar}") + + java-pkg_check-versioned-jar ${jar_basename} + + # check if it exists + if [[ -e "${jar}" ]] ; then + # Don't overwrite if jar has already been installed with the same + # name + local dest="${D}${JAVA_PKG_JARDEST}/${jar_basename}" + if [[ -e "${dest}" ]]; then + ewarn "Overwriting ${dest}" + fi + + # install it into JARDEST if it's a non-symlink + if [[ ! -L "${jar}" ]] ; then + #but first check class version when in strict mode. + is-java-strict && java-pkg_verify-classes "${jar}" + + INSDESTTREE="${JAVA_PKG_JARDEST}" \ + doins "${jar}" || die "failed to install ${jar}" + java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" + debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}" + # make a symlink to the original jar if it's symlink + else + # TODO use dosym, once we find something that could use it + # -nichoj + ln -s "$(readlink "${jar}")" "${D}${JAVA_PKG_JARDEST}/${jar_basename}" + debug-print "${jar} is a symlink, linking accordingly" + fi + else + die "${jar} does not exist" + fi + done + + java-pkg_do_write_ +} + +# @FUNCTION: java-pkg_regjar +# @USAGE: </path/to/installed/jar> +# @DESCRIPTION: +# Records an already installed (in ${D}) jar in the package.env +# This would mostly be used if the package has make or a custom script to +# install things. +# +# WARNING: +# if you want to use shell expansion, you have to use ${D}/... as the for in +# this function will not be able to expand the path, here's an example: +# +# @CODE +# java-pkg_regjar ${D}/opt/my-java/lib/*.jar +# @CODE +# + +# TODO should we be making sure the jar is present on ${D} or wherever? +java-pkg_regjar() { + debug-print-function ${FUNCNAME} $* + + java-pkg_check-phase install + + [[ ${#} -lt 1 ]] && die "at least one argument needed" + + java-pkg_init_paths_ + + local jar jar_dir jar_file + for jar in "${@}"; do + # TODO use java-pkg_check-versioned-jar + if [[ -e "${jar}" || -e "${D}${jar}" ]]; then + [[ -d "${jar}" || -d "${D}${jar}" ]] \ + && die "Called ${FUNCNAME} on a directory $*" + + #check that class version correct when in strict mode + is-java-strict && java-pkg_verify-classes "${jar}" + + # nelchael: we should strip ${D} in this case too, here's why: + # imagine such call: + # java-pkg_regjar ${D}/opt/java/*.jar + # such call will fall into this case (-e ${jar}) and will + # record paths with ${D} in package.env + java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" + else + if [[ ${jar} = *\** ]]; then + eerror "The argument ${jar} to ${FUNCNAME}" + eerror "has * in it. If you want it to glob in" + eerror '${D} add ${D} to the argument.' + fi + debug-print "${jar} or ${D}${jar} not found" + die "${jar} does not exist" + fi + done + + java-pkg_do_write_ +} + +# @FUNCTION: java-pkg_newjar +# @USAGE: <path/to/oldname.jar> [<newname.jar>] +# @DESCRIPTION: +# Installs a jar with a new name (defaults to $PN.jar) +# +# For example, installs a versioned jar without the version +java-pkg_newjar() { + debug-print-function ${FUNCNAME} $* + + local original_jar="${1}" + local new_jar="${2:-${PN}.jar}" + local new_jar_dest="${T}/${new_jar}" + + [[ -z ${original_jar} ]] && die "Must specify a jar to install" + [[ ! -f ${original_jar} ]] \ + && die "${original_jar} does not exist or is not a file!" + + rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" + cp "${original_jar}" "${new_jar_dest}" \ + || die "Failed to copy ${original_jar} to ${new_jar_dest}" + java-pkg_dojar "${new_jar_dest}" +} + +# @FUNCTION: java-pkg_addcp +# @USAGE: <classpath> +# @DESCRIPTION: +# Add something to the package's classpath. For jars, you should use dojar, +# newjar, or regjar. This is typically used to add directories to the classpath. +# The parameters of this function are appended to JAVA_PKG_CLASSPATH +java-pkg_addcp() { + java-pkg_append_ JAVA_PKG_CLASSPATH "${@}" + java-pkg_do_write_ +} + +# @FUNCTION: java-pkg_doso +# @USAGE: <path/to/file1.so> [...] +# @DESCRIPTION: +# Installs any number of JNI libraries +# They will be installed into /usr/lib by default, but java-pkg_sointo +# can be used change this path +# +# @CODE +# Example: +# java-pkg_doso *.so +# @CODE +java-pkg_doso() { + debug-print-function ${FUNCNAME} $* + + java-pkg_check-phase install + + [[ ${#} -lt 1 ]] && die "${FUNCNAME} requires at least one argument" + + java-pkg_init_paths_ + + local lib + # for each lib + for lib in "$@" ; do + # if the lib exists... + if [[ -e "${lib}" ]] ; then + # install if it isn't a symlink + if [[ ! -L "${lib}" ]] ; then + INSDESTTREE="${JAVA_PKG_LIBDEST}" \ + INSOPTIONS="-m0755" \ + doins "${lib}" || die "failed to install ${lib}" + java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" + debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" + # otherwise make a symlink to the symlink's origin + else + dosym "$(readlink "${lib}")" "${JAVA_PKG_LIBDEST}/${lib##*/}" + debug-print "${lib} is a symlink, linking accordantly" + fi + # otherwise die + else + die "${lib} does not exist" + fi + done + + java-pkg_do_write_ +} + +# @FUNCTION: java-pkg_regso +# @USAGE: <file1.so> [...] +# @DESCRIPTION: +# Registers an already installed JNI library in package.env. +# +# @CODE +# Parameters: +# $@ - JNI libraries to register +# +# Example: +# java-pkg_regso *.so /path/*.so +# @CODE +java-pkg_regso() { + debug-print-function ${FUNCNAME} $* + + java-pkg_check-phase install + + [[ ${#} -lt 1 ]] && die "${FUNCNAME} requires at least one argument" + + java-pkg_init_paths_ + + local lib target_dir + for lib in "$@" ; do + # Check the absolute path of the lib + if [[ -e "${lib}" ]] ; then + target_dir="$(java-pkg_expand_dir_ ${lib})" + java-pkg_append_ JAVA_PKG_LIBRARY "/${target_dir#${D}}" + # Check the path of the lib relative to ${D} + elif [[ -e "${D}${lib}" ]]; then + target_dir="$(java-pkg_expand_dir_ ${D}${lib})" + java-pkg_append_ JAVA_PKG_LIBRARY "${target_dir}" + else + die "${lib} does not exist" + fi + done + + java-pkg_do_write_ +} + +# @FUNCTION: java-pkg_jarinto +# @USAGE: </path/to/install/jars/into> +# @DESCRIPTION: +# Changes the path jars are installed into via subsequent java-pkg_dojar calls. +java-pkg_jarinto() { + debug-print-function ${FUNCNAME} $* + + JAVA_PKG_JARDEST="${1}" +} + +# @FUNCTION: java-pkg_sointo +# @USAGE: </path/to/install/sofiles/into> +# @DESCRIPTION: +# Changes the path that JNI libraries are installed into via subsequent +# java-pkg_doso calls. +java-pkg_sointo() { + debug-print-function ${FUNCNAME} $* + + JAVA_PKG_LIBDEST="${1}" +} + +# @FUNCTION: java-pkg_dohtml +# @USAGE: <path/to/javadoc/documentation> [...] +# @DESCRIPTION: +# Install Javadoc HTML documentation. Usage of java-pkg_dojavadoc is preferred. +# +# @CODE +# java-pkg_dohtml dist/docs/ +# @CODE +java-pkg_dohtml() { + debug-print-function ${FUNCNAME} $* + + [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" + + # from /usr/lib/portage/bin/dohtml -h + # -f Set list of allowed extensionless file names. + dohtml -f package-list "$@" + + # this probably shouldn't be here but it provides + # a reasonable way to catch # docs for all of the + # old ebuilds. + java-pkg_recordjavadoc +} + +# @FUNCTION: java-pkg_dojavadoc +# @USAGE: [--symlink destination] <path/to/javadocs/root> +# @DESCRIPTION: +# Installs javadoc documentation. This should be controlled by the doc use flag. +# +# @CODE +# Parameters: +# $1: optional --symlink creates to symlink like this for html +# documentation bundles. +# $2: - The javadoc root directory. +# +# Examples: +# java-pkg_dojavadoc docs/api +# java-pkg_dojavadoc --symlink apidocs docs/api +# @CODE +java-pkg_dojavadoc() { + debug-print-function ${FUNCNAME} $* + + # For html documentation bundles that link to Javadoc + local symlink + if [[ ${1} = --symlink ]]; then + symlink=${2} + shift 2 + fi + + local dir="$1" + local dest=/usr/share/doc/${PF}/html + + # QA checks + + java-pkg_check-phase install + java-pkg_init_paths_ + + [[ -z "${dir}" ]] && die "Must specify a directory!" + [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!" + if [[ ! -e "${dir}/index.html" ]]; then + local msg="No index.html in javadoc directory" + ewarn "${msg}" + is-java-strict && die "${msg}" + fi + + if [[ -e ${D}/${dest}/api ]]; then + eerror "${dest} already exists. Will not overwrite." + die "${dest}" + fi + + # Renaming to match our directory layout + + local dir_to_install="${dir}" + if [[ "$(basename "${dir}")" != "api" ]]; then + dir_to_install="${T}/api" + # TODO use doins + cp -r "${dir}" "${dir_to_install}" || die "cp failed" + fi + + # Actual installation + + java-pkg_dohtml -r "${dir_to_install}" + + # Let's make a symlink to the directory we have everything else under + dosym ${dest}/api "${JAVA_PKG_SHAREPATH}/api" || die + + if [[ ${symlink} ]]; then + debug-print "symlinking ${dest}/{api,${symlink}}" + dosym ${dest}/{api,${symlink}} || die + fi +} + +# @FUNCTION: java-pkg_dosrc +# @USAGE: <path/to/sources> [...] +# @DESCRIPTION: +# Installs a zip containing the source for a package, so it can used in +# from IDEs like eclipse and netbeans. +# Ebuild needs to DEPEND on app-arch/zip to use this. It also should be controlled by USE=source. +# +# @CODE +# Example: +# java-pkg_dosrc src/* +# @CODE + +# TODO change so it the arguments it takes are the base directories containing +# source -nichoj +# +# TODO should we be able to handle multiple calls to dosrc? -nichoj +# +# TODO maybe we can take an existing zip/jar? -nichoj +# +# FIXME apparently this fails if you give it an empty directories +java-pkg_dosrc() { + debug-print-function ${FUNCNAME} $* + + [ ${#} -lt 1 ] && die "At least one argument needed" + + java-pkg_check-phase install + + [[ ${#} -lt 1 ]] && die "At least one argument needed" + + if ! [[ ${DEPEND} = *app-arch/zip* ]]; then + local msg="${FUNCNAME} called without app-arch/zip in DEPEND" + java-pkg_announce-qa-violation ${msg} + fi + + java-pkg_init_paths_ + + local zip_name="${PN}-src.zip" + local zip_path="${T}/${zip_name}" + local dir + for dir in "${@}"; do + local dir_parent=$(dirname "${dir}") + local dir_name=$(basename "${dir}") + pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" + zip -q -r ${zip_path} ${dir_name} -i '*.java' + local result=$? + # 12 means zip has nothing to do + if [[ ${result} != 12 && ${result} != 0 ]]; then + die "failed to zip ${dir_name}" + fi + popd >/dev/null + done + + # Install the zip + INSDESTTREE=${JAVA_PKG_SOURCESPATH} \ + doins ${zip_path} || die "Failed to install source" + + JAVA_SOURCES="${JAVA_PKG_SOURCESPATH}/${zip_name}" + java-pkg_do_write_ +} + +# @FUNCTION: java-pkg_dolauncher +# @USAGE: <filename> [options] +# @DESCRIPTION: +# Make a wrapper script to lauch/start this package +# If necessary, the wrapper will switch to the appropriate VM. +# +# Can be called without parameters if the package installs only one jar +# that has the Main-class attribute set. The wrapper will be named ${PN}. +# +# @CODE +# Parameters: +# $1 - filename of launcher to create +# $2 - options, as follows: +# --main the.main.class.to.start +# --jar /the/jar/too/launch.jar or just <name>.jar +# --java_args 'Extra arguments to pass to java' +# --pkg_args 'Extra arguments to pass to the package' +# --pwd Directory the launcher changes to before executing java +# -into Directory to install the launcher to, instead of /usr/bin +# -pre Prepend contents of this file to the launcher +# @CODE +java-pkg_dolauncher() { + debug-print-function ${FUNCNAME} $* + + java-pkg_check-phase install + java-pkg_init_paths_ + + if [[ ${#} = 0 ]]; then + local name="${PN}" + else + local name="${1}" + shift + fi + + # TODO rename to launcher + local target="${T}/${name}" + local var_tmp="${T}/launcher_variables_tmp" + local target_dir pre + + # Process the other the rest of the arguments + while [[ -n "${1}" && -n "${2}" ]]; do + local var="${1}" value="${2}" + if [[ "${var:0:2}" == "--" ]]; then + local var=${var:2} + echo "gjl_${var}=\"${value}\"" >> "${var_tmp}" + local gjl_${var}="${value}" + elif [[ "${var}" == "-into" ]]; then + target_dir="${value}" + elif [[ "${var}" == "-pre" ]]; then + pre="${value}" + fi + shift 2 + done + + # Test if no --jar and --main arguments were given and + # in that case check if the package only installs one jar + # and use that jar. + if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then + local cp="${JAVA_PKG_CLASSPATH}" + if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then + echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}" + else + local msg="Not enough information to create a launcher given." + msg="${msg} Please give --jar or --main argument to ${FUNCNAME}." + die "${msg}" + fi + fi + + # Write the actual script + echo "#!/bin/bash" > "${target}" + if [[ -n "${pre}" ]]; then + if [[ -f "${pre}" ]]; then + cat "${pre}" >> "${target}" + else + die "-pre specified file '${pre}' does not exist" + fi + fi + echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" + cat "${var_tmp}" >> "${target}" + rm -f "${var_tmp}" + echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" + + if [[ -n "${target_dir}" ]]; then + DESTTREE="${target_dir}" dobin "${target}" + local ret=$? + return ${ret} + else + dobin "${target}" + fi +} + +# @FUNCTION: java-pkg_dowar +# @DESCRIPTION: +# Install war files. +# TODO document +java-pkg_dowar() { + debug-print-function ${FUNCNAME} $* + + # Check for arguments + [[ ${#} -lt 1 ]] && die "At least one argument needed" + java-pkg_check-phase install + + java-pkg_init_paths_ + + local war + for war in $* ; do + local warpath + # TODO evaluate if we want to handle symlinks differently -nichoj + # Check for symlink + if [[ -L "${war}" ]] ; then + cp "${war}" "${T}" + warpath="${T}$(basename "${war}")" + # Check for directory + # TODO evaluate if we want to handle directories differently -nichoj + elif [[ -d "${war}" ]] ; then + echo "dowar: warning, skipping directory ${war}" + continue + else + warpath="${war}" + fi + + # Install those files like you mean it + INSOPTIONS="-m 0644" \ + INSDESTTREE=${JAVA_PKG_WARDEST} \ + doins ${warpath} + done +} + +# @FUNCTION: java-pkg_recordjavadoc +# @INTERNAL +# @DESCRIPTION: +# Scan for JavaDocs, and record their existence in the package.env file + +# TODO make sure this in the proper section +java-pkg_recordjavadoc() +{ + debug-print-function ${FUNCNAME} $* + # the find statement is important + # as some packages include multiple trees of javadoc + JAVADOC_PATH="$(find ${D}/usr/share/doc/ -name allclasses-frame.html -printf '%h:')" + # remove $D - TODO: check this is ok with all cases of the above + JAVADOC_PATH="${JAVADOC_PATH//${D}}" + if [[ -n "${JAVADOC_PATH}" ]] ; then + debug-print "javadocs found in ${JAVADOC_PATH%:}" + java-pkg_do_write_ + else + debug-print "No javadocs found" + fi +} + + +# @FUNCTION: java-pkg_jar-from +# @USAGE: [--build-only] [--with-dependencies] [--virtual] [--into dir] <package> [<package.jar>] [<destination.jar>] +# @DESCRIPTION: +# Makes a symlink to a jar from a certain package +# A lot of java packages include dependencies in a lib/ directory +# You can use this function to replace these bundled dependencies. +# The dependency is recorded into package.env DEPEND line, unless "--build-only" +# is passed as the very first argument, for jars that have to be present only +# at build time and are not needed on runtime (junit testing etc). +# +# @CODE +# Example: get all jars from xerces slot 2 +# java-pkg_jar-from xerces-2 +# +# Example: get a specific jar from xerces slot 2 +# java-pkg_jar-from xerces-2 xml-apis.jar +# +# Example: get a specific jar from xerces slot 2, and name it diffrently +# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar +# +# Example: get junit.jar which is needed only for building +# java-pkg_jar-from --build-only junit junit.jar +# @CODE +# +# @CODE +# Parameters +# --build-only - makes the jar(s) not added into package.env DEPEND line. +# (assumed automatically when called inside src_test) +# --with-dependencies - get jars also from requested package's dependencies +# transitively. +# --virtual - Packages passed to this function are to be handled as virtuals +# and will not have individual jar dependencies recorded. +# --into $dir - symlink jar(s) into $dir (must exist) instead of . +# $1 - Package to get jars from, or comma-separated list of packages in +# case other parameters are not used. +# $2 - jar from package. If not specified, all jars will be used. +# $3 - When a single jar is specified, destination filename of the +# symlink. Defaults to the name of the jar. +# @CODE + +# TODO could probably be cleaned up a little +java-pkg_jar-from() { + debug-print-function ${FUNCNAME} $* + + local build_only="" + local destdir="." + local deep="" + local virtual="" + local record_jar="" + + [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build" + + while [[ "${1}" == --* ]]; do + if [[ "${1}" = "--build-only" ]]; then + build_only="build" + elif [[ "${1}" = "--with-dependencies" ]]; then + deep="--with-dependencies" + elif [[ "${1}" = "--virtual" ]]; then + virtual="true" + elif [[ "${1}" = "--into" ]]; then + destdir="${2}" + shift + else + die "java-pkg_jar-from called with unknown parameter: ${1}" + fi + shift + done + + local target_pkg="${1}" target_jar="${2}" destjar="${3}" + + [[ -z ${target_pkg} ]] && die "Must specify a package" + + if [[ "${EAPI}" == "1" ]]; then + target_pkg="${target_pkg//:/-}" + fi + + # default destjar to the target jar + [[ -z "${destjar}" ]] && destjar="${target_jar}" + + local error_msg="There was a problem getting the classpath for ${target_pkg}." + local classpath + classpath="$(java-config ${deep} --classpath=${target_pkg})" + [[ $? != 0 ]] && die ${error_msg} + + # When we have commas this functions is called to bring jars from multiple + # packages. This affects recording of dependencencies performed later + # which expects one package only, so we do it here. + if [[ ${target_pkg} = *,* ]]; then + for pkg in ${target_pkg//,/ }; do + java-pkg_ensure-dep "${build_only}" "${pkg}" + [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" + done + # setting this disables further record-jar_ calls later + record_jar="true" + else + java-pkg_ensure-dep "${build_only}" "${target_pkg}" + fi + + # Record the entire virtual as a dependency so that + # no jars are missed. + if [[ -z "${build_only}" && -n "${virtual}" ]]; then + java-pkg_record-jar_ "${target_pkg}" + # setting this disables further record-jars_ calls later + record_jar="true" + fi + + pushd ${destdir} > /dev/null \ + || die "failed to change directory to ${destdir}" + + local jar + for jar in ${classpath//:/ }; do + local jar_name=$(basename "${jar}") + if [[ ! -f "${jar}" ]] ; then + debug-print "${jar} from ${target_pkg} does not exist" + die "Installation problems with jars in ${target_pkg} - is it installed?" + fi + # If no specific target jar was indicated, link it + if [[ -z "${target_jar}" ]] ; then + [[ -f "${target_jar}" ]] && rm "${target_jar}" + ln -snf "${jar}" \ + || die "Failed to make symlink from ${jar} to ${jar_name}" + if [[ -z "${record_jar}" ]]; then + if [[ -z "${build_only}" ]]; then + java-pkg_record-jar_ "${target_pkg}" "${jar}" + else + java-pkg_record-jar_ --build-only "${target_pkg}" "${jar}" + fi + fi + # otherwise, if the current jar is the target jar, link it + elif [[ "${jar_name}" == "${target_jar}" ]] ; then + [[ -f "${destjar}" ]] && rm "${destjar}" + ln -snf "${jar}" "${destjar}" \ + || die "Failed to make symlink from ${jar} to ${destjar}" + if [[ -z "${record_jar}" ]]; then + if [[ -z "${build_only}" ]]; then + java-pkg_record-jar_ "${target_pkg}" "${jar}" + else + java-pkg_record-jar_ --build-only "${target_pkg}" "${jar}" + fi + fi + popd > /dev/null + return 0 + fi + done + popd > /dev/null + # if no target was specified, we're ok + if [[ -z "${target_jar}" ]] ; then + return 0 + # otherwise, die bitterly + else + die "Failed to find ${target_jar:-jar} in ${target_pkg}" + fi +} + +# @FUNCTION: java-pkg_jarfrom +# @DESCRIPTION: +# See java-pkg_jar-from +java-pkg_jarfrom() { + java-pkg_jar-from "$@" +} + +# @FUNCTION: java-pkg_getjars +# @USAGE: [--build-only] [--with-dependencies] <package1>[,<package2>...] +# @DESCRIPTION: +# Get the classpath provided by any number of packages +# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'. +# The providing packages are recorded as dependencies into package.env DEPEND +# line, unless "--build-only" is passed as the very first argument, for jars +# that have to be present only at build time and are not needed on runtime +# (junit testing etc). +# +# @CODE +# Example: Get the classpath for xerces-2 and xalan, +# java-pkg_getjars xerces-2,xalan +# +# Example Return: +# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar +# +# +# Parameters: +# --build-only - makes the jar(s) not added into package.env DEPEND line. +# (assumed automatically when called inside src_test) +# --with-dependencies - get jars also from requested package's dependencies +# transitively. +# $1 - list of packages to get jars from +# (passed to java-config --classpath) +# @CODE +java-pkg_getjars() { + debug-print-function ${FUNCNAME} $* + + local build_only="" + local deep="" + + [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build" + + while [[ "${1}" == --* ]]; do + if [[ "${1}" = "--build-only" ]]; then + build_only="build" + elif [[ "${1}" = "--with-dependencies" ]]; then + deep="--with-dependencies" + else + die "java-pkg_jar-from called with unknown parameter: ${1}" + fi + shift + done + + [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only |
