2022-12-28 23:56:33 +03:00
|
|
|
# Copyright 2007-2022 Gentoo Authors
|
2015-10-06 09:26:20 +03:00
|
|
|
# Distributed under the terms of the GNU General Public License v2
|
2012-02-06 16:39:49 +04:00
|
|
|
|
2015-10-20 12:09:11 +03:00
|
|
|
# @ECLASS: java-osgi.eclass
|
|
|
|
# @MAINTAINER:
|
|
|
|
# java@gentoo.org
|
|
|
|
# @AUTHOR:
|
2021-03-31 11:33:30 +03:00
|
|
|
# Java maintainers <java@gentoo.org>
|
2022-12-28 23:56:33 +03:00
|
|
|
# @SUPPORTED_EAPIS: 7 8
|
2021-09-03 00:08:59 +03:00
|
|
|
# @PROVIDES: java-utils-2
|
2021-06-21 22:46:01 +03:00
|
|
|
# @BLURB: Java OSGi eclass
|
2015-10-20 12:09:11 +03:00
|
|
|
# @DESCRIPTION:
|
|
|
|
# This eclass provides functionality which is used by packages that need to be
|
|
|
|
# OSGi compliant. This means that the generated jars will have special headers
|
|
|
|
# in their manifests. Currently this is used only by Eclipse-3.3 - later we
|
|
|
|
# could extend this so that Gentoo Java system would be fully OSGi compliant.
|
2012-02-06 16:39:49 +04:00
|
|
|
|
2022-12-28 23:56:33 +03:00
|
|
|
case ${EAPI} in
|
|
|
|
7|8) ;;
|
2021-06-21 06:49:54 +03:00
|
|
|
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [[ -z ${_JAVA_OSGI_ECLASS} ]] ; then
|
|
|
|
_JAVA_OSGI_ECLASS=1
|
|
|
|
|
2012-02-06 16:39:49 +04:00
|
|
|
inherit java-utils-2
|
|
|
|
|
2022-03-24 17:03:46 +03:00
|
|
|
# @ECLASS_VARIABLE: _OSGI_T
|
2015-10-20 12:09:11 +03:00
|
|
|
# @INTERNAL
|
|
|
|
# @DESCRIPTION:
|
2022-12-28 23:56:33 +03:00
|
|
|
_OSGI_T="${T}"
|
2012-02-06 16:39:49 +04:00
|
|
|
|
2022-12-28 23:56:33 +03:00
|
|
|
# TODO add to portability.eclass
|
2012-02-06 16:39:49 +04:00
|
|
|
_canonicalise() {
|
|
|
|
if type -p realpath > /dev/null; then
|
|
|
|
realpath "${@}"
|
|
|
|
elif type -p readlink > /dev/null; then
|
|
|
|
readlink -f "${@}"
|
|
|
|
else
|
|
|
|
# can't die, subshell
|
|
|
|
eerror "No readlink nor realpath found, cannot canonicalise"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-10-20 12:09:11 +03:00
|
|
|
# @FUNCTION: _java-osgi_plugin
|
|
|
|
# @USAGE: <plugin name>
|
|
|
|
# @INTERNAL
|
|
|
|
# @DESCRIPTION:
|
2012-02-06 16:39:49 +04:00
|
|
|
# This is an internal function, not to be called directly.
|
|
|
|
#
|
2015-10-20 12:09:11 +03:00
|
|
|
# @CODE
|
2012-02-06 16:39:49 +04:00
|
|
|
# _java-osgi_plugin "JSch"
|
2015-10-20 12:09:11 +03:00
|
|
|
# @CODE
|
2012-02-06 16:39:49 +04:00
|
|
|
#
|
|
|
|
# @param $1 - bundle name
|
|
|
|
_java-osgi_plugin() {
|
|
|
|
# We hardcode Gentoo as the vendor name
|
|
|
|
|
|
|
|
cat > "${_OSGI_T}/tmp_jar/plugin.properties" <<-EOF
|
|
|
|
bundleName="${1}"
|
|
|
|
vendorName="Gentoo"
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2015-10-20 12:09:11 +03:00
|
|
|
# @FUNCTION: _java-osgi_makejar
|
|
|
|
# @USAGE: <jar name> <symbolic name> <bundle name> <header name>
|
|
|
|
# @INTERNAL
|
|
|
|
# @DESCRIPTION:
|
2012-02-06 16:39:49 +04:00
|
|
|
# This is an internal function, not to be called directly.
|
|
|
|
#
|
2015-10-20 12:09:11 +03:00
|
|
|
# @CODE
|
2012-02-06 16:39:49 +04:00
|
|
|
# _java-osgi_makejar "dist/${PN}.jar" "com.jcraft.jsch" "JSch" "com.jcraft.jsch, com.jcraft.jsch.jce;x-internal:=true"
|
2015-10-20 12:09:11 +03:00
|
|
|
# @CODE
|
2012-02-06 16:39:49 +04:00
|
|
|
#
|
|
|
|
# @param $1 - name of jar to repackage with OSGi
|
|
|
|
# @param $2 - bundle symbolic name
|
|
|
|
# @param $3 - bundle name
|
|
|
|
# @param $4 - export-package header
|
|
|
|
_java-osgi_makejar() {
|
|
|
|
debug-print-function ${FUNCNAME} "$@"
|
|
|
|
|
|
|
|
(( ${#} < 4 )) && die "Four arguments are needed for _java-osgi_makejar()"
|
|
|
|
|
|
|
|
local absoluteJarPath="$(_canonicalise ${1})"
|
|
|
|
local jarName="$(basename ${1})"
|
|
|
|
|
|
|
|
mkdir "${_OSGI_T}/tmp_jar" || die "Unable to create directory ${_OSGI_T}/tmp_jar"
|
|
|
|
[[ -d "${_OSGI_T}/osgi" ]] || mkdir "${_OSGI_T}/osgi" || die "Unable to create directory ${_OSGI_T}/osgi"
|
|
|
|
|
|
|
|
cd "${_OSGI_T}/tmp_jar" && jar xf "${absoluteJarPath}" && cd - > /dev/null \
|
|
|
|
|| die "Unable to uncompress correctly the original jar"
|
|
|
|
|
|
|
|
cat > "${_OSGI_T}/tmp_jar/META-INF/MANIFEST.MF" <<-EOF
|
|
|
|
Manifest-Version: 1.0
|
|
|
|
Bundle-ManifestVersion: 2
|
|
|
|
Bundle-Name: %bundleName
|
|
|
|
Bundle-Vendor: %vendorName
|
|
|
|
Bundle-Localization: plugin
|
|
|
|
Bundle-SymbolicName: ${2}
|
|
|
|
Bundle-Version: ${PV}
|
|
|
|
Export-Package: ${4}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
_java-osgi_plugin "${3}"
|
|
|
|
|
|
|
|
jar cfm "${_OSGI_T}/osgi/${jarName}" "${_OSGI_T}/tmp_jar/META-INF/MANIFEST.MF" \
|
|
|
|
-C "${_OSGI_T}/tmp_jar/" . > /dev/null || die "Unable to recreate the OSGi compliant jar"
|
|
|
|
rm -rf "${_OSGI_T}/tmp_jar"
|
|
|
|
}
|
|
|
|
|
2015-10-20 12:09:11 +03:00
|
|
|
# @FUNCTION: @java-osgi_dojar
|
|
|
|
# @USAGE: <jar name> <symbolic name> <bundle name> <header name>
|
|
|
|
# @DESCRIPTION:
|
2012-02-06 16:39:49 +04:00
|
|
|
# Rewrites a jar, and produce an OSGi compliant jar from arguments given on the command line.
|
|
|
|
# The arguments given correspond to the minimal set of headers
|
|
|
|
# that must be present on a Manifest file of an OSGi package.
|
|
|
|
# If you need more headers, you should use the *-fromfile functions below,
|
|
|
|
# that create the Manifest from a file.
|
|
|
|
# It will call java-pkg_dojar at the end.
|
|
|
|
#
|
2015-10-20 12:09:11 +03:00
|
|
|
# @CODE
|
2012-02-06 16:39:49 +04:00
|
|
|
# java-osgi_dojar "dist/${PN}.jar" "com.jcraft.jsch" "JSch" "com.jcraft.jsch, com.jcraft.jsch.jce;x-internal:=true"
|
2015-10-20 12:09:11 +03:00
|
|
|
# @CODE
|
2012-02-06 16:39:49 +04:00
|
|
|
#
|
|
|
|
# @param $1 - name of jar to repackage with OSGi
|
|
|
|
# @param $2 - bundle symbolic name
|
|
|
|
# @param $3 - bundle name
|
|
|
|
# @param $4 - export-package-header
|
|
|
|
java-osgi_dojar() {
|
|
|
|
debug-print-function ${FUNCNAME} "$@"
|
|
|
|
local jarName="$(basename ${1})"
|
|
|
|
_java-osgi_makejar "$@"
|
|
|
|
java-pkg_dojar "${_OSGI_T}/osgi/${jarName}"
|
|
|
|
}
|
|
|
|
|
2015-10-20 12:09:11 +03:00
|
|
|
# @FUNCTION: java-osgi_newjar
|
|
|
|
# @USAGE: <jar name> <symbolic name> <bundle name> <header name>
|
|
|
|
# @DESCRIPTION:
|
2012-02-06 16:39:49 +04:00
|
|
|
# Rewrites a jar, and produce an OSGi compliant jar.
|
|
|
|
# The arguments given correspond to the minimal set of headers
|
|
|
|
# that must be present on a Manifest file of an OSGi package.
|
|
|
|
# If you need more headers, you should use the *-fromfile functions below,
|
|
|
|
# that create the Manifest from a file.
|
|
|
|
# It will call java-pkg_newjar at the end.
|
|
|
|
#
|
2015-10-20 12:09:11 +03:00
|
|
|
# @CODE
|
2012-02-06 16:39:49 +04:00
|
|
|
# java-osgi_newjar "dist/${PN}.jar" "com.jcraft.jsch" "JSch" "com.jcraft.jsch, com.jcraft.jsch.jce;x-internal:=true"
|
2015-10-20 12:09:11 +03:00
|
|
|
# @CODE
|
2012-02-06 16:39:49 +04:00
|
|
|
#
|
|
|
|
# @param $1 - name of jar to repackage with OSGi
|
|
|
|
# @param $2 (optional) - name of the target jar. It will default to package name if not specified.
|
|
|
|
# @param $3 - bundle symbolic name
|
|
|
|
# @param $4 - bundle name
|
|
|
|
# @param $5 - export-package header
|
|
|
|
java-osgi_newjar() {
|
|
|
|
debug-print-function ${FUNCNAME} "$@"
|
|
|
|
local jarName="$(basename $1)"
|
|
|
|
|
|
|
|
if (( ${#} > 4 )); then
|
|
|
|
_java-osgi_makejar "${1}" "${3}" "${4}" "${5}"
|
|
|
|
java-pkg_newjar "${_OSGI_T}/osgi/${jarName}" "${2}"
|
|
|
|
else
|
|
|
|
_java-osgi_makejar "$@"
|
|
|
|
java-pkg_newjar "${_OSGI_T}/osgi/${jarName}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-10-20 12:09:11 +03:00
|
|
|
# @FUNCTION:_java-osgi_makejar-fromfile
|
|
|
|
# @USAGE: <jar to repackage with OSGi> <Manifest file> <bundle name> <version rewriting>
|
|
|
|
# @INTERNAL
|
|
|
|
# @DESCRIPTION:
|
2012-02-06 16:39:49 +04:00
|
|
|
# This is an internal function, not to be called directly.
|
|
|
|
#
|
2015-10-20 12:09:11 +03:00
|
|
|
# @CODE
|
2012-02-06 16:39:49 +04:00
|
|
|
# _java-osgi_makejar-fromfile "dist/${PN}.jar" "${FILESDIR}/MANIFEST.MF" "JSch" 1
|
2015-10-20 12:09:11 +03:00
|
|
|
# @CODE
|
2012-02-06 16:39:49 +04:00
|
|
|
#
|
|
|
|
# @param $1 - name of jar to repackage with OSGi
|
|
|
|
# @param $2 - path to the Manifest file
|
|
|
|
# @param $3 - bundle name
|
|
|
|
# @param $4 - automatic version rewriting (0 or 1)
|
|
|
|
_java-osgi_makejar-fromfile() {
|
|
|
|
debug-print-function ${FUNCNAME} "$@"
|
|
|
|
|
|
|
|
((${#} < 4)) && die "Four arguments are needed for _java-osgi_makejar-fromfile()"
|
|
|
|
|
|
|
|
local absoluteJarPath="$(_canonicalise ${1})"
|
|
|
|
local jarName="$(basename ${1})"
|
|
|
|
|
|
|
|
mkdir "${_OSGI_T}/tmp_jar" || die "Unable to create directory ${_OSGI_T}/tmp_jar"
|
|
|
|
[[ -d "${_OSGI_T}/osgi" ]] || mkdir "${_OSGI_T}/osgi" || die "Unable to create directory ${_OSGI_T}/osgi"
|
|
|
|
|
|
|
|
cd "${_OSGI_T}/tmp_jar" && jar xf "${absoluteJarPath}" && cd - > /dev/null \
|
|
|
|
|| die "Unable to uncompress correctly the original jar"
|
|
|
|
|
|
|
|
[[ -e "${2}" ]] || die "Manifest file ${2} not found"
|
|
|
|
|
|
|
|
# We automatically change the version if automatic version rewriting is on
|
|
|
|
|
|
|
|
if (( ${4} )); then
|
|
|
|
cat "${2}" | sed "s/Bundle-Version:.*/Bundle-Version: ${PV}/" > \
|
|
|
|
"${_OSGI_T}/tmp_jar/META-INF/MANIFEST.MF"
|
|
|
|
else
|
|
|
|
cat "${2}" > "${_OSGI_T}/tmp_jar/META-INF/MANIFEST.MF"
|
|
|
|
fi
|
|
|
|
|
|
|
|
_java-osgi_plugin "${3}"
|
|
|
|
|
|
|
|
jar cfm "${_OSGI_T}/osgi/${jarName}" "${_OSGI_T}/tmp_jar/META-INF/MANIFEST.MF" \
|
|
|
|
-C "${_OSGI_T}/tmp_jar/" . > /dev/null || die "Unable to recreate the OSGi compliant jar"
|
|
|
|
rm -rf "${_OSGI_T}/tmp_jar"
|
|
|
|
}
|
|
|
|
|
2015-10-20 12:09:11 +03:00
|
|
|
# @FUNCTION: java-osgi_newjar-fromfile
|
|
|
|
# @USAGE: <jar to repackage with OSGi> <Manifest file> <bundle name> <version rewriting>
|
|
|
|
# @DESCRIPTION:
|
2012-02-06 16:39:49 +04:00
|
|
|
# This function produces an OSGi compliant jar from a given manifest file.
|
|
|
|
# The Manifest Bundle-Version header will be replaced by the current version
|
|
|
|
# of the package, unless the --no-auto-version option is given.
|
|
|
|
# It will call java-pkg_newjar at the end.
|
|
|
|
#
|
2015-10-20 12:09:11 +03:00
|
|
|
# @CODE
|
2012-02-06 16:39:49 +04:00
|
|
|
# java-osgi_newjar-fromfile "dist/${PN}.jar" "${FILESDIR}/MANIFEST.MF" "Standard Widget Toolkit for GTK 2.0"
|
2015-10-20 12:09:11 +03:00
|
|
|
# @CODE
|
2012-02-06 16:39:49 +04:00
|
|
|
#
|
|
|
|
# @param $opt
|
|
|
|
# --no-auto-version - This option disables automatic rewriting of the
|
2015-10-20 12:09:11 +03:00
|
|
|
# version in the Manifest file
|
|
|
|
#
|
2012-02-06 16:39:49 +04:00
|
|
|
# @param $1 - name of jar to repackage with OSGi
|
|
|
|
# @param $2 (optional) - name of the target jar. It will default to package name if not specified.
|
|
|
|
# @param $3 - path to the Manifest file
|
|
|
|
# @param $4 - bundle name
|
|
|
|
java-osgi_newjar-fromfile() {
|
|
|
|
debug-print-function ${FUNCNAME} "$@"
|
|
|
|
local versionRewriting=1
|
|
|
|
|
|
|
|
if [[ "${1}" == "--no-auto-version" ]]; then
|
|
|
|
versionRewriting=0
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
local jarName="$(basename ${1})"
|
|
|
|
|
|
|
|
if (( ${#} > 3 )); then
|
|
|
|
_java-osgi_makejar-fromfile "${1}" "${3}" "${4}" "${versionRewriting}"
|
|
|
|
java-pkg_newjar "${_OSGI_T}/osgi/${jarName}" "${2}"
|
|
|
|
else
|
|
|
|
_java-osgi_makejar-fromfile "$@" "${versionRewriting}"
|
|
|
|
java-pkg_newjar "${_OSGI_T}/osgi/${jarName}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-03-20 00:52:53 +03:00
|
|
|
# @FUNCTION: java-osgi_dojar-fromfile
|
2015-10-20 12:09:11 +03:00
|
|
|
# @USAGE: <jar to repackage with OSGi> <Manifest file> <bundle name>
|
|
|
|
# @DESCRIPTION:
|
2012-02-06 16:39:49 +04:00
|
|
|
# This function produces an OSGi compliant jar from a given manifestfile.
|
|
|
|
# The Manifest Bundle-Version header will be replaced by the current version
|
|
|
|
# of the package, unless the --no-auto-version option is given.
|
|
|
|
# It will call java-pkg_dojar at the end.
|
|
|
|
#
|
2015-10-20 12:09:11 +03:00
|
|
|
# @CODE
|
2012-02-06 16:39:49 +04:00
|
|
|
# java-osgi_dojar-fromfile "dist/${PN}.jar" "${FILESDIR}/MANIFEST.MF" "Standard Widget Toolkit for GTK 2.0"
|
2015-10-20 12:09:11 +03:00
|
|
|
# @CODE
|
2012-02-06 16:39:49 +04:00
|
|
|
#
|
|
|
|
# @param $opt
|
|
|
|
# --no-auto-version - This option disables automatic rewriting of the
|
|
|
|
# version in the Manifest file
|
2015-10-20 12:09:11 +03:00
|
|
|
#
|
2012-02-06 16:39:49 +04:00
|
|
|
# @param $1 - name of jar to repackage with OSGi
|
|
|
|
# @param $2 - path to the Manifest file
|
|
|
|
# @param $3 - bundle name
|
|
|
|
java-osgi_dojar-fromfile() {
|
|
|
|
debug-print-function ${FUNCNAME} "$@"
|
|
|
|
local versionRewriting=1
|
|
|
|
|
|
|
|
if [[ "${1}" == "--no-auto-version" ]]; then
|
|
|
|
versionRewriting=0
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
local jarName="$(basename ${1})"
|
|
|
|
|
|
|
|
_java-osgi_makejar-fromfile "$@" "${versionRewriting}"
|
|
|
|
java-pkg_dojar "${_OSGI_T}/osgi/${jarName}"
|
|
|
|
}
|
2021-06-21 06:49:54 +03:00
|
|
|
|
|
|
|
fi
|