<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.solutions.identity</groupId>
        <artifactId>identity-solution-parent</artifactId>
        <version>1.0</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>wso2-identity-solution</artifactId>
    <packaging>pom</packaging>
    <name>Identity Solution : Distribution</name>

    <profiles>
        <profile>
            <id>release</id>
            <activation>
                <property>
                    <name>release</name>
                </property>
            </activation>

            <build>
                <filters>
                    <filter>src/assemble/filter.properties</filter>
                </filters>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>2.0-alpha-4</version>
                        <executions>
                            <execution>
                                <id>unpack</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                                <configuration>
                                    <artifactItems>
                                        <!--<artifactItem>
                                            <groupId>org.wso2.solutions.identity</groupId>
                                            <artifactId>httpd-relying-party</artifactId>
                                            <version>${pom.version}</version>
                                            <type>zip</type>
                                            <overWrite>true</overWrite>
                                            <outputDirectory>
                                                target/httpd-relying-party-zip
                                            </outputDirectory>
                                        </artifactItem>-->
                                        <artifactItem>
                                            <groupId>org.wso2.wsas</groupId>
                                            <artifactId>wso2wsas</artifactId>
                                            <version>${wsas.version}</version>
                                            <type>zip</type>
                                            <overWrite>true</overWrite>
                                            <outputDirectory>${dir.build}</outputDirectory>
                                        </artifactItem>
                                    </artifactItems>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.1</version>
                        <executions>
                            <execution>
                                <id>build-javadoc</id>
                                <phase>process-classes</phase>
                                <configuration>
                                    <tasks>
                                        <!-- TODO This filtering should be removed once the filtering bug fixed in Mvn -->
                                        <echo message="############## Initialize filter tokens #################"/>
                                        <filter token="wso2is_version" value="${identity.solution.version}"/>
                                        <filter token="wso2wsas_version" value="${wsas.version}"/>
                                        <filter token="bcprov_jdk13_version" value="${bcprov.jdk13.version}"/>
                                        <filter token="bcprov_jdk15_version" value="${bcprov.jdk15.version}"/>

                                        <mkdir dir="${basedir}/target/documentation" />
                                        <copy todir="target/documentation" filtering="on">
                                            <fileset dir="../../target/site/documentation">
                                                <include name="**/**.html"/>
                                                <include name="**/**.css"/>
                                                <include name="**/**.xsl"/>
                                                <include name="**/**.js"/>
                                            </fileset>
                                        </copy>
                                        <copy todir="target/documentation">
                                            <fileset dir="../../target/site/documentation">
                                                <include name="**/**.png"/>
                                                <include name="**/**.gif"/>
                                                <include name="**/**.jpg"/>
                                            </fileset>
                                        </copy>

                                        <javadoc packagenames="org.wso2.*"
                                                 overview="../../etc/copyright.html"
                                                 stylesheetfile="../../etc/JavadocStyles.css"
                                                 destdir="../../target/site/documentation/apidocs"
                                                 author="true"
                                                 breakiterator="true"
                                                 version="true"
                                                 use="true"
                                                 windowtitle="WSO2 Identity Solution API">

                                            <sourcepath>
                                                <dirset dir="../..">
                                                    <include
                                                            name="**/identity-provider/src/main/java"/>
                                                    <include
                                                            name="**/token-verifier-core/src/main/java"/>
                                                    <include name="**/base/src/main/java"/>
                                                </dirset>
                                            </sourcepath>

                                            <classpath refid="maven.dependency.classpath"/>
                                            <classpath refid="maven.compile.classpath"/>
                                            <classpath refid="maven.runtime.classpath"/>

                                        </javadoc>
                                    </tasks>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>unpack-httpd-relying-party</id>
                                <phase>package</phase>
                                <configuration>
                                    <tasks>
                                        <mkdir dir="target"/>
                                        <copy file="../identity-provider/conf/hibernate.properties"
                                              tofile="target/hibernate.properties"/>

                                        <echo message="################# Create Database ####################"/>

                                        <property name="sqlOutput"
                                                  value="target/tmp/schema-export.sql"/>
                                        <property name="dbURL"
                                                  value="jdbc:derby:${basedir}/${dir.build.wsas}/database/WSO2IDENTITY_DB;create=true"/>

                                        <path id="base.hibernate.classpath">
                                            <path refid="maven.compile.classpath"/>
                                            <pathelement location="../base/target/classes"/>
                                            <pathelement location="../identity-provider/target/classes"/>
                                        </path>

                                        <path id="hibernate.classpath">
                                            <path refid="base.hibernate.classpath"/>
                                            <fileset dir="${dir.build.wsas}/lib">
                                                <include name="**/*.jar"/>
                                            </fileset>
                                        </path>

                                        <taskdef name="SchemaExport"
                                                 classname="org.hibernate.tool.hbm2ddl.SchemaExportTask"
                                                 classpathref="hibernate.classpath"/>

                                        <macrodef name="create-database">
                                            <attribute name="sqlOutput" default="."/>
                                            <attribute name="dbURL" default="."/>
                                            <attribute name="userid" default="wso2is"/>
                                            <attribute name="password" default="wso2is"/>
                                            <sequential>
                                                <SchemaExport
                                                        properties="${basedir}/target/hibernate.properties"
                                                        quiet="yes"
                                                        create="yes"
                                                        text="no"
                                                        drop="no"
                                                        delimiter=";"
                                                        output="@{sqlOutput}">
                                                    <fileset
                                                            file="../identity-provider/conf/wso2identity.hbm.xml"/>
                                                </SchemaExport>

                                                <sql driver="org.apache.derby.jdbc.EmbeddedDriver"
                                                     url="@{dbURL}"
                                                     userid="@{userid}" password="@{password}"
                                                     autocommit="true" onerror="continue">
                                                    <classpath>
                                                        <path refid="hibernate.classpath"/>
                                                    </classpath>
                                                    <fileset file="@{sqlOutput}"/>
                                                </sql>
                                            </sequential>
                                        </macrodef>

                                        <create-database sqlOutput="${sqlOutput}" dbURL="${dbURL}"/>
                                        <delete file="target/tmp/schema-export.sql"/>

                                        <echo message="##################### END ############################"/>

                                        <!-- Build samples -->
                                        <echo message="########### Create Default User Database ##############"/>
                                        <sql driver="org.apache.derby.jdbc.EmbeddedDriver"
                                             url="jdbc:derby:${basedir}/${dir.build.wsas}/database/WSO2IDENTITY_SAMPLE_DB;create=true"
                                             userid="wso2is" password="wso2is"
                                             autocommit="true" onerror="continue">
                                            <classpath>
                                                <path refid="hibernate.classpath"/>
                                            </classpath>
                                            <fileset file="../samples/identity-provider/db.sql"/>
                                        </sql>
                                        <echo message="##################### END ############################"/>
 
                                        <echo message="########### Create Default User Database ##############"/>
                                        <sql driver="org.apache.derby.jdbc.EmbeddedDriver"
                                             url="jdbc:derby:${basedir}/${dir.build.wsas}/database/WSO2IDENTITY_AC_SAMPLE_DB;create=true"
                                             userid="wso2is" password="wso2is"
                                             autocommit="true" onerror="continue">
                                            <classpath>
                                                <path refid="hibernate.classpath"/>
                                            </classpath>
                                            <fileset file="../samples/access-control/db.sql"/>
                                        </sql>
                                        <echo message="##################### END ############################"/>

                                        <echo message="########### Create Sample User Database ##############"/>
                                        <sql driver="org.apache.derby.jdbc.EmbeddedDriver"
                                             url="jdbc:derby:${basedir}/${dir.build.wsas}/database/WSO2IDENTITY_DEFAULT_USER_DB;create=true"
                                             userid="wso2is" password="wso2is"
                                             autocommit="true" onerror="continue">
                                            <classpath>
                                                <path refid="hibernate.classpath"/>
                                            </classpath>
                                            <fileset file="../identity-provider/conf/default-store.sql"/>
                                        </sql>

                                        <echo message="##################### END ############################"/>

                                    </tasks>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <version>2.2-beta-1</version>
                        <executions>
                            <execution>
                                <id>distribution-package</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>attached</goal>
                                </goals>
                                <configuration>
                                    <descriptors>
                                        <descriptor>src/assemble/assembly-bin.xml</descriptor>
                                        <descriptor>src/assemble/assembly-src.xml</descriptor>
                                    </descriptors>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                </plugins>
            </build>

            <dependencies>
                <dependency>
                    <groupId>org.wso2.solutions.identity</groupId>
                    <artifactId>wso2is-identity-provider</artifactId>
                    <version>${pom.version}</version>
                </dependency>

                <dependency>
                    <groupId>org.wso2.commons.usermanager</groupId>
                    <artifactId>usermanager-config-annotation</artifactId>
                    <version>${usermanager.version}</version>
                </dependency>


                <dependency>
                    <groupId>org.wso2.solutions.identity</groupId>
                    <artifactId>wso2is-base</artifactId>
                    <version>${pom.version}</version>
                </dependency>

                <dependency>
                    <groupId>org.wso2.solutions.identity</groupId>
                    <artifactId>wso2is-token-verifier-core</artifactId>
                    <version>${pom.version}</version>
                </dependency>

                <dependency>
                    <groupId>org.wso2.solutions.identity</groupId>
                    <artifactId>wso2is-security-token-service</artifactId>
                    <version>${pom.version}</version>
                    <type>aar</type>
                </dependency>
                <dependency>
                    <groupId>org.wso2.solutions.identity</groupId>
                    <artifactId>wso2is-identity-mex</artifactId>
                    <version>${pom.version}</version>
                    <type>aar</type>
                </dependency>
                <dependency>
                    <groupId>org.wso2.solutions.identity</groupId>
                    <artifactId>wso2is-admin-ui</artifactId>
                    <version>${pom.version}</version>
                    <type>war</type>
                </dependency>
                <dependency>
                    <groupId>org.wso2.solutions.identity</groupId>
                    <artifactId>wso2is-user-app-ui</artifactId>
                    <version>${pom.version}</version>
                    <type>war</type>
                </dependency>

                <dependency>
                    <groupId>opensymphony</groupId>
                    <artifactId>ognl</artifactId>
                    <version>2.6.11</version>
                </dependency>

                <dependency>
                    <groupId>com.opensymphony</groupId>
                    <artifactId>xwork</artifactId>
                    <version>2.0.4</version>
                </dependency>

                <dependency>
                    <groupId>logkit</groupId>
                    <artifactId>logkit</artifactId>
                    <version>1.0.1</version>
                </dependency>

            </dependencies>

            <modules>
                <module>rp-extension-drupal</module>
                <module>rp-extension-mediawiki</module>
            </modules>


        </profile>
    </profiles>

</project>
