<?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/xsd/maven-4.0.0.xsd">
    <parent>
        <groupId>org.wso2.ues</groupId>
        <artifactId>wso2ues-parent</artifactId>
        <version>2.0.0-m2</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>wso2ues</artifactId>
    <packaging>jar</packaging>
    <name>WSO2 User Engagement Server - Distribution</name>
    <description>User Engagement Server Distribution</description>
    <dependencies>
        <dependency>
            <groupId>javax.el</groupId>
            <artifactId>el-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database.wso2</groupId>
            <artifactId>h2-database-engine</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>buildnumber-maven-plugin</artifactId>
                <configuration>
                    <format>{0,date,dd MMM yyyy}</format>
                    <items>
                        <item>timestamp</item>
                    </items>
                    <doCheck>false</doCheck>
                    <doUpdate>false</doUpdate>
                </configuration>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>create</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <inherited>false</inherited>
                <executions>
                    <execution>
                        <id>2-unpack-wso2carbon</id>
                        <phase>package</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>copy-resources</id>
                                            <phase>package</phase>
                                            <goals>
                                                <goal>copy</goal>
                                            </goals>
                                            <configuration>
                                                <artifactItems>
                                                    <artifactItem>
                                                        <groupId>org.wso2.carbon.registry</groupId>
                                                        <artifactId>RestOAuthAPI</artifactId>
                                                        <version>${patch.version.405}</version>
                                                        <type>war</type>
                                                        <overWrite>true</overWrite>
                                                        <outputDirectory>target/jaxwebapps</outputDirectory>
                                                        <destFileName>resources.war</destFileName>
                                                    </artifactItem>
                                                </artifactItems>
                                            </configuration>
                                        </execution>-->
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>3-extract-docs-from-components</id>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>
                                <property name="tempdir" value="target/docs-temp" />
                                <property name="jardir" value="target/jars" />
                                <mkdir dir="${tempdir}" />
                                <unzip dest="${tempdir}">
                                    <fileset dir="target">
                                        <include name="${project.artifactId}-${product.ues.version}.zip" />
                                    </fileset>
                                </unzip>
                                <copy todir="target/wso2carbon-core-${carbon.kernel.version}/repository/components" overwrite="true">
                                    <fileset dir="${tempdir}/${project.artifactId}-${product.ues.version}/repository/components">
                                    </fileset>
                                </copy>
                                <delete file="target/${project.artifactId}-${product.ues.version}.zip" />
                                <delete dir="${tempdir}" />
                            </tasks>
                        </configuration>
                    </execution>
                    <!-- Fix for requiring -Dsetup -->
                    <execution>
                        <id>2-identity-h2-table-gen</id>
                        <phase>package</phase>
                        <configuration>
                            <target>
                                <copy todir="target/wso2carbon-core-${carbon.kernel.version}/dbscripts/identity" overwrite="false">
                                    <fileset dir="${basedir}/../p2-profile-gen/target/wso2carbon-core-${carbon.kernel.version}/dbscripts/identity/" />
                                </copy>
                                <path id="h2.classpath">
                                    <path refid="maven.compile.classpath" />
                                </path>
                                <echo message="########### Create Identity Database ##############" />
                                <sql driver="org.h2.Driver" url="jdbc:h2:${basedir}/target/wso2carbon-core-${carbon.kernel.version}/repository/database/WSO2CARBON_DB" userid="wso2carbon" password="wso2carbon" autocommit="true" onerror="continue">
                                    <classpath>
                                        <path refid="h2.classpath" />
                                    </classpath>
                                    <fileset file="target/wso2carbon-core-${carbon.kernel.version}/dbscripts/identity/h2.sql" />
                                </sql>
                                <echo message="##################### END ########################" />
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                    <!-- End of fix -->
                    <execution>
                        <id>clean_target</id>
                        <phase>install</phase>
                        <configuration>
                            <tasks>
                                <delete dir="target/jars" />
                                <delete dir="target/*.xml" />
                                <delete dir="target/archive-tmp" />
                                <delete dir="target/dependency-maven-plugin-markers" />
                                <delete dir="target/maven-archiver" />
                                <delete dir="target/wso2carbon-core-${carbon.kernel.version}" />
                                <delete file="target/${project.artifactId}-${product.ues.version}.jar" />
                                <delete dir="target/sources" />
                                <delete dir="target/site" />
                                <delete dir="target/antrun" />
                                <delete dir="src/site" />
                                <delete dir="target/jaxwebapps" />
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <id>1-pre-dist</id>
                        <phase>test</phase>
                        <!--we are creating a temporary carbon distribution for document extracting purposes during the test phase-->
                        <goals>
                            <goal>attached</goal>
                        </goals>
                        <configuration>
                            <filters>
                                <filter>${basedir}/src/assembly/filter.properties</filter>
                            </filters>
                            <descriptors>
                                <descriptor>${basedir}/src/assembly/dist.xml</descriptor>
                            </descriptors>
                            <appendAssemblyId>false</appendAssemblyId>
                        </configuration>
                    </execution>
                    <execution>
                        <id>2-dist</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>
                                <!-- <descriptor>${basedir}/src/assembly/docs.xml</descriptor>-->
                            </descriptors>
                            <appendAssemblyId>false</appendAssemblyId>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>