Saturday, February 1, 2014

Merge WSO2 Carbon products using Maven


It's a common requirement for users of WSO2 to combine multiple WSO2 products together everything can be run within one JVM instance. Because of component architecture of WSO2 Carbon, you can combine features from several into one product which would help some deployments. Some of the common products that get merged together are AS + DSS + BPS, ESB + IS, BAM + CEP. The default way to install products/features is to use the 'Feature Manager' in the management console. But users might want to merge products via Apache Maven. This is done by creating a maven pom.xml, and leveraging carbon-p2-plugin.

Following steps guide you on how to create merge features from different products together.

Pre-requisites -

Apache Maven 3.0.x and Apache Ant are required.

Steps -

  1.  Create a directory, and add the following in a file named pom.xml. Let's call this directory as $BASE_DIR
  2.  Download the P2-repo at http://dist.wso2.org/p2/carbon/releases/turing.tar.gz
  3.  Extract the turing.tar.gz to $BASE_DIR/p2-repo. Now, the content.jar should be located at $BASE_DIR/p2-repo/content.jar
  4.  Add the features you want additionally to the pom.xml. The sample contains two features - org.wso2.carbon.webapp.mgt.feature.group, and org.wso2.carbon.logging.mgt.feature.group. The feature listings should look like the following. The features needed for each product can be found under the p2-profile-gen/pom.xml. For ex. the AS features - https://svn.wso2.org/repos/wso2/carbon/platform/branches/turing/products/as/5.2.1/modules/p2-profile-gen/pom.xml
            <feature>
                <id>org.wso2.carbon.webapp.mgt.feature.group</id>
                <version>${carbon.platform.version}</version>
            </feature> 
    
  5. Enter the command `mvn clean install`
  6. Your combined product will be built at $BASE_DIR/target/wso2carbon-x.x.x.


    <?xml version="1.0" encoding="utf-8"?>
    <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/maven-v4_0_0.xsd">
    <parent>
        <groupId>org.wso2.appserver</groupId>
        <artifactId>wso2appserver-parent</artifactId>
        <version>5.2.0</version>
    </parent>
    
    <modelVersion>4.0.0</modelVersion>
    <artifactId>wso2product-p2-gen</artifactId>
    <packaging>pom</packaging>
    <name>WSO2 Product Profile Generation</name>
    <url>http://wso2.org</url>
    
    <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.8</version>
            <inherited>false</inherited>
            <executions>
                <execution>
                    <id>1-unpack-p2-agent-distribution</id>
                    <phase>test</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>org.wso2.carbon</groupId>
                                <artifactId>wso2carbon-core</artifactId>
                                <version>${carbon.kernel.version}</version>
                                <type>zip</type>
                                <overWrite>true</overWrite>
                                <outputDirectory>target</outputDirectory>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
                <execution>
                    <id>unpack-equinox-executable</id>
                    <phase>test</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>org.eclipse.equinox</groupId>
                                <artifactId>org.eclipse.equinox.executable</artifactId>
                                <version>3.5.0.v20110530-7P7NFUFFLWUl76mart</version>
                                <type>zip</type>
                                <overWrite>true</overWrite>
                                <outputDirectory>target</outputDirectory>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.wso2.maven</groupId>
            <artifactId>carbon-p2-plugin</artifactId>
            <version>${carbon.p2.plugin.version}</version>
            <executions>
              <execution>
                    <id>3-p2-profile-generation</id>
                    <phase>package</phase>
                    <goals>
                        <goal>p2-profile-gen</goal>
                    </goals>
                <configuration>
                    <profile>default</profile>
                    <metadataRepository>file:${basedir}/p2-repo</metadataRepository>
                    <artifactRepository>file:${basedir}/p2-repo</artifactRepository>
                    <destination>
                        ${basedir}/target/wso2carbon-core-${carbon.kernel.version}/repository/components
                    </destination>
                    <deleteOldProfileFiles>true</deleteOldProfileFiles>
                    <features>
                        <!-- ### Add your features here ### -->
                        <feature>
                            <id>org.wso2.carbon.logging.mgt.feature.group</id>
                            <version>${carbon.platform.version}</version>
                        </feature>
    
                        <feature>
                            <id>org.wso2.carbon.webapp.mgt.feature.group</id>
                            <version>${carbon.platform.version}</version>
                        </feature>
    
                    </features>
                </configuration>
              </execution>
    
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <configuration>
                        <tasks>
                            <replace token="false" value="true"
                                     dir="target/wso2carbon-core-${carbon.kernel.version}/repository/components">
                                <include name="**/bundles.info"/>
                            </replace>
                        </tasks>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
    </build>
    <properties>
       <carbon.platform.version>4.2.0</carbon.platform.version>
       <carbon.kernel.version>4.2.0</carbon.kernel.version>
    </properties>
    
    <repositories>
         <repository>
            <id>wso2-nexus</id>
            <name>WSO2 internal Repository</name>
            <url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>daily</updatePolicy>
                <checksumPolicy>ignore</checksumPolicy>
            </releases>
        </repository>
    </repositories>
    
    <pluginRepositories>
        <pluginRepository>
            <id>wso2-maven2-repository-1</id>
            <url>http://dist.wso2.org/maven2</url>
        </pluginRepository>
        <pluginRepository>
            <id>wso2-maven2-repository-2</id>
            <url>http://dist.wso2.org/snapshots/maven2</url>
        </pluginRepository>
     </pluginRepositories>
    </project>