<?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="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>
        <artifactId>carbon-device-mgt-plugins-parent</artifactId>
        <groupId>org.wso2.carbon.devicemgt-plugins</groupId>
        <version>6.0.0-SNAPSHOT</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>test-coverage</artifactId>
    <name>WSO2 Carbon - Carbon Device Management Plugins Test Coverage Component</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>

        <!-- extensions  component related properties -->
        <extensions>extensions</extensions>

        <!-- cdmf-transport adapters-->
        <cdmf.adapters>${extensions}/cdmf-transport-adapters</cdmf.adapters>
        <input.extension>
            ${basedir}/../${cdmf.adapters}/input/org.wso2.carbon.device.mgt.input.adapter.extension
        </input.extension>
        <input.http>
            ${basedir}/../${cdmf.adapters}/input/org.wso2.carbon.device.mgt.input.adapter.http
        </input.http>
        <input.mqtt>
            ${basedir}/../${cdmf.adapters}/input/org.wso2.carbon.device.mgt.input.adapter.mqtt
        </input.mqtt>
        <input.thrift>
            ${basedir}/../${cdmf.adapters}/input/org.wso2.carbon.device.mgt.input.adapter.thrift
        </input.thrift>
        <input.xmpp>
            ${basedir}/../${cdmf.adapters}/input/org.wso2.carbon.device.mgt.input.adapter.xmpp
        </input.xmpp>
        <output.mqtt>
            ${basedir}/../${cdmf.adapters}/output/org.wso2.carbon.device.mgt.output.adapter.mqtt
        </output.mqtt>
        <output.websocket>
            ${basedir}/../${cdmf.adapters}/output/org.wso2.carbon.device.mgt.output.adapter.websocket
        </output.websocket>
        <output.websocket.endpoint>
            ${basedir}/../${cdmf.adapters}/output/org.wso2.carbon.device.mgt.output.adapter.websocket.endpoint
        </output.websocket.endpoint>
        <output.xmpp>
            ${basedir}/../${cdmf.adapters}/output/org.wso2.carbon.device.mgt.output.adapter.xmpp
        </output.xmpp>

        <mb.extensions>${extensions}/mb-extensions</mb.extensions>
        <mb.api>${basedir}/../${mb.extensions}/org.wso2.carbon.andes.extensions.device.mgt.api</mb.api>
        <mb.authorization>
            ${basedir}/../${mb.extensions}/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization
        </mb.authorization>

        <pull.notification.listener>
            ${basedir}/../${extensions}/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener
        </pull.notification.listener>

        <!-- mobile-plugins component -->
        <mobile.plugins>mobile-plugins</mobile.plugins>
        <android.plugin>${mobile.plugins}/android-plugin</android.plugin>
        <android.mobile>${basedir}/../${android.plugin}/org.wso2.carbon.device.mgt.mobile.android</android.mobile>
        <android.api>${basedir}/../${android.plugin}/org.wso2.carbon.device.mgt.mobile.android.api</android.api>
    </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="${android.api}/${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="${android.api}/${target}/${coverge-report}">
                                                    <include name="${individual.test.report.name}" />
                                                </fileset>

                                                <!-- Need to list the newly added exec files here -->
                                            </executiondata>
                                            <structure name="Carbon Device Management Plugins Component Coverage Report">
                                                <group name="extensions">
                                                    <group name="cdmf-transport-adapters">
                                                        <group name="input">
                                                            <group name="org.wso2.carbon.device.mgt.input.adapter.extension">
                                                                <classfiles>
                                                                    <fileset dir="${input.extension}/${target}/${classes}" />
                                                                </classfiles>
                                                                <sourcefiles encoding="UTF-8">
                                                                    <fileset dir="${input.extension}/${source}" />
                                                                </sourcefiles>
                                                            </group>
                                                            <group name="org.wso2.carbon.device.mgt.input.adapter.http">
                                                                <classfiles>
                                                                    <fileset dir="${input.http}/${target}/${classes}" />
                                                                </classfiles>
                                                                <sourcefiles encoding="UTF-8">
                                                                    <fileset dir="${input.http}/${source}" />
                                                                </sourcefiles>
                                                            </group>
                                                            <group name="org.wso2.carbon.device.mgt.input.adapter.mqtt">
                                                                <classfiles>
                                                                    <fileset dir="${input.mqtt}/${target}/${classes}" />
                                                                </classfiles>
                                                                <sourcefiles encoding="UTF-8">
                                                                    <fileset dir="${input.mqtt}/${source}" />
                                                                </sourcefiles>
                                                            </group>
                                                            <group name="org.wso2.carbon.device.mgt.input.adapter.thrift">
                                                                <classfiles>
                                                                    <fileset dir="${input.thrift}/${target}/${classes}" />
                                                                </classfiles>
                                                                <sourcefiles encoding="UTF-8">
                                                                    <fileset dir="${input.thrift}/${source}" />
                                                                </sourcefiles>
                                                            </group>
                                                        </group>

                                                        <group name="output">
                                                            <group name="org.wso2.carbon.device.mgt.output.adapter.mqtt">
                                                                <classfiles>
                                                                    <fileset dir="${output.mqtt}/${target}/${classes}" />
                                                                </classfiles>
                                                                <sourcefiles encoding="UTF-8">
                                                                    <fileset dir="${output.mqtt}/${source}" />
                                                                </sourcefiles>
                                                            </group>
                                                            <group name="org.wso2.carbon.device.mgt.output.adapter.websocket">
                                                                <classfiles>
                                                                    <fileset dir="${output.websocket}/${target}/${classes}" />
                                                                </classfiles>
                                                                <sourcefiles encoding="UTF-8">
                                                                    <fileset dir="${output.websocket}/${source}" />
                                                                </sourcefiles>
                                                            </group>
                                                            <group name="org.wso2.carbon.device.mgt.output.adapter.websocket.endpoint">
                                                                <classfiles>
                                                                    <fileset dir="${output.websocket.endpoint}/${target}/${classes}" />
                                                                </classfiles>
                                                                <sourcefiles encoding="UTF-8">
                                                                    <fileset dir="${output.websocket.endpoint}/${source}" />
                                                                </sourcefiles>
                                                            </group>
                                                            <group name="org.wso2.carbon.device.mgt.output.adapter.xmpp">
                                                                <classfiles>
                                                                    <fileset dir="${output.xmpp}/${target}/${classes}" />
                                                                </classfiles>
                                                                <sourcefiles encoding="UTF-8">
                                                                    <fileset dir="${output.xmpp}/${source}" />
                                                                </sourcefiles>
                                                            </group>
                                                        </group>
                                                    </group>
                                                    <group name="mb-extensions">
                                                        <group name="org.wso2.carbon.andes.extensions.device.mgt.api">
                                                            <classfiles>
                                                                <fileset dir="${mb.api}/${target}/${classes}" />
                                                            </classfiles>
                                                            <sourcefiles encoding="UTF-8">
                                                                <fileset dir="${mb.api}/${source}" />
                                                            </sourcefiles>
                                                        </group>
                                                        <group name="org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization">
                                                            <classfiles>
                                                                <fileset dir="${mb.authorization}/${target}/${classes}" />
                                                            </classfiles>
                                                            <sourcefiles encoding="UTF-8">
                                                                <fileset dir="${mb.authorization}/${source}" />
                                                            </sourcefiles>
                                                        </group>
                                                    </group>
                                                    <group name="pull-notification-listeners">
                                                      <classfiles>
                                                            <fileset dir="${pull.notification.listener}/${target}/${classes}" />
                                                        </classfiles>
                                                        <sourcefiles encoding="UTF-8">
                                                            <fileset dir="${pull.notification.listener}/${source}" />
                                                        </sourcefiles>
                                                    </group>
                                                </group>
                                                <group name="mobile-plugins">
                                                    <group name="android-plugin">
                                                        <group name="org.wso2.carbon.device.mgt.mobile.android">
                                                            <classfiles>
                                                                <fileset dir="${android.mobile}/${target}/${classes}" />
                                                            </classfiles>
                                                            <sourcefiles encoding="UTF-8">
                                                                <fileset dir="${android.mobile}/${source}" />
                                                            </sourcefiles>
                                                        </group>
                                                        <group name="org.wso2.carbon.device.mgt.mobile.android.api">
                                                            <classfiles>
                                                                <fileset dir="${android.api}/${target}/${classes}" />
                                                            </classfiles>
                                                            <sourcefiles encoding="UTF-8">
                                                                <fileset dir="${android.api}/${source}" />
                                                            </sourcefiles>
                                                        </group>
                                                    </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>${jacoco.ant.verision}</version>
                    </dependency>
                    <dependency>
                        <groupId>ant-contrib</groupId>
                        <artifactId>ant-contrib</artifactId>
                        <version>${ant.contrib.version}</version>
                        <exclusions>
                            <exclusion>
                                <groupId>ant</groupId>
                                <artifactId>ant</artifactId>
                            </exclusion>
                        </exclusions>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>