<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2016 WSO2, Inc. (http://wso2.com)
  ~
  ~ 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/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>carbon-datasources</artifactId>
        <groupId>org.wso2.carbon.datasources</groupId>
        <version>1.0.2</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <packaging>pom</packaging>

    <artifactId>wso2carbon-datasource</artifactId>
    <name>WSO2 Carbon Datasources - Distribution</name>
    <description>Install the data source feature into C5 and rebuild the pack</description>

    <dependencies>
        <dependency>
            <groupId>org.wso2.carbon</groupId>
            <artifactId>org.wso2.carbon.launcher</artifactId>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon.datasources</groupId>
            <artifactId>org.wso2.carbon.datasource.core.feature</artifactId>
            <type>zip</type>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon.jndi</groupId>
            <artifactId>org.wso2.carbon.jndi.feature</artifactId>
            <type>zip</type>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon</groupId>
            <artifactId>org.wso2.carbon.kernel.feature</artifactId>
            <type>zip</type>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon</groupId>
            <artifactId>org.wso2.carbon.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>
                <version>${carbon.feature.plugin.version}</version>
                <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.kernel.feature</id>
                                    <version>${carbon.kernel.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.runtime.feature</id>
                                    <version>${carbon.kernel.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.datasource.core.feature</id>
                                    <version>${project.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.jndi.feature</id>
                                    <version>${carbon.jndi.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-kernel-${carbon.kernel.version}/osgi</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-kernel-${carbon.kernel.version}/osgi
                            </destination>
                            <deleteOldProfileFiles>true</deleteOldProfileFiles>
                            <features>
                                <feature>
                                    <id>org.wso2.carbon.kernel.feature.group</id>
                                    <version>${carbon.kernel.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.datasource.core.feature</id>
                                    <version>${project.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.jndi.feature</id>
                                    <version>${carbon.jndi.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-kernel-${carbon.kernel.version}/osgi" 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" />
                                <delete file="target/tmp" />
                                <delete dir="target/wso2carbon-kernel-${carbon.kernel.version}" />
                                <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>
                            <descriptors>
                                <descriptor>${basedir}/bin.xml</descriptor>
                            </descriptors>
                            <appendAssemblyId>false</appendAssemblyId>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>
