<!--
 ~ Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 ~
 ~ WSO2 Inc. licenses this file to you 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.bps</groupId>
        <artifactId>wso2bps-parent</artifactId>
        <version>3.0.1</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>wso2bps</artifactId>
    <packaging>jar</packaging>
    <name>WSO2 BPS - Distribution</name>
    <description>WSO2 Business Process Server Distribution</description>

    <dependencies>
        <dependency>
            <groupId>bouncycastle</groupId>
            <artifactId>bcprov-jdk15</artifactId>
            <version>${bouncycastle.version}</version>
        </dependency>

        <dependency>
            <groupId>com.h2database.wso2</groupId>
            <artifactId>h2-database-engine</artifactId>
            <version>${wso2.h2.orbit.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.rampart</groupId>
            <artifactId>rampart</artifactId>
            <version>${rampart.mar.version}</version>
            <type>mar</type>
        </dependency>

        <!--<dependency>-->
        <!--<groupId>groovy</groupId>-->
        <!--<artifactId>groovy-all-1.0-jsr</artifactId>-->
        <!--<version>05</version>-->
        <!--</dependency>-->
    </dependencies>

    <properties>
        <maven.build.timestamp.format>dd MMM yyyy</maven.build.timestamp.format>
        <buildNumber>${maven.build.timestamp}</buildNumber>
        <product.version>${project.parent.version}</product.version>
    </properties>


    <build>
        <plugins>
            <!--plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <inherited>true</inherited>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin-->

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.0-alpha-4</version>
                <inherited>false</inherited>
                <executions>
                    <execution>
                        <id>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.core.patch.version}</version>
                                    <type>zip</type>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>target</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.groovy.maven</groupId>
                <artifactId>gmaven-plugin</artifactId>
                <version>1.0-rc-5</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                        <configuration>
                            <source>
                                import javax.xml.parsers.DocumentBuilder
                                import javax.xml.parsers.DocumentBuilderFactory
                                import javax.xml.transform.Transformer
                                import javax.xml.transform.TransformerFactory
                                import javax.xml.transform.dom.DOMSource
                                import javax.xml.transform.stream.StreamResult
                                import org.w3c.dom.Document
                                import org.w3c.dom.Element

                                def axis2XML = new
                                File("$pom.basedir/target/wso2carbon-core-${carbon.core.patch.version}/repository/conf/axis2.xml");
                                if (axis2XML.exists()) {
                                println "###### Editing axis2.xml of root tenant. ######";
                                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                                DocumentBuilder db = dbf.newDocumentBuilder();
                                Document doc = db.parse(axis2XML);

                                Element soapRoleEle = doc.createElement("SOAPRoleConfiguration");
                                soapRoleEle.setAttribute("isUltimateReceiver", "false");
                                Element roleEle = doc.createElement("role");
                                roleEle.setTextContent("superTenant");
                                soapRoleEle.appendChild(roleEle);
                                doc.getDocumentElement().appendChild(soapRoleEle);

                                //set up a transformer
                                TransformerFactory transfac = TransformerFactory.newInstance();
                                Transformer trans = transfac.newTransformer();

                                //create string from xml tree
                                StringWriter sw = new StringWriter();
                                StreamResult result = new StreamResult(sw);
                                DOMSource source = new DOMSource(doc);
                                trans.transform(source, result);
                                String outputXML = sw.toString();

                                OutputStream f0;
                                def buf = outputXML.getBytes();
                                f0 = new
                                FileOutputStream("$pom.basedir/target/wso2carbon-core-${carbon.core.patch.version}/repository/conf/axis2.xml");
                                for (int i = 0; i &lt; buf.length; i++) {
                                f0.write(buf[i]);
                                }
                                f0.close();
                                buf = null;
                                } else {
                                println "###### axis2.xml is not found. ######";
                                }

                            </source>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.2</version>

                <executions>
                    <execution>
                        <id>create-ode-database</id>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>
                                <echo message="######## Creating BPEL / HumanTask Archives. #########"/>
                                <property name="tempdir" value="target/samples"/>
                                <property name="bpelSampleDir" value="target/samples/bpel"/>
                                <property name="humantaskSampleDir"
                                          value="target/samples/humantask"/>
                                <mkdir dir="${tempdir}"/>
                                <mkdir dir="${bpelSampleDir}"/>
                                <mkdir dir="${humantaskSampleDir}"/>
                                <zip destfile="target/samples/bpel/CustomerInfo.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/CustomerInfo"/>
                                <zip destfile="target/samples/bpel/LoanProcess.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/LoanProcess"/>
                                <zip destfile="target/samples/bpel/LoanService.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/LoanService"/>
                                <zip destfile="target/samples/bpel/TestE4XDirect.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/TestE4XDirect"/>
                                <zip destfile="target/samples/bpel/AttachmentHandlingProcess.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/AttachmentHandlingProcess"/>
                                <zip destfile="target/samples/bpel/CreditRating.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/CreditRating"/>
                                <zip destfile="target/samples/bpel/CleanUpTest1.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/CleanUpTest1"/>
                                <zip destfile="target/samples/bpel/FlexibleAssign.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/FlexibleAssign"/>
                                <zip destfile="target/samples/bpel/helloHeaderTest.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/helloHeaderTest"/>
                                <zip destfile="target/samples/bpel/HelloWorld2.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/HelloWorld2"/>
                                <zip destfile="target/samples/bpel/MyRoleMexTestProcess.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/MyRoleMexTestProcess"/>
                                <zip destfile="target/samples/bpel/RPCClientProcess.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/RPCClientProcess"/>
                                <zip destfile="target/samples/bpel/RPCServiceProcess.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/RPCServiceProcess"/>
                                <zip destfile="target/samples/bpel/FlightReservationProcess.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/SampleCompensationHandlers/FlightReservationProcess/"/>
                                <zip destfile="target/samples/bpel/SampleEventHandler.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/SampleEventHandlers"/>
                                <zip destfile="target/samples/bpel/AdderProcess.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/SampleFaultHandler/AdderProcess/"/>
                                <zip destfile="target/samples/bpel/DivisionProcess.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/SampleFaultHandler/DivisionProcess/"/>
                                <zip destfile="target/samples/bpel/FaultHandlingSample.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/SampleFaultHandler/FaultHandlingSample/"/>
                                <zip destfile="target/samples/bpel/Async-Client.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/SampleAsynchronousProcess/Async-Client/"/>
                                <zip destfile="target/samples/bpel/Async-Server.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/SampleAsynchronousProcess/Async-Server/"/>
                                <zip destfile="target/samples/bpel/SecurePartnerBPEL.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/SecurePartnerBPEL"/>
                                <zip destfile="target/samples/bpel/TestAlarm.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/TestAlarm"/>
                                <zip destfile="target/samples/bpel/TestAssignActivity1.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/TestAssignActivity1"/>
                                <zip destfile="target/samples/bpel/TestAssignDate.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/TestAssignDate"/>
                                <zip destfile="target/samples/bpel/TestCombineUrl.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/TestCombineUrl"/>
                                <zip destfile="target/samples/bpel/TestComposeUrl.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/TestComposeUrl"/>
                                <zip destfile="target/samples/bpel/TestCorrelationUnique.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/TestCorrelationUnique"/>
                                <zip destfile="target/samples/bpel/TestCounter.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/TestCounter"/>
                                <zip destfile="target/samples/bpel/TestE4XDirect.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/TestE4XDirect"/>
                                <zip destfile="target/samples/bpel/TestExpandTemplate.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/TestExpandTemplate"/>
                                <zip destfile="target/samples/bpel/TestFlowLinks.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/TestFlowLinks"/>
                                <zip destfile="target/samples/bpel/TestForEach.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/TestForEach"/>
                                <zip destfile="target/samples/bpel/TestIf.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/TestIf"/>
                                <zip destfile="target/samples/bpel/TestIgnoreMissingFromData.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/TestIgnoreMissingFromData"/>
                                <zip destfile="target/samples/bpel/TestPickOneWay.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/TestPickOneWay"/>
                                <zip destfile="target/samples/bpel/TestProcessProperties.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/TestProcessProperties"/>
                                <zip destfile="target/samples/bpel/TestPubSubInProc.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/TestPubSubInProc"/>
                                <zip destfile="target/samples/bpel/TestRepeatUntil.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/TestRepeatUntil"/>
                                <zip destfile="target/samples/bpel/TestRESTProcess.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/TestRESTProcess"/>
                                <zip destfile="target/samples/bpel/TestSplit.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/TestSplit"/>
                                <zip destfile="target/samples/bpel/TestThrowCatchFaultHandling.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/TestThrowCatchFaultHandling"/>
                                <zip destfile="target/samples/bpel/TestWhile.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/TestWhile"/>
                                <zip destfile="target/samples/bpel/TestXslTransform.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/TestXslTransform"/>
                                <zip destfile="target/samples/bpel/ClaimsApprovalProcess.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/ClaimsApprovalProcess"/>
                                <zip destfile="target/samples/bpel/DynPartner.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/DynPartner"/>
                                <zip destfile="target/samples/bpel/XMLAttributeProcess.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/XMLAttributeProcess"/>
                                <zip destfile="target/samples/bpel/Async-Server.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/SampleAsynchronousProcess/Async-Server"/>
                                <zip destfile="target/samples/bpel/Async-Client.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/SampleAsynchronousProcess/Async-Client"/>
                                <zip destfile="target/samples/bpel/SecuredWithServiceDescriptorProcess.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/SecuredWithServiceDescriptorProcess"/>
                                <zip destfile="target/samples/bpel/KPISample.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/KPISample"/>
                               <zip destfile="target/samples/bpel/AdminServiceInvokeSample.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/bpel/2.0/AdminServiceInvokeSample"/>
                                <!--  Copying Human Tasks Sample -->

                                <zip destfile="target/samples/humantask/ClaimsApprovalTask.zip"
                                     basedir="${basedir}/../samples/product/src/main/resources/humantask/ClaimsApprovalTask"/>

                                <echo message="######### Copying Samples Services are temporary skipped###########"/>


                                <path id="h2.classpath">
                                    <path refid="maven.compile.classpath"/>
                                </path>

                                <echo
                                        message="########### Create BPS Database ##############"/>
                                <sql
                                        driver="org.h2.Driver"
                                        url="jdbc:h2:${basedir}/target/database/jpadb;create=true"
                                        userid="wso2carbon" password="wso2carbon" autocommit="true"
                                        onerror="continue">
                                    <classpath>
                                        <path refid="h2.classpath"/>
                                    </classpath>
                                    <fileset
                                            file="${basedir}/sql/h2.sql"/>
                                </sql>

                                <echo
                                        message="##################### END ############################"/>
                            </tasks>
                        </configuration>
                    </execution>
                    <execution>
                        <id>extract-docs-from-components</id>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>
                                <property name="tempdir" value="target/docs-temp"/>
                                <mkdir dir="${tempdir}"/>
                                <unzip dest="${tempdir}">
                                    <fileset dir="target">
                                        <include
                                                name="${project.artifactId}-${project.version}.zip"/>
                                    </fileset>
                                </unzip>
                                <copy todir="target/wso2carbon-core-${carbon.core.patch.version}/repository/components"
                                      overwrite="true">
                                    <fileset
                                            dir="${tempdir}/${project.artifactId}-${project.version}/repository/components">
                                    </fileset>
                                </copy>
                                <delete file="target/${project.artifactId}-${project.version}.zip"/>
                                <delete dir="${tempdir}"/>
                                <mkdir dir="${tempdir}"/>
                                <unzip dest="${tempdir}">
                                    <fileset
                                            dir="target/wso2carbon-core-${carbon.core.patch.version}/repository/components/plugins/">
                                        <include name="*.ui*.jar"/>
                                    </fileset>
                                </unzip>
                                <move todir="${tempdir}/web/" includeemptydirs="false">
                                    <fileset dir="${tempdir}/web/">
                                        <exclude name="**/yui/**"/>
                                        <exclude name="**/ajax/**"/>
                                        <exclude name="**/WEB-INF/**"/>
                                        <include name="**/*.html"/>
                                    </fileset>
                                    <mapper type="glob" from="*.html" to="*.xml"/>
                                </move>
                                <mkdir dir="src/site/xdoc"/>
                                <copy todir="src/site/xdoc" overwrite="false"
                                      includeemptydirs="false">
                                    <fileset dir="${tempdir}/web">
                                        <exclude name="**/yui/**"/>
                                        <exclude name="**/ajax/**"/>
                                        <exclude name="**/WEB-INF/**"/>
                                        <exclude name="**/*.html"/>
                                        <exclude name="**/*.js"/>
                                        <exclude name="**/*.jsp"/>
                                        <exclude name="**/*.xsl"/>
                                        <exclude name="**/codepress.xml"/>
                                        <exclude name="**/template.xml"/>
                                        <exclude name="*.*"/>
                                    </fileset>
                                </copy>
                                <copy todir="src/site" overwrite="false" includeemptydirs="false">
                                    <fileset dir="../../docs">
                                        <exclude name="**/user-mgt-actdir.xml"/>
                                        <exclude name="**/user-mgt-jdbc.xml"/>
                                        <exclude name="**/user-mgt-ldap.xml"/>
                                    </fileset>
                                </copy>
                                <copy todir="target/site/" overwrite="false"
                                      includeemptydirs="false">
                                    <fileset dir="src/site/xdoc/">
                                        <include name="**/images/*.*"/>
                                    </fileset>
                                </copy>
                                <delete dir="${tempdir}"/>

                            </tasks>
                        </configuration>
                    </execution>
                    <execution>
                        <id>clean_target</id>
                        <phase>install</phase>
                        <configuration>
                            <tasks>
                                <delete dir="target/archive-tmp"/>
                                <delete dir="target/dependency-maven-plugin-markers"/>
                                <delete dir="target/maven-archiver"/>
                                <delete dir="target/wso2carbon-core-${carbon.core.patch.version}"/>
                                <delete file="target/${project.artifactId}-${project.version}.jar"/>
                                <delete dir="target/sources"/>
                                <delete dir="target/site"/>
                                <delete dir="target/database"/>
                                <delete dir="target/samples"/>
                                <delete dir="src/site"/>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <reportPlugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-project-info-reports-plugin</artifactId>
                            <version>2.4</version>
                            <reportSets>
                                <reportSet>
                                    <reports>
                                        <report>index</report>
                                    </reports>
                                </reportSet>
                            </reportSets>
                        </plugin>
                    </reportPlugins>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>site</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>
                        <goals>
                            <goal>attached</goal>
                        </goals>
                        <configuration>
                            <filters>
                                <filter>${basedir}/src/assembly/filter.properties</filter>
                            </filters>
                            <descriptors>
                                <descriptor>${basedir}/src/assembly/dist.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                    <execution>
                        <id>4-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/src.xml</descriptor>-->
                                <descriptor>${basedir}/src/assembly/docs.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>


