| 1 |
# Base eclass for Java packages that needs to be OSGi compliant
|
| 2 |
#
|
| 3 |
# Copyright (c) 2007, Jean-Noël Rivasseau <elvanor@gmail.com>
|
| 4 |
# Copyright (c) 2007-2011, Gentoo Foundation
|
| 5 |
#
|
| 6 |
# Licensed under the GNU General Public License, v2
|
| 7 |
#
|
| 8 |
# $Header: /var/cvsroot/gentoo-x86/eclass/java-osgi.eclass,v 1.6 2011/08/29 01:28:10 vapier Exp $
|
| 9 |
|
| 10 |
# -----------------------------------------------------------------------------
|
| 11 |
# @eclass-begin
|
| 12 |
# @eclass-shortdesc Java OSGi eclass
|
| 13 |
# @eclass-maintainer java@gentoo.org
|
| 14 |
#
|
| 15 |
# This eclass provides functionality which is used by
|
| 16 |
# packages that need to be OSGi compliant. This means
|
| 17 |
# that the generated jars will have special headers in their manifests.
|
| 18 |
# Currently this is used only by Eclipse-3.3 - later
|
| 19 |
# we could extend this so that Gentoo Java system would be
|
| 20 |
# fully OSGi compliant.
|
| 21 |
#
|
| 22 |
# -----------------------------------------------------------------------------
|
| 23 |
|
| 24 |
inherit java-utils-2
|
| 25 |
|
| 26 |
# We define _OSGI_T so that it does not contain a slash at the end.
|
| 27 |
# According to Paludis guys, there is currently a proposal for EAPIs that
|
| 28 |
# would require all variables to end with a slash.
|
| 29 |
|
| 30 |
_OSGI_T="${T/%\//}"
|
| 31 |
|
| 32 |
# must get Diego to commit something like this to portability.eclass
|
| 33 |
_canonicalise() {
|
| 34 |
if type -p realpath > /dev/null; then
|
| 35 |
realpath "${@}"
|
| 36 |
elif type -p readlink > /dev/null; then
|
| 37 |
readlink -f "${@}"
|
| 38 |
else
|
| 39 |
# can't die, subshell
|
| 40 |
eerror "No readlink nor realpath found, cannot canonicalise"
|
| 41 |
fi
|
| 42 |
}
|
| 43 |
|
| 44 |
# -----------------------------------------------------------------------------
|
| 45 |
# @ebuild-function _java-osgi_plugin
|
| 46 |
#
|
| 47 |
# This is an internal function, not to be called directly.
|
| 48 |
#
|
| 49 |
# @example
|
| 50 |
# _java-osgi_plugin "JSch"
|
| 51 |
#
|
| 52 |
# @param $1 - bundle name
|
| 53 |
#
|
| 54 |
# ------------------------------------------------------------------------------
|
| 55 |
|
| 56 |
_java-osgi_plugin() {
|
| 57 |
# We hardcode Gentoo as the vendor name
|
| 58 |
|
| 59 |
cat > "${_OSGI_T}/tmp_jar/plugin.properties" <<-EOF
|
| 60 |
bundleName="${1}"
|
| 61 |
vendorName="Gentoo"
|
| 62 |
EOF
|
| 63 |
}
|
| 64 |
|
| 65 |
# -----------------------------------------------------------------------------
|
| 66 |
# @ebuild-function _java-osgi_makejar
|
| 67 |
#
|
| 68 |
# This is an internal function, not to be called directly.
|
| 69 |
#
|
| 70 |
# @example
|
| 71 |
# _java-osgi_makejar "dist/${PN}.jar" "com.jcraft.jsch" "JSch" "com.jcraft.jsch, com.jcraft.jsch.jce;x-internal:=true"
|
| 72 |
#
|
| 73 |
# @param $1 - name of jar to repackage with OSGi
|
| 74 |
# @param $2 - bundle symbolic name
|
| 75 |
# @param $3 - bundle name
|
| 76 |
# @param $4 - export-package header
|
| 77 |
#
|
| 78 |
# ------------------------------------------------------------------------------
|
| 79 |
|
| 80 |
_java-osgi_makejar() {
|
| 81 |
debug-print-function ${FUNCNAME} "$@"
|
| 82 |
|
| 83 |
(( ${#} < 4 )) && die "Four arguments are needed for _java-osgi_makejar()"
|
| 84 |
|
| 85 |
local absoluteJarPath="$(_canonicalise ${1})"
|
| 86 |
local jarName="$(basename ${1})"
|
| 87 |
|
| 88 |
mkdir "${_OSGI_T}/tmp_jar" || die "Unable to create directory ${_OSGI_T}/tmp_jar"
|
| 89 |
[[ -d "${_OSGI_T}/osgi" ]] || mkdir "${_OSGI_T}/osgi" || die "Unable to create directory ${_OSGI_T}/osgi"
|
| 90 |
|
| 91 |
cd "${_OSGI_T}/tmp_jar" && jar xf "${absoluteJarPath}" && cd - > /dev/null \
|
| 92 |
|| die "Unable to uncompress correctly the original jar"
|
| 93 |
|
| 94 |
cat > "${_OSGI_T}/tmp_jar/META-INF/MANIFEST.MF" <<-EOF
|
| 95 |
Manifest-Version: 1.0
|
| 96 |
Bundle-ManifestVersion: 2
|
| 97 |
Bundle-Name: %bundleName
|
| 98 |
Bundle-Vendor: %vendorName
|
| 99 |
Bundle-Localization: plugin
|
| 100 |
Bundle-SymbolicName: ${2}
|
| 101 |
Bundle-Version: ${PV}
|
| 102 |
Export-Package: ${4}
|
| 103 |
EOF
|
| 104 |
|
| 105 |
_java-osgi_plugin "${3}"
|
| 106 |
|
| 107 |
jar cfm "${_OSGI_T}/osgi/${jarName}" "${_OSGI_T}/tmp_jar/META-INF/MANIFEST.MF" \
|
| 108 |
-C "${_OSGI_T}/tmp_jar/" . > /dev/null || die "Unable to recreate the OSGi compliant jar"
|
| 109 |
rm -rf "${_OSGI_T}/tmp_jar"
|
| 110 |
}
|
| 111 |
|
| 112 |
# -----------------------------------------------------------------------------
|
| 113 |
# @ebuild-function java-osgi_dojar
|
| 114 |
#
|
| 115 |
# Rewrites a jar, and produce an OSGi compliant jar from arguments given on the command line.
|
| 116 |
# The arguments given correspond to the minimal set of headers
|
| 117 |
# that must be present on a Manifest file of an OSGi package.
|
| 118 |
# If you need more headers, you should use the *-fromfile functions below,
|
| 119 |
# that create the Manifest from a file.
|
| 120 |
# It will call java-pkg_dojar at the end.
|
| 121 |
#
|
| 122 |
# @example
|
| 123 |
# java-osgi_dojar "dist/${PN}.jar" "com.jcraft.jsch" "JSch" "com.jcraft.jsch, com.jcraft.jsch.jce;x-internal:=true"
|
| 124 |
#
|
| 125 |
# @param $1 - name of jar to repackage with OSGi
|
| 126 |
# @param $2 - bundle symbolic name
|
| 127 |
# @param $3 - bundle name
|
| 128 |
# @param $4 - export-package-header
|
| 129 |
#
|
| 130 |
# ------------------------------------------------------------------------------
|
| 131 |
|
| 132 |
java-osgi_dojar() {
|
| 133 |
debug-print-function ${FUNCNAME} "$@"
|
| 134 |
local jarName="$(basename ${1})"
|
| 135 |
_java-osgi_makejar "$@"
|
| 136 |
java-pkg_dojar "${_OSGI_T}/osgi/${jarName}"
|
| 137 |
}
|
| 138 |
|
| 139 |
# -----------------------------------------------------------------------------
|
| 140 |
# @ebuild-function java-osgi_newjar
|
| 141 |
#
|
| 142 |
# Rewrites a jar, and produce an OSGi compliant jar.
|
| 143 |
# The arguments given correspond to the minimal set of headers
|
| 144 |
# that must be present on a Manifest file of an OSGi package.
|
| 145 |
# If you need more headers, you should use the *-fromfile functions below,
|
| 146 |
# that create the Manifest from a file.
|
| 147 |
# It will call java-pkg_newjar at the end.
|
| 148 |
#
|
| 149 |
# @example
|
| 150 |
# java-osgi_newjar "dist/${PN}.jar" "com.jcraft.jsch" "JSch" "com.jcraft.jsch, com.jcraft.jsch.jce;x-internal:=true"
|
| 151 |
#
|
| 152 |
# @param $1 - name of jar to repackage with OSGi
|
| 153 |
# @param $2 (optional) - name of the target jar. It will default to package name if not specified.
|
| 154 |
# @param $3 - bundle symbolic name
|
| 155 |
# @param $4 - bundle name
|
| 156 |
# @param $5 - export-package header
|
| 157 |
#
|
| 158 |
# ------------------------------------------------------------------------------
|
| 159 |
|
| 160 |
java-osgi_newjar() {
|
| 161 |
debug-print-function ${FUNCNAME} "$@"
|
| 162 |
local jarName="$(basename $1)"
|
| 163 |
|
| 164 |
if (( ${#} > 4 )); then
|
| 165 |
_java-osgi_makejar "${1}" "${3}" "${4}" "${5}"
|
| 166 |
java-pkg_newjar "${_OSGI_T}/osgi/${jarName}" "${2}"
|
| 167 |
else
|
| 168 |
_java-osgi_makejar "$@"
|
| 169 |
java-pkg_newjar "${_OSGI_T}/osgi/${jarName}"
|
| 170 |
fi
|
| 171 |
}
|
| 172 |
|
| 173 |
# -----------------------------------------------------------------------------
|
| 174 |
# @ebuild-function _java-osgi_makejar-fromfile
|
| 175 |
#
|
| 176 |
# This is an internal function, not to be called directly.
|
| 177 |
#
|
| 178 |
# @example
|
| 179 |
# _java-osgi_makejar-fromfile "dist/${PN}.jar" "${FILESDIR}/MANIFEST.MF" "JSch" 1
|
| 180 |
#
|
| 181 |
# @param $1 - name of jar to repackage with OSGi
|
| 182 |
# @param $2 - path to the Manifest file
|
| 183 |
# @param $3 - bundle name
|
| 184 |
# @param $4 - automatic version rewriting (0 or 1)
|
| 185 |
#
|
| 186 |
# ------------------------------------------------------------------------------
|
| 187 |
|
| 188 |
_java-osgi_makejar-fromfile() {
|
| 189 |
debug-print-function ${FUNCNAME} "$@"
|
| 190 |
|
| 191 |
((${#} < 4)) && die "Four arguments are needed for _java-osgi_makejar-fromfile()"
|
| 192 |
|
| 193 |
local absoluteJarPath="$(_canonicalise ${1})"
|
| 194 |
local jarName="$(basename ${1})"
|
| 195 |
|
| 196 |
mkdir "${_OSGI_T}/tmp_jar" || die "Unable to create directory ${_OSGI_T}/tmp_jar"
|
| 197 |
[[ -d "${_OSGI_T}/osgi" ]] || mkdir "${_OSGI_T}/osgi" || die "Unable to create directory ${_OSGI_T}/osgi"
|
| 198 |
|
| 199 |
cd "${_OSGI_T}/tmp_jar" && jar xf "${absoluteJarPath}" && cd - > /dev/null \
|
| 200 |
|| die "Unable to uncompress correctly the original jar"
|
| 201 |
|
| 202 |
[[ -e "${2}" ]] || die "Manifest file ${2} not found"
|
| 203 |
|
| 204 |
# We automatically change the version if automatic version rewriting is on
|
| 205 |
|
| 206 |
if (( ${4} )); then
|
| 207 |
cat "${2}" | sed "s/Bundle-Version:.*/Bundle-Version: ${PV}/" > \
|
| 208 |
"${_OSGI_T}/tmp_jar/META-INF/MANIFEST.MF"
|
| 209 |
else
|
| 210 |
cat "${2}" > "${_OSGI_T}/tmp_jar/META-INF/MANIFEST.MF"
|
| 211 |
fi
|
| 212 |
|
| 213 |
_java-osgi_plugin "${3}"
|
| 214 |
|
| 215 |
jar cfm "${_OSGI_T}/osgi/${jarName}" "${_OSGI_T}/tmp_jar/META-INF/MANIFEST.MF" \
|
| 216 |
-C "${_OSGI_T}/tmp_jar/" . > /dev/null || die "Unable to recreate the OSGi compliant jar"
|
| 217 |
rm -rf "${_OSGI_T}/tmp_jar"
|
| 218 |
}
|
| 219 |
|
| 220 |
# -----------------------------------------------------------------------------
|
| 221 |
# @ebuild-function java-osgi_newjar-fromfile()
|
| 222 |
#
|
| 223 |
# This function produces an OSGi compliant jar from a given manifest file.
|
| 224 |
# The Manifest Bundle-Version header will be replaced by the current version
|
| 225 |
# of the package, unless the --no-auto-version option is given.
|
| 226 |
# It will call java-pkg_newjar at the end.
|
| 227 |
#
|
| 228 |
# @example
|
| 229 |
# java-osgi_newjar-fromfile "dist/${PN}.jar" "${FILESDIR}/MANIFEST.MF" "Standard Widget Toolkit for GTK 2.0"
|
| 230 |
#
|
| 231 |
# @param $opt
|
| 232 |
# --no-auto-version - This option disables automatic rewriting of the
|
| 233 |
# version in the Manifest file#
|
| 234 |
# @param $1 - name of jar to repackage with OSGi
|
| 235 |
# @param $2 (optional) - name of the target jar. It will default to package name if not specified.
|
| 236 |
# @param $3 - path to the Manifest file
|
| 237 |
# @param $4 - bundle name
|
| 238 |
#
|
| 239 |
# ------------------------------------------------------------------------------
|
| 240 |
|
| 241 |
java-osgi_newjar-fromfile() {
|
| 242 |
debug-print-function ${FUNCNAME} "$@"
|
| 243 |
local versionRewriting=1
|
| 244 |
|
| 245 |
if [[ "${1}" == "--no-auto-version" ]]; then
|
| 246 |
versionRewriting=0
|
| 247 |
shift
|
| 248 |
fi
|
| 249 |
local jarName="$(basename ${1})"
|
| 250 |
|
| 251 |
if (( ${#} > 3 )); then
|
| 252 |
_java-osgi_makejar-fromfile "${1}" "${3}" "${4}" "${versionRewriting}"
|
| 253 |
java-pkg_newjar "${_OSGI_T}/osgi/${jarName}" "${2}"
|
| 254 |
else
|
| 255 |
_java-osgi_makejar-fromfile "$@" "${versionRewriting}"
|
| 256 |
java-pkg_newjar "${_OSGI_T}/osgi/${jarName}"
|
| 257 |
fi
|
| 258 |
}
|
| 259 |
|
| 260 |
# -----------------------------------------------------------------------------
|
| 261 |
# @ebuild-function java-osgi_dojar-fromfile()
|
| 262 |
#
|
| 263 |
# This function produces an OSGi compliant jar from a given manifestfile.
|
| 264 |
# The Manifest Bundle-Version header will be replaced by the current version
|
| 265 |
# of the package, unless the --no-auto-version option is given.
|
| 266 |
# It will call java-pkg_dojar at the end.
|
| 267 |
#
|
| 268 |
# @example
|
| 269 |
# java-osgi_dojar-fromfile "dist/${PN}.jar" "${FILESDIR}/MANIFEST.MF" "Standard Widget Toolkit for GTK 2.0"
|
| 270 |
#
|
| 271 |
# @param $opt
|
| 272 |
# --no-auto-version - This option disables automatic rewriting of the
|
| 273 |
# version in the Manifest file
|
| 274 |
# @param $1 - name of jar to repackage with OSGi
|
| 275 |
# @param $2 - path to the Manifest file
|
| 276 |
# @param $3 - bundle name
|
| 277 |
#
|
| 278 |
# ------------------------------------------------------------------------------
|
| 279 |
|
| 280 |
java-osgi_dojar-fromfile() {
|
| 281 |
debug-print-function ${FUNCNAME} "$@"
|
| 282 |
local versionRewriting=1
|
| 283 |
|
| 284 |
if [[ "${1}" == "--no-auto-version" ]]; then
|
| 285 |
versionRewriting=0
|
| 286 |
shift
|
| 287 |
fi
|
| 288 |
local jarName="$(basename ${1})"
|
| 289 |
|
| 290 |
_java-osgi_makejar-fromfile "$@" "${versionRewriting}"
|
| 291 |
java-pkg_dojar "${_OSGI_T}/osgi/${jarName}"
|
| 292 |
}
|