cayenne-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cristiano Ghersi <cristiano.ghe...@abodata.com>
Subject Re: Cayenne under OSGi
Date Thu, 28 Feb 2013 09:19:28 GMT
Hi Andrus,

I know you have been very busy with the new upcoming release of Cayenne.

I'd like to know if and when we can resume the task of Cayenne
OSGi-fication.

I'm at your disposal for every clarification.

Thank you very much
Best
Cristiano

2013/2/1 Cristiano Ghersi <cristiano.ghersi@abodata.com>

> Hi Andrus,
>
> given your re-engineering of the structure, perhaps I can tell you the
> changes we have plugged in in order to make the stuff work. They are quite
> simple changes to the code, so perhaps is simpler for you to add these
> pieces of code than trying to cope with the complete structure.
>
> We just added ClassRegistry class in the *org.apache.cayenne.di.spi*
>  package.
> Moreover, the class *org.apache.cayenne.di.spi.DefaultAdhocObjectFactory* has
> also been modified to be able to search in the ClassRegistry for classes:
>
> public Class<?> getJavaClass(String className) throws ClassNotFoundException {
>
>                 // is there a better way to get array class from string name?
>
>                 if (className == null) {
>                         throw new ClassNotFoundException("Null class name");
>                 }
>
>                 ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
>
>                 if (classLoader == null) {
>                         classLoader = DefaultAdhocObjectFactory.class.getClassLoader();
>                 }
>
>                 //first for OSGi Environment: look for class in registry.
>                 //try with the class loader registry
>                 Class<?> registryClass = ClassRegistry.getClassByName(className);
>                 if (registryClass != null) {
>                         try {
>                                 return registryClass.getClassLoader().loadClass(className);
>                         }
>                         catch (ClassNotFoundException cnfe) {
>                         }
>                 }
>
>                 // use custom logic on failure only, assuming primitives and arrays are
not that
>                 // common
>                 try {
>                         return Class.forName(className, true, classLoader);
>                 }
>
>                 if (!className.endsWith("[]")) {
>                         if ("byte".equals(className)) {
>                                 return Byte.TYPE;
>                         }
>                         ...}
>
>
>
>
> Generate an OSGi Bundle
>
>
> To generate an OSGi bundle some changes are needed in the *pom.xml*. First of all it
is necessary to change the *packaging* type of the project from *jar* to *bundle* as it is
show in this snippet:
>
> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
>         <modelVersion>4.0.0</modelVersion>
>         <parent>
>                 <groupId>org.apache.cayenne</groupId>
>                 <artifactId>cayenne-parent</artifactId>
>                 <version>3.1B2-SNAPSHOT</version>
>                 <relativePath>../../pom.xml</relativePath>
>         </parent>
>         <groupId>org.apache.cayenne.osgi</groupId>
>         <artifactId>cayenne-osgi</artifactId>
>         <name>Cayenne OSGified</name>     <packaging>bundle</packaging>
 <url>http://maven.apache.org</url>
>
> Then it is necessary to add a *plugin* to the *build* section:
>
> <plugins>
>         ...
>
> <plugin>
>                 <groupId>org.apache.felix</groupId>
>                 <artifactId>maven-bundle-plugin</artifactId>
>                 <version>2.3.7</version>
>                 <extensions>true</extensions>
>                 <configuration>
>                         <instructions>
>                                 <Export-Package>org.apache.cayenne, org.apache.cayenne.*</Export-Package>
>                                 <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
>                         </instructions>
>                 </configuration>
>         </plugin>
>
>         ...</plugins>
>
> Finally you can generate the bundle jar
>
> $ cd cayenne-osgi # or navigate to the root directory of the cayenne osgi project
> $ mvn org.apache.felix:maven-bundle-plugin:bundle
>
> The bundle jar can be found in *cayenne-osgi/target/cayenne-osgi.jar.*
>
> *
> *
>
> *
> *
>
> To use the Cayenne OSGi bundle the following steps must be performed:
>
>    1. Import the .jar bundle generated with the above procedure
>    2. Create and import a Cayenne *dependencies* bundle containing all
>    the .jar files needed to satisfy the import packages of Cayenne bundle (the
>    ones added to folder Cayenne-Dependencies folder in the github repo)
>    3. Create a Fragment bundle (setting as the host Cayenne bundle) for
>    each cayenne project. In the *src* folder of the fragment add the two
>    cayenne xml files.
>
>
> Hope this can help the integration.
>
> Let me know if you need further clarification, I'm at complete disposal.
>
> Best
> cghersi
>
>
>
> 2013/2/1 Andrus Adamchik <andrus@objectstyle.org>
>
>> Hi cghersi,
>>
>> Thanks!
>>
>> Trying to make sense of the GitHub project structure and what is
>> different from Cayenne. From what I can tell we need this piece in the pom:
>>
>>         <plugin>
>>                 <groupId>org.apache.felix</groupId>
>>                 <artifactId>maven-bundle-plugin</artifactId>
>>                 <version>2.3.7</version>
>>                 <extensions>true</extensions>
>>                 <configuration>
>>                         <instructions>
>>                                 <Export-Package>org.apache.cayenne,
>> org.apache.cayenne.*</Export-Package>
>>
>> <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
>>                         </instructions>
>>                 </configuration>
>>         </plugin>
>>
>> and also the META-INF dir (
>> https://github.com/cristianoghersi/CayenneOSGi/tree/master/cayenne-osgi/META-INF)
?
>>
>> Or is META-INF generated?
>>
>> Also integrating this into our convoluted build structure will be a
>> challenge. One of the 3.2 undeclared goals is simplifying the build
>> structure, so maybe once we start looking into it, we might consider the
>> OSGi aspect. And in any event it is very helpful for us, even we can't
>> simply patch Cayenne from what's on the GitHub. It gives a clear idea of
>> what we need to do to make ours jars OSGi-friendly.
>>
>> Cheers,
>> Andrus
>>
>> On Jan 31, 2013, at 3:42 PM, Cristiano Ghersi <
>> cristiano.ghersi@abodata.com> wrote:
>> > Good morning,
>> >
>> > My company (Abodata, www.abodata.com) has ported Cayenne into OSGi
>> > environment, and we would like to contribute to Cayenne project with
>> this
>> > enhancement as I posted under user mailing list on October 2012.
>> >
>> > Following your instructions, we have uploaded the full content under the
>> > github repo:
>> > https://github.com/cristianoghersi/CayenneOSGi
>> >
>> > Basically, we have packaged the source code of 3.1 version into an OSGi
>> > bundle called cayenne-osgi, adding some stuff to manage the particular
>> > classloading features of OSGi.
>> > Then we added also another bundle, called Cayenne-3.1-Dependencies, that
>> > packages all the required dependencies.
>> >
>> > I'm at complete disposal for every clarification you need.
>> >
>> > I'll wait for your feedback.
>> >
>> > Best
>> > cghersi
>>
>>
>>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message