<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">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>io.undertow</groupId>
        <artifactId>undertow-parent</artifactId>
        <version>2.3.15.Final</version>
    </parent>
    <artifactId>undertow-coverage-report</artifactId>
    <name>Undertow Test Coverage Report</name>
    <description>aggregates and compiles jacoco test coverage report</description>
    <packaging>pom</packaging>

    <build>
        <plugins>
             
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${version.org.jacoco}</version>
                <executions>
                    <execution>
                        <id>merge-reports</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>merge</goal>
                        </goals>
                        <configuration>
                            <fileSets>
                                <fileSet>
                                    <directory>${project.basedir}/../</directory>
                                    <includes>
                                        <include>**/target/jacoco.exec</include>
                                    </includes>
                                </fileSet>
                            </fileSets>
                        </configuration>
                    </execution>
                    <execution>
                        <id>compile-report</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <!-- copy the ant tasks jar -->
                    <execution>
                        <id>jacoco-dependency-ant</id>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <phase>test-compile</phase>
                        <inherited>false</inherited>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.jacoco</groupId>
                                    <artifactId>org.jacoco.ant</artifactId>
                                    <version>${version.org.jacoco}</version>
                                </artifactItem>
                            </artifactItems>
                            <stripVersion>true</stripVersion>
                            <outputDirectory>${basedir}/target/jacoco-jars</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>test</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                            <!-- Execute an ant task within maven -->
                                <echo message="Generating JaCoCo Reports" />
                                <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="${basedir}/../core/target">
                                            <include name="jacoco.exec" />
                                        </fileset>
                                        <fileset dir="${basedir}/../servlet/target">
                                            <include name="jacoco.exec" />
                                        </fileset>
                                        <fileset dir="${basedir}/../websockets-jsr/target">
                                            <include name="jacoco.exec" />
                                        </fileset>
                                    </executiondata>
                                    <structure name="jacoco-multi Coverage Project">
                                        <group name="jacoco-multi">
                                            <classfiles>
                                                <fileset dir="${basedir}/../core/target/classes" />
                                                <fileset dir="${basedir}/../servlet/target/classes" />
                                                <fileset dir="${basedir}/../websockets-jsr/target/classes" />
                                            </classfiles>
                                            <sourcefiles encoding="UTF-8">
                                                <fileset dir="${basedir}/../core/src/main/java" />
                                                <fileset dir="${basedir}/../servlet/src/main/java" />
                                                <fileset dir="${basedir}/../websockets-jsr/src/main/java" />                                                
                                            </sourcefiles>
                                        </group>
                                    </structure>
                                    <html destdir="${basedir}/target/coverage-report/html" />
                                    <xml destfile="${basedir}/target/coverage-report/coverage-report.xml" />
                                    <csv destfile="${basedir}/target/coverage-report/coverage-report.csv" />
                                </report>
                            </target>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.jacoco</groupId>
                        <artifactId>org.jacoco.ant</artifactId>
                        <version>${version.org.jacoco}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>
