OSGi Aware Programming in Tuscany (TUSCANY) edited by Luciano Resende
      Page: 
http://cwiki.apache.org/confluence/display/TUSCANY/OSGi+Aware+Programming+in+Tuscany
   Changes: 
http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=101617&originalVersion=3&revisedVersion=4






Content:
---------------------------------------------------------------------

h2.Motivation for OSGi

   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.

   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.

   In summary:
* Better class loading mechanism for our modules
* Create clean boundaries between sub-systems

h2.Tuscany and OSGi - 3rd party dependencies

   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.
 
   !osgi_3rd_party_dependencies.JPG!


h2.Tuscany and OSGi - Granularity

   The granularity used to define modules should be very familiar to all 
tuscany developers, 

   Tuscany Modules      --> OSGi Bundles
   3rd Party Libraries  --> OSGi Bundles (using unpacked wrap style bundle)

h2.Properly defining new Tuscany modules as an OSGi bundle

 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.

h4.Generating OSGi manifest with Felix maven-bundle-plugin

{code:title="configuring maven to generate the OSGi manifest"}
<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>
{code}

Below is a manifest that was generated for one of the Tuscany modules using the 
felix maven-bundle-plugin.

{code:title="OSGi Manifest (META-INF\manifest.mf"}
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";version="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";version="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";version="1.4"
Private-Package: org.apache.tuscany.sca.assembly.builder.impl;version=
 "1.4"
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://www.apache.org/licenses/LICENSE-2.0.txt
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="1.4",org.apache.tuscany.sca.a
 ssembly.builder;version="1.4",org.apache.tuscany.sca.assembly.impl;ve
 rsion="1.4",org.apache.tuscany.sca.core;version="1.4",org.apache.tusc
 any.sca.definitions;version="1.4",org.apache.tuscany.sca.extensibilit
 y;version="1.4",org.apache.tuscany.sca.interfacedef;version="1.4",org
 .apache.tuscany.sca.monitor;version="1.4",org.apache.tuscany.sca.poli
 cy;version="1.4",org.apache.tuscany.sca.policy.util;version="1.4",org
 .w3c.dom,org.xml.sax,junit.framework;resolution:=optional,org.apache.
 tuscany.sca.interfacedef.impl;version="1.4";resolution:=optional,org.
 junit;resolution:=optional
Bundle-SymbolicName: org.apache.tuscany.sca.assembly
Bundle-DocURL: http://www.apache.org/
{code}

h2.Tweaking the OSGi manifest

   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 :

* Updating imported/exported packages
* Marking test dependencies optional 
** Avoid issues when tests have references to external packages 

   !osgi_manifest_editor.jpg!





---------------------------------------------------------------------
CONFLUENCE INFORMATION
This message is automatically generated by Confluence

Unsubscribe or edit your notifications preferences
   http://cwiki.apache.org/confluence/users/viewnotifications.action

If you think it was sent incorrectly contact one of the administrators
   http://cwiki.apache.org/confluence/administrators.action

If you want more information on Confluence, or have a bug to report see
   http://www.atlassian.com/software/confluence


Reply via email to