<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!--
 Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->
<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.carbon</groupId>
        <artifactId>carbon-kernel-parent</artifactId>
        <version>5.0.0</version>
        <relativePath>../parent/pom.xml</relativePath>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>wso2carbon-kernel</artifactId>
    <packaging>pom</packaging>
    <name>WSO2 Carbon Kernel - Distribution</name>
    <description>
        This module generates the product distribution (zip) by installing kernel core and runtime features
        and finally assembles product specific configurations files and startup scripts using assembly plugin.
    </description>
    <url>http://wso2.com</url>

    <dependencies>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon</groupId>
            <artifactId>org.wso2.carbon.launcher</artifactId>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon</groupId>
            <artifactId>org.wso2.carbon.tools</artifactId>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon</groupId>
            <artifactId>org.wso2.carbon.core.server.feature</artifactId>
            <type>zip</type>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon</groupId>
            <artifactId>org.wso2.carbon.core.runtime.feature</artifactId>
            <type>zip</type>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <inherited>false</inherited>
                <executions>
                    <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.carbon.maven</groupId>
                <artifactId>carbon-feature-plugin</artifactId>
                <executions>
                    <execution>
                        <id>p2-repo-generation</id>
                        <phase>package</phase>
                        <goals>
                            <goal>generate-repo</goal>
                        </goals>
                        <configuration>
                            <targetRepository>file:${basedir}/target/p2-repo</targetRepository>
                            <features>
                                <feature>
                                    <id>org.wso2.carbon.core.server.feature</id>
                                    <version>${carbon.kernel.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.core.runtime.feature</id>
                                    <version>${carbon.kernel.version}</version>
                                </feature>
                            </features>
                        </configuration>
                    </execution>
                    <execution>
                        <id>publishing products</id>
                        <phase>package</phase>
                        <goals>
                            <goal>publish-product</goal>
                        </goals>
                        <configuration>
                            <productConfigurationFile>${basedir}/carbon.product
                            </productConfigurationFile>
                            <executable>
                                ${basedir}/target/org.eclipse.equinox.executable_3.5.0.v20110530-7P7NFUFFLWUl76mart
                            </executable>
                            <repositoryURL>file:${basedir}/target/p2-repo</repositoryURL>

                        </configuration>
                    </execution>
                    <execution>
                        <id>materialize-product</id>
                        <phase>package</phase>
                        <goals>
                            <goal>generate-profile</goal>
                        </goals>
                        <configuration>
                            <productConfigurationFile>${basedir}/carbon.product
                            </productConfigurationFile>
                            <repositoryURL>file:${basedir}/target/p2-repo</repositoryURL>

                            <targetPath>file:${basedir}/target/WSO2Carbon</targetPath>
                            <profile>profiles/default</profile>
                        </configuration>
                    </execution>
                    <execution>
                        <id>feature-installation</id>
                        <phase>package</phase>
                        <goals>
                            <goal>install</goal>
                        </goals>
                        <configuration>
                            <profile>profiles/default</profile>
                            <repositoryURL>file:${basedir}/target/p2-repo</repositoryURL>

                            <destination>${basedir}/target/WSO2Carbon</destination>
                            <deleteOldProfileFiles>true</deleteOldProfileFiles>
                            <features>
                                <feature>
                                    <id>org.wso2.carbon.core.server.feature.group</id>
                                    <version>${carbon.kernel.version}</version>
                                </feature>
                            </features>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <configuration>
                            <tasks>
                                <replace dir="target/WSO2Carbon" token="false" value="true">
                                    <include name="**/bundles.info" />
                                </replace>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>clean_target</id>
                        <phase>install</phase>
                        <configuration>
                            <target>
                                <delete dir="target/archive-tmp" />
                                <delete dir="target/dependency-maven-plugin-markers" />
                                <delete dir="target/org.eclipse.equinox.executable-3.5.0.v20110530-7P7NFUFFLWUl76mart" />
                                <delete dir="target/p2-repo" />
                                <!-- Figure out a way to delete tmp.* files -->
                                <delete file="target/tmp" />
                                <delete dir="target/WSO2Carbon" />
                                <delete dir="target/antrun" />
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>

                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <id>distribution</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attached</goal>
                        </goals>
                        <configuration>
                            <filters>
                                <filter>${basedir}/src/assembly/filter.properties</filter>
                            </filters>
                            <descriptors>
                                <descriptor>${basedir}/src/assembly/bin.xml</descriptor>
                            </descriptors>
                            <appendAssemblyId>false</appendAssemblyId>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
