<!--
 ~ 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.jaggeryjs</groupId>
        <artifactId>jaggery-parent</artifactId>
        <version>0.9.0.ALPHA4.wso2v3</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>jaggery</artifactId>
    <packaging>jar</packaging>
    <name>WSO2 Carbon - Distribution</name>
    <description>WSO2 Carbon Distribution</description>
    <dependencies>
        <dependency>
            <groupId>net.sf.saxon.wso2</groupId>
            <artifactId>saxon.bps</artifactId>
            <version>9.0.0.x-wso2v1</version>
        </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.kernal.version}</version>
                                    <type>zip</type>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>target</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-kernel-patch</id>
                        <phase>test</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.wso2.carbon</groupId>
                                    <artifactId>WSO2-CARBON-PATCH-4.2.0</artifactId>
                                    <version>0005</version>
                                    <type>zip</type>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>target</outputDirectory>
                                </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="jaggery-${pom.version}.zip"/>
                                    </fileset>
                                </unzip>
                                <copy todir="target/wso2carbon-core-${carbon.kernal.version}/repository/components"
                                      overwrite="true">
                                    <fileset
                                            dir="${tempdir}/jaggery-${pom.version}/carbon/repository/components">
                                    </fileset>
                                </copy>
                                <unzip src="target/wso2carbon-core-${carbon.kernal.version}/repository/components/plugins/org.jaggeryjs.jaggery.deployer_${jaggery.deployer.osgi.version}.jar"
                                       dest="${jardir}/deployer">
                                    <patternset>
                                        <exclude name="**/component.xml"/>
                                    </patternset>
                                </unzip>
                                <copy file="src/resources/jar/META-INF/component.xml"
                                      todir="${jardir}/deployer/META-INF"/>
                                <delete file="target/wso2carbon-core-${carbon.kernal.version}/repository/components/plugins/org.jaggeryjs.jaggery.deployer_${jaggery.deployer.osgi.version}.jar"></delete>
                                <zip destfile="target/wso2carbon-core-${carbon.kernal.version}/repository/components/plugins/org.jaggeryjs.jaggery.deployer_${jaggery.deployer.osgi.version}.jar"
                                     basedir="${jardir}/deployer"/>


                                <delete file="target/jaggery-${pom.version}.zip"/>
                                <delete dir="${tempdir}"/>
                                <mkdir dir="${tempdir}"/>
                                <unzip dest="${tempdir}">
                                    <fileset
                                            dir="target/wso2carbon-core-${carbon.kernal.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="**/editarea/**"/>
                                        <exclude name="**/codepress/**"/>
                                        <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="*.*"/>
                                    </fileset>
                                </copy>
                                <!--copy todir="src/site" overwrite="false" includeemptydirs="false">
                                    <fileset dir="../../docs">
                                        <exclude name="**/images/**/*.*"/>
                                    </fileset>
                                    <filterset>
                                        <filter token="buildNumber" value="${buildNumber}"/>
                                    </filterset>
                                </copy>
                                <copy todir="src/site" overwrite="false" includeemptydirs="false">
                                    <fileset dir="../../docs">
                                        <include name="**/images/**/*.*"/>
                                    </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/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.kernal.version}"/>
                                <delete file="target/jaggery-${project.version}.jar"/>
                                <delete dir="target/sources"/>
                                <delete dir="target/site"/>
                                <delete dir="target/antrun"/>
                                <delete dir="src/site"/>
                                <delete dir="target/WSO2-CARBON-PATCH-4.2.0-0005"/>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!--<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <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>
                        <!--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>
                        </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>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <executions>
                    <execution>
                        <id>auto-clean</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>
</project>
