Tuesday, April 23, 2013

Generating p2-repo for custom WSO2 Features, and Components

Here, I'm going to discuss how to generate a p2-repo for custom, user-written WSO2 components, and features. This can be easily achieved using the maven plugin, carbon-p2-plugin, that WSO2 have written.
First, you may have a look at Creating-your-own-wso2-carbon-components webinar to know how to write carbon components, and a feature for those components. It covers quite a lot of basics, and best practices as well.
Now, to install these features to WSO2 products like WSO2 Enterprise Service Bus, you need to generate a p2-repository. Then, you can add that p2-repo via the "Feature Management" utility in management console, and install the features you want. p2-repo concept comes from the underline Eclipse equinox project that WSO2 products use. In the following I will tell you how to generate a p2-repo for your features.
  • Simply create a new maven project (packaging: pom)
  • Add carbon-p2-plugin as a maven plugin
  • Then set the features you want to publish under the carbon-p2-plugin plugin configuration as shown in the following sample pom.xml.  
  • This sample pom.xml was copied from the p2-repo generation pom.xml of carbon 4.1.0, and I simplified it for clarity.
  • There are two sample feature definitions I have specified. Replace those featureArtifactDef with your own feature definitions. The format is $groupId:$artifactId:$version.

I have tested this pom file, and it worked for me just fine. 
When you build this via maven, maven creates the target/p2-repo directory. This has the p2-repository which contains the complete p2-repo including artifacts.jar and content.jar. You can just use this folder to install features, or you can host it somewhere. There're no special requirements on hosting.

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">


    <name>WSO2 Carbon - Feature Repository</name>


<!-- change the featureArtifactDef to match your needs -->