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