<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (c) 2017, 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:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.wso2.appcloud</groupId>
        <artifactId>appcloud-parent</artifactId>
        <version>3.0.0-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <artifactId>test-coverage</artifactId>
    <name>WSO2 Carbon - Unit Test Coverage Generation</name>
    <properties>
        <target>target</target>
        <coverge-report>coverage-reports</coverge-report>
        <individual.test.report.name>jacoco-unit.exec</individual.test.report.name>
        <classes>classes</classes>
        <source>src/main/java</source>

        <!-- integration cloud related properties -->
        <integration-cloud>Integration-cloud</integration-cloud>
        <integrationcloud-common.dir>${basedir}/../modules/components/org.wso2.appcloud.common</integrationcloud-common.dir>
        <integrationcloud-core.dir>${basedir}/../modules/components/org.wso2.appcloud.core</integrationcloud-core.dir>

    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>

                        <configuration>
                            <target name="mergeReports">
                                <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="maven.plugin.classpath" />
                                <if>
                                    <and>
                                        <available file="${integrationcloud-common.dir}/${target}/${coverge-report}/${individual.test.report.name}" />
                                        <!-- After adding the test cases need to list the exec files here-->
                                        <available file="${integrationcloud-core.dir}/${target}/${coverge-report}/${individual.test.report.name}" />
                                    </and>
                                    <then>
                                        <taskdef name="report" classname="org.jacoco.ant.ReportTask">
                                            <classpath path="${basedir}/target/jacoco-jars/org.jacoco.ant.jar" />
                                        </taskdef>
                                        <mkdir dir="${basedir}/target/coverage-report" />
                                        <report>
                                            <executiondata>
                                                <fileset dir="${integrationcloud-common.dir}/${target}/${coverge-report}">
                                                    <include name="${individual.test.report.name}" />
                                                </fileset>
                                                <fileset dir="${integrationcloud-core.dir}/${target}/${coverge-report}">
                                                    <include name="${individual.test.report.name}" />
                                                </fileset>
                                                <!-- Need to list the newly added exec files here -->
                                            </executiondata>
                                            <structure name="integration cloud Component">
                                                <group name="Integration-cloud">
                                                    <group name="org.wso2.appcloud.common">
                                                        <classfiles>
                                                            <fileset dir="${integrationcloud-common.dir}/${target}/${classes}" />
                                                        </classfiles>
                                                        <sourcefiles encoding="UTF-8">
                                                            <fileset dir="${integrationcloud-common.dir}/${source}" />
                                                        </sourcefiles>
                                                    </group>
                                                    <group name="org.wso2.appcloud.core">
                                                        <classfiles>
                                                            <fileset dir="${integrationcloud-core.dir}/${target}/${classes}" />
                                                        </classfiles>
                                                        <sourcefiles encoding="UTF-8">
                                                            <fileset dir="${integrationcloud-core.dir}/${source}" />
                                                        </sourcefiles>
                                                    </group>
                                                </group>
                                            </structure>

                                            <html destdir="${basedir}/target/coverage-report/site" />
                                        </report>
                                    </then>
                                </if>
                            </target>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.jacoco</groupId>
                        <artifactId>org.jacoco.ant</artifactId>
                        <version>0.7.5.201505241946</version>
                    </dependency>
                    <dependency>
                        <groupId>ant-contrib</groupId>
                        <artifactId>ant-contrib</artifactId>
                        <version>1.0b3</version>
                        <exclusions>
                            <exclusion>
                                <groupId>ant</groupId>
                                <artifactId>ant</artifactId>
                            </exclusion>
                        </exclusions>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>