1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<META name="description" content="Apache Tuscany">
<META name="keywords" content="apache, apache tuscany, tuscany, service, services, fabric, soa, service oriented architecture, sca, service component architecture, das, sdo, csa, ruby, opensource">
<LINK type="text/css" rel="stylesheet" href="http://tuscany.apache.org/stylesheets/default.css">
<LINK rel="SHORTCUT ICON" href="https://cwiki.apache.org/confluence/display/TUSCANYxDOCx2x/$images/favicon.ico">
<TITLE>OSGi Aware Programming in Tuscany : Apache Tuscany</TITLE>
<META http-equiv="Content-Type" content="text/html;charset=UTF-8"></HEAD>
<STYLE>
.spacetree * ul {
padding-left:0px;
margin-left: 0px;
}
.spacetree * li {
margin-left: 5px;
padding-left:5px;
}
</STYLE>
<BODY onload="init()">
<!-- topNav -->
<TABLE border="0" cellpadding="2" cellspacing="0" width="100%">
<TR class="topBar">
<TD align="left" valign="middle" class="topBarDiv" align="left" nowrap="">
<A href="https://cwiki.apache.org/geronimo"> Home</A> > <A href="index.html" title="Apache Tuscany Docs 2.x">Apache Tuscany Docs 2.x</A> > <A href="index.html" title="Index">Index</A> > <A href="development-guides.html" title="Development Guides">Development Guides</A> > <A href="" title="OSGi Aware Programming in Tuscany">OSGi Aware Programming in Tuscany</A>
</TD>
<TD align="right" valign="middle" nowrap="">
<FORM name="search" action="http://www.google.com/search" method="get">
<INPUT type="hidden" name="ie" value="UTF-8">
<INPUT type="hidden" name="oe" value="UTF-8">
<INPUT type="hidden" name="domains" value="">
<INPUT type="hidden" name="sitesearch" value="">
<INPUT type="text" name="q" maxlength="255" value="">
<INPUT type="submit" name="btnG" value="Google Search">
</FORM>
</TD>
</TR>
</TABLE>
<TABLE border="0" cellpadding="2" cellspacing="0" width="100%">
<TR class="topBar">
<TD align="left" valign="middle" class="topBarDiv" nowrap="true" width="100%">
<A href="index.html" title="Apache Tuscany Docs 2.x">Apache Tuscany Docs 2.x</A> > <A href="index.html" title="Index">Index</A> > <A href="development-guides.html" title="Development Guides">Development Guides</A> > <A href="" title="OSGi Aware Programming in Tuscany">OSGi Aware Programming in Tuscany</A>
</TD>
<TD align="right" valign="middle" class="topBarDiv" align="left" nowrap="true">
<A href="http://tuscany.apache.org/">Tuscany Home</A> | <A href="http://mail-archives.apache.org/mod_mbox/tuscany-user">User List</A> | <A href="http://mail-archives.apache.org/mod_mbox/tuscany-dev">Dev List</A> | <A href="http://issues.apache.org/jira/browse/Tuscany">Issue Tracker</A>
</TD>
</TR>
</TABLE>
<TABLE border="0" cellpadding="0" width="100%" bgcolor="#FFFFFF">
<TR>
<TD valign="top" align="left" width="22%" bgcolor="#F9F9F9" class="noprint">
<DIV class="tabletitle">Table of Contents</DIV>
<DIV class="spacetree">
</DIV>
</TD>
<TD align="left" valign="top" width="78%">
<!-- pageContent -->
<DIV id="PageContent">
<DIV class="pageheader" style="padding: 6px 0px 0px 0px;">
<!-- We'll enable this once we figure out how to access (and save) the logo resource -->
<!--img src="http://geronimo.apache.org/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"-->
<DIV style="margin: 0px 10px 0px 10px" class="smalltext">Apache Tuscany Docs 2.x</DIV>
<DIV style="margin: 0px 10px 8px 10px" class="pagetitle">OSGi Aware Programming in Tuscany</DIV>
<DIV class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;">
<!-- -->
<A href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=109135">
<IMG src="http://geronimo.apache.org/images/icons/notep_16.gif" height="16" width="16" border="0" align="absmiddle" title="Edit Page"></A>
<A href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=109135">Edit Page</A>
<A href="https://cwiki.apache.org/confluence/pages/listpages.action?key=TUSCANYxDOCx2x">
<IMG src="http://geronimo.apache.org/images/icons/browse_space.gif" height="16" width="16" border="0" align="absmiddle" title="Browse Space"></A>
<A href="https://cwiki.apache.org/confluence/pages/listpages.action?key=TUSCANYxDOCx2x">Browse Space</A>
<A href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=TUSCANYxDOCx2x&fromPageId=109135">
<IMG src="http://geronimo.apache.org/images/icons/add_page_16.gif" height="16" width="16" border="0" align="absmiddle" title="Add Page"></A>
<A href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=TUSCANYxDOCx2x&fromPageId=109135">Add Page</A>
<A href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=TUSCANYxDOCx2x&fromPageId=109135">
<IMG src="http://geronimo.apache.org/images/icons/add_blogentry_16.gif" height="16" width="16" border="0" align="absmiddle" title="Add News"></A>
<A href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=TUSCANYxDOCx2x&fromPageId=109135">Add News</A>
<!-- -->
</DIV>
</DIV>
<DIV class="pagecontent">
<DIV class="wiki-content">
<H2><A name="OSGiAwareProgramminginTuscany-MotivationforOSGi"></A>Motivation for OSGi</H2>
<P> The Apache Tuscany project has become a large project, with various extensions and component types that brings to the SCA Runtime different levels of dependencies. With its growth, Tuscany also started to have it's SPIs violated by some of these extensions, and some of the boundaries between sub-systems are broken, as there wasn't any enforcement of these boundaries.</P>
<P> The OSGi model provides a very powerful and flexible framework to develop applications in a modular fashion with a high degree of control over classloading inter-dependencies over modules. An OSGi module (a.k.a bundle) have a manifest file (META-INF\manifest.mf) that contains module information such as "name", "version" and also a list of what packages are being exported, and what packages are being imported from the given bundle, providing ways to easily enforce module boundaries.</P>
<P> In summary:</P>
<UL>
<LI>Better class loading mechanism for our modules</LI>
<LI>Create clean boundaries between sub-systems</LI>
</UL>
<H2><A name="OSGiAwareProgramminginTuscany-TuscanyandOSGi3rdpartydependencies"></A>Tuscany and OSGi - 3rd party dependencies</H2>
<P> Currently we are wrapping the 3rd party dependencies as OSGi bundles, but leaving it unpacked (a.k.a folder structure). This allow use to use the same dependency jars in a OSGi environment as well as in a non-OSGI environment and generating no side effect on our distribution footprint.</P>
<P> <SPAN class="image-wrap" style=""><IMG src="osgi-aware-programming-in-tuscany.data/osgi_3rd_party_dependencies.JPG" style="border: 0px solid black"></SPAN></P>
<H2><A name="OSGiAwareProgramminginTuscany-TuscanyandOSGiGranularity"></A>Tuscany and OSGi - Granularity</H2>
<P> The granularity used to define modules should be very familiar to all tuscany developers, </P>
<P> Tuscany Modules --> OSGi Bundles<BR>
3rd Party Libraries --> OSGi Bundles (using unpacked wrap style bundle)</P>
<H2><A name="OSGiAwareProgramminginTuscany-ProperlydefiningnewTuscanymodulesasanOSGibundle"></A>Properly defining new Tuscany modules as an OSGi bundle</H2>
<P> When adding new modules to the Tuscany project, the developer will need to create the OSGi Manifest to properly describe the new module as an OSGi bundle. These artifacts can be automatically generated using the Felix maven-bundle-plugin and should be available from svn repository once it's stable.</P>
<H4><A name="OSGiAwareProgramminginTuscany-GeneratingOSGimanifestwithFelixmavenbundleplugin"></A>Generating OSGi manifest with Felix maven-bundle-plugin</H4>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;"><B>"configuring maven to generate the OSGi manifest"</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<!-- Bundle versioned from Tuscany version -->
<Bundle-Version>${tuscany.version}</Bundle-Version>
<!-- Bundle Symbolic name -->
<Bundle-SymbolicName>org.apache.tuscany.sca.api</Bundle-SymbolicName>
<!-- Bundle description from pom description -->
<Bundle-Description>${pom.description}</Bundle-Description>
<!-- Export org.osoa.sca and all sub-packages -->
<Export-Package>org.osoa.sca*</Export-Package>
<!-- No Import-Package so calculate imports from code dependencies -->
</instructions>
</configuration>
</plugin>
</PRE>
</DIV></DIV>
<P>Below is a manifest that was generated for one of the Tuscany modules using the felix maven-bundle-plugin.</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;"><B>"OSGi Manifest (META-INF\manifest.mf)"</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">
Manifest-Version: 1.0
Export-Package: org.apache.tuscany.sca.assembly;uses:="javax.xml.xpath
,org.apache.tuscany.sca.assembly.impl,org.apache.tuscany.sca.policy,o
rg.apache.tuscany.sca.interfacedef,javax.xml.namespace<SPAN class="code-quote">";version="</SPAN>1.4"
,org.apache.tuscany.sca.assembly.impl;uses:="javax.xml.xpath,org.apac
he.tuscany.sca.assembly,org.apache.tuscany.sca.policy,org.apache.tusc
any.sca.interfacedef,javax.xml.namespace<SPAN class="code-quote">";version="</SPAN>1.4",org.apache.tu
scany.sca.assembly.builder;uses:="org.apache.tuscany.sca.assembly,org
.apache.tuscany.sca.definitions,org.apache.tuscany.sca.core,org.apach
e.tuscany.sca.monitor,org.apache.tuscany.sca.interfacedef,org.apache.
tuscany.sca.extensibility<SPAN class="code-quote">";version="</SPAN>1.4"
Private-Package: org.apache.tuscany.sca.assembly.builder.impl;version=
<SPAN class="code-quote">"1.4"</SPAN>
Tool: Bnd-0.0.255
Bundle-Name: Apache Tuscany SCA Assembly Model
Created-By: 1.6.0_07 (Sun Microsystems Inc.)
Bundle-Vendor: The Apache Software Foundation
Bundle-Version: 1.4
Bnd-LastModified: 1225397097203
Bundle-ManifestVersion: 2
Bundle-License: http:<SPAN class="code-comment">//www.apache.org/licenses/LICENSE-2.0.txt
</SPAN>Bundle-Description: Apache Tuscany SCA Assembly Model
Import-Package: javax.xml.namespace,javax.xml.parsers,javax.xml.transf
orm,javax.xml.transform.dom,javax.xml.transform.sax,javax.xml.xpath,o
rg.apache.tuscany.sca.assembly;version=<SPAN class="code-quote">"1.4"</SPAN>,org.apache.tuscany.sca.a
ssembly.builder;version=<SPAN class="code-quote">"1.4"</SPAN>,org.apache.tuscany.sca.assembly.impl;ve
rsion=<SPAN class="code-quote">"1.4"</SPAN>,org.apache.tuscany.sca.core;version=<SPAN class="code-quote">"1.4"</SPAN>,org.apache.tusc
any.sca.definitions;version=<SPAN class="code-quote">"1.4"</SPAN>,org.apache.tuscany.sca.extensibilit
y;version=<SPAN class="code-quote">"1.4"</SPAN>,org.apache.tuscany.sca.interfacedef;version=<SPAN class="code-quote">"1.4"</SPAN>,org
.apache.tuscany.sca.monitor;version=<SPAN class="code-quote">"1.4"</SPAN>,org.apache.tuscany.sca.poli
cy;version=<SPAN class="code-quote">"1.4"</SPAN>,org.apache.tuscany.sca.policy.util;version=<SPAN class="code-quote">"1.4"</SPAN>,org
.w3c.dom,org.xml.sax,junit.framework;resolution:=optional,org.apache.
tuscany.sca.interfacedef.impl;version=<SPAN class="code-quote">"1.4"</SPAN>;resolution:=optional,org.
junit;resolution:=optional
Bundle-SymbolicName: org.apache.tuscany.sca.assembly
Bundle-DocURL: http:<SPAN class="code-comment">//www.apache.org/</SPAN>
</PRE>
</DIV></DIV>
<H2><A name="OSGiAwareProgramminginTuscany-TweakingtheOSGimanifest"></A>Tweaking the OSGi manifest</H2>
<P> Eclipse PDE provides good tooling for editing and maintaining OSGi manifest files. There are various scenarios we might need to tweak the OSGi manifest manualy :</P>
<UL>
<LI>Updating imported/exported packages</LI>
<LI>Marking test dependencies optional
<UL>
<LI>Avoid issues when tests have references to external packages</LI>
</UL>
</LI>
</UL>
<P> <SPAN class="image-wrap" style=""><IMG src="osgi-aware-programming-in-tuscany.data/osgi_manifest_editor.jpg" style="border: 0px solid black"></SPAN></P>
<H2><A name="OSGiAwareProgramminginTuscany-PDEintegrationoftuscanymodules"></A>PDE integration of tuscany modules</H2>
<P>1) We generate the .classpath from maven dependencies.</P>
<P>2) For maven compile/provided dependencies, the modules explicit references <BR>
these dependencies via packages. We define corresponding Import-Package <BR>
header in the MANIFEST.MF for OSGi, and these get resolved to other bundles <BR>
that export the matching packages. This magic comes from the <BR>
"org.eclipse.pde.core.requiredPlugins" classpath container which is <BR>
contributed by the Eclipse PDE. The classpath container resolves the OSGi <BR>
dependencies such as Import-Package or Required-Bundle and automatically add <BR>
the required bundles to the classpath as we see in Eclipse project under the <BR>
"Plugin Dependencies".</P>
<P>3) The exported packages come from three types of sources:</P>
<UL>
<LI>System packages (exported by the System Bundle, i.e., org.eclipse.osgi).<BR>
Different JDK levels have different list of system packages, for example, <BR>
javax.xml.stream is not in J2SE-1.5 but in JSEJava-1.6. You can find the <BR>
complete list by looking the .profile files within osgi-<version>.jar.</LI>
<LI>Tuscany modules in the Eclipse workspace. The classpath entry will be<BR>
listed as a project under "Plugin Dependencies"</LI>
<LI>3rd-party jars (already as OSGi bundles contributed by the target<BR>
platform). The classpath entry will be listed as a jar under "Plugin <BR>
Dependencies"</LI>
</UL>
<P>4) For maven runtime dependencies, there is no corresponding Import-Package <BR>
and the dependencies are used in runtime. Ideally in OSGi, they could be a <BR>
Required-Bundle or a bundle available at runtime. To run the project in JSE <BR>
inside Eclipse, we generate an explicit classpath entry.</P>
<P>5) For maven test dependencies, there are two types: one is for test <BR>
compilation and the other for test runtime. For the first type, we use <BR>
optional Import-Package to pull in the dependencies if the same project has <BR>
the compile dependency for the same artifact. Otherwise, we generate an <BR>
explicit classpath entry for JSE testing.</P>
<P>6) For test cases which require extra dependencies in addition to the <BR>
compile/provided/runtime dependencies for the main code, they probably <BR>
should not be unit tests. We need to consider how to move them into the <BR>
itest bucket.</P>
</DIV>
</DIV>
</DIV>
</TD>
</TR>
</TABLE>
<!-- footer -->
<TABLE border="0" cellpadding="2" cellspacing="0" width="100%">
<TR>
<TD align="left" valign="middle" class="footer">
<IMG src="http://static.delicious.com/img/delicious.small.gif" height="10" width="10" alt="Delicious">
<A href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title),'delicious','toolbar=no,width=550,height=550'); return false;">Bookmark this on Delicious</A>
<IMG src="http://digg.com/img/badges/16x16-digg-guy.gif" width="16" height="16" alt="Digg!">
<A href="" onclick="window.open('http://digg.com/submit?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)+'&topic=programming');">Digg this</A>
<!-- Slicker, but no text
<script type="text/javascript">
digg_skin = 'icon';
digg_window = 'new';
digg_title = 'Apache Geronimo v2.2 Documentation : OSGi Aware Programming in Tuscany';
digg_topic = 'programming';
</script>
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script>
-->
</TD>
<TD align="right" valign="middle" class="footer">
<A href="http://cwiki.apache.org/GMOxPMGT/geronimo-privacy-policy.html">Privacy Policy</A> -
Copyright © 2003-2010, The Apache Software Foundation, Licensed under <A href="http://www.apache.org/licenses/LICENSE-2.0">ASL 2.0.</A>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
|