You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Nicolas Delsaux <ni...@gmail.com> on 2010/04/07 11:33:44 UTC

iPOJO annotations with a maven project

Hi all,
after having run along the classical Felix tutorials (creating bundles
through maven), i was quite interested by the promises of OSGi, but a
little worried by the way dependencies were resolved. Fortunatly, my
eye felt on iPOJO. I can say I was quite pleased by the promise of IoC
between plugins (what seems to offer iPOJO) especially using
annotations, which may be a fad, but are to my mind very useful.

Before all, I must confess I'm a converted maven user, which may alter
some of my points of view.

So, I've tried to do the maven tutorial
(http://felix.apache.org/site/ipojo-hello-word-maven-based-tutorial.html)
using a well-known maven way : a superpom containing my poms basic
definitions and one module for each feature : a hello-service module,
and a hello-client one. Before all, I have to say I used this
architecture for classical Felix tutorials, and it perfectly worked.
So, my modules pom were quite light, and so were my classes.
In these classes, I defined the HelloService interface, a HelloImpl
provider (with @Component and @Provides) annotation, and a HelloClient
using @Requires annotation, as well as @Validates one to start the
hello world code.
Having done so, it seemed to me I didn't had to create a metada.xml
file, since all informations were in these annotations. Was I
theorically right ?
Well, in the facts, i was wrong since :
 - my jars METADATA.INF don't contain any of the data defined by both
parent and module maven-bundle-plugin configuration
 - the maven log don't reveal any maven-bundle-plugin execution (which
may be the reason for the lack of METADATA.INF) ... well, this one was
found and resolved : my modules didn't packaged themselves as "bundle"
... stupid of me !
 - once the above is corrected, my METADA.INF were created, my bundles
had their correct names set in felix, but the @Validate method of my
client was never called. FTR, here is my full hello client :

@Component(name="Da Hello Klient")
public class HelloClient {
	private static final Logger logger = Logger.getLogger(HelloClient.class
			.getName());

	@Requires
	private HelloService service;
	
	private String user = System.getProperty("user.name");
	
	@Validate
	public void hello() {
		logger.info(service.sayHello(user));
	}
	
	@Invalidate
	public void goodbye() {
		logger.info(service.sayGoodbye(user));
	}
}

And the associated METADATA.INF

Manifest-Version: 1.0
Export-Package: com.mycompany.hello.api
Built-By: ndx
Tool: Bnd-0.0.238
Bundle-Name: com.mycompany.hello
Created-By: Apache Maven Bundle Plugin
Bundle-Vendor: Perigee
Build-Jdk: 1.6.0_16
Bundle-Version: 0.0.1.SNAPSHOT
Bnd-LastModified: 1270632257171
Bundle-ManifestVersion: 2
Bundle-Description: Dis bonjour au monde !
Import-Package: com.mycompany.hello.api
Bundle-SymbolicName: com.mycompany.hello-service
Bundle-DocURL: http://www.mycompany.fr

So, here are my questions :
 - Do I absolutely need a metada.xml file ?
 - Is the validate method really called once all dependencies have
been resolved and my iPOJO can be started ?

Thanks

-- 
Nicolas Delsaux

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: iPOJO annotations with a maven project

Posted by Clement Escoffier <cl...@gmail.com>.
Hi,

On 08.04.2010, at 14:13, Nicolas Delsaux wrote:

> On Wed, Apr 7, 2010 at 5:15 PM, Clement Escoffier
> <cl...@gmail.com> wrote:
>> 
>> Hi,
>> 
>> 
>> So for the metadata.xml, no it's absolutely not required to have one. But in the 1.4.0, the metadata.xml allows to declare instances. (in the 1.5.0-SNAPSHOT, there is a new annotation for that).
> 
> There is something weird. Since my project is a maven one, I use the
> following dependency declaration :
> 
> 			<dependency>
> 				<groupId>org.apache.felix</groupId>
> 				<artifactId>org.apache.felix.ipojo.annotations</artifactId>
> 				<version>1.2.0</version>
> 			</dependency>
> 
> I think I'm really far from bleeding edge ;-)
> Anyway, I've already seen the metada.xml is mandatory to create
> instances. Do you have a publicly visible repository with iPOJO
> 1.5.0-SNAPSHOT for me to test annotation based instance creation ?

It is deployed on the Apache Snapshot Repository (https://repository.apache.org/content/groups/snapshots/org/apache/felix/org.apache.felix.ipojo.annotations/1.5.0-SNAPSHOT/)
This annotations is processed by the maven-ipojo-plugin 1.5.0-SNAPSHOT too.

The good news is ... the iPOJO 1.6.0 release is pretty close now :-)

Clement


>> 
>> The validate method will be call if you have declared an instance of your component. iPOJO interprets @Component as a component type declaration, so you have to declare instances. To declare instances, you can use the configu admin or the metadata.xml. In this latter case, just create a simple metadata.xml containing
>> <ipojo>
>> <instance component="....HelloClient"/>
>> </ipojo>
>> 
>> But as far as I see, the maven-ipojo-plugin was not called on your bundle. So add to your pom file the following excerpt:
>> <plugin>
>>             <groupId>org.apache.felix</groupId>
>>             <artifactId>maven-ipojo-plugin</artifactId>
>>             <version>1.4.2</version>
>>             <executions>
>>               <execution>
>>               <goals>
>>                     <goal>ipojo-bundle</goal>
>>              </goals>
>>            </execution>
>>       </executions>
>>     </plugin>
>> 
> Well, it's defined in the superpom.
>> 
>> Then, the resulting manifest should contains a specific header with a weird content. If so, your bundle was correctly manipulated, and your bundle will be managed by iPOJO.
>> 
>> Regards,
>> 
> Thanks for the advices.
> 
> --
> Nicolas Delsaux
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: iPOJO annotations with a maven project

Posted by Nicolas Delsaux <ni...@gmail.com>.
On Wed, Apr 7, 2010 at 5:15 PM, Clement Escoffier
<cl...@gmail.com> wrote:
>
> Hi,
>
>
> So for the metadata.xml, no it's absolutely not required to have one. But in the 1.4.0, the metadata.xml allows to declare instances. (in the 1.5.0-SNAPSHOT, there is a new annotation for that).

There is something weird. Since my project is a maven one, I use the
following dependency declaration :

			<dependency>
				<groupId>org.apache.felix</groupId>
				<artifactId>org.apache.felix.ipojo.annotations</artifactId>
				<version>1.2.0</version>
			</dependency>

I think I'm really far from bleeding edge ;-)
Anyway, I've already seen the metada.xml is mandatory to create
instances. Do you have a publicly visible repository with iPOJO
1.5.0-SNAPSHOT for me to test annotation based instance creation ?
>
> The validate method will be call if you have declared an instance of your component. iPOJO interprets @Component as a component type declaration, so you have to declare instances. To declare instances, you can use the configu admin or the metadata.xml. In this latter case, just create a simple metadata.xml containing
> <ipojo>
> <instance component="....HelloClient"/>
> </ipojo>
>
> But as far as I see, the maven-ipojo-plugin was not called on your bundle. So add to your pom file the following excerpt:
> <plugin>
>             <groupId>org.apache.felix</groupId>
>             <artifactId>maven-ipojo-plugin</artifactId>
>             <version>1.4.2</version>
>             <executions>
>               <execution>
>               <goals>
>                     <goal>ipojo-bundle</goal>
>              </goals>
>            </execution>
>       </executions>
>     </plugin>
>
Well, it's defined in the superpom.
>
> Then, the resulting manifest should contains a specific header with a weird content. If so, your bundle was correctly manipulated, and your bundle will be managed by iPOJO.
>
> Regards,
>
Thanks for the advices.

--
Nicolas Delsaux

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: iPOJO annotations with a maven project

Posted by Clement Escoffier <cl...@gmail.com>.
Hi,

On 07.04.2010, at 11:33, Nicolas Delsaux wrote:

> Hi all,
> after having run along the classical Felix tutorials (creating bundles
> through maven), i was quite interested by the promises of OSGi, but a
> little worried by the way dependencies were resolved. Fortunatly, my
> eye felt on iPOJO. I can say I was quite pleased by the promise of IoC
> between plugins (what seems to offer iPOJO) especially using
> annotations, which may be a fad, but are to my mind very useful.
> 
> Before all, I must confess I'm a converted maven user, which may alter
> some of my points of view.
> 
> So, I've tried to do the maven tutorial
> (http://felix.apache.org/site/ipojo-hello-word-maven-based-tutorial.html)
> using a well-known maven way : a superpom containing my poms basic
> definitions and one module for each feature : a hello-service module,
> and a hello-client one. Before all, I have to say I used this
> architecture for classical Felix tutorials, and it perfectly worked.
> So, my modules pom were quite light, and so were my classes.
> In these classes, I defined the HelloService interface, a HelloImpl
> provider (with @Component and @Provides) annotation, and a HelloClient
> using @Requires annotation, as well as @Validates one to start the
> hello world code.
> Having done so, it seemed to me I didn't had to create a metada.xml
> file, since all informations were in these annotations. Was I
> theorically right ?
> Well, in the facts, i was wrong since :
> - my jars METADATA.INF don't contain any of the data defined by both
> parent and module maven-bundle-plugin configuration
> - the maven log don't reveal any maven-bundle-plugin execution (which
> may be the reason for the lack of METADATA.INF) ... well, this one was
> found and resolved : my modules didn't packaged themselves as "bundle"
> ... stupid of me !
> - once the above is corrected, my METADA.INF were created, my bundles
> had their correct names set in felix, but the @Validate method of my
> client was never called. FTR, here is my full hello client :
> 
> @Component(name="Da Hello Klient")
> public class HelloClient {
> 	private static final Logger logger = Logger.getLogger(HelloClient.class
> 			.getName());
> 
> 	@Requires
> 	private HelloService service;
> 	
> 	private String user = System.getProperty("user.name");
> 	
> 	@Validate
> 	public void hello() {
> 		logger.info(service.sayHello(user));
> 	}
> 	
> 	@Invalidate
> 	public void goodbye() {
> 		logger.info(service.sayGoodbye(user));
> 	}
> }
> 
> And the associated METADATA.INF
> 
> Manifest-Version: 1.0
> Export-Package: com.mycompany.hello.api
> Built-By: ndx
> Tool: Bnd-0.0.238
> Bundle-Name: com.mycompany.hello
> Created-By: Apache Maven Bundle Plugin
> Bundle-Vendor: Perigee
> Build-Jdk: 1.6.0_16
> Bundle-Version: 0.0.1.SNAPSHOT
> Bnd-LastModified: 1270632257171
> Bundle-ManifestVersion: 2
> Bundle-Description: Dis bonjour au monde !
> Import-Package: com.mycompany.hello.api
> Bundle-SymbolicName: com.mycompany.hello-service
> Bundle-DocURL: http://www.mycompany.fr
> 
> So, here are my questions :
> - Do I absolutely need a metada.xml file ?
> - Is the validate method really called once all dependencies have
> been resolved and my iPOJO can be started ?

So for the metadata.xml, no it's absolutely not required to have one. But in the 1.4.0, the metadata.xml allows to declare instances. (in the 1.5.0-SNAPSHOT, there is a new annotation for that).

The validate method will be call if you have declared an instance of your component. iPOJO interprets @Component as a component type declaration, so you have to declare instances. To declare instances, you can use the configu admin or the metadata.xml. In this latter case, just create a simple metadata.xml containing
<ipojo>
<instance component="....HelloClient"/>
</ipojo>

But as far as I see, the maven-ipojo-plugin was not called on your bundle. So add to your pom file the following excerpt:
<plugin>
             <groupId>org.apache.felix</groupId>
             <artifactId>maven-ipojo-plugin</artifactId>
             <version>1.4.2</version>
             <executions>
               <execution>
               <goals>
                     <goal>ipojo-bundle</goal>
              </goals>
            </execution>
       </executions>
     </plugin>


Then, the resulting manifest should contains a specific header with a weird content. If so, your bundle was correctly manipulated, and your bundle will be managed by iPOJO.

Regards,

Clement

> 
> Thanks
> 
> -- 
> Nicolas Delsaux
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>