<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright © 2018. Sir Wellington.
  ~ Licensed 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">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>tech.sirwellington.alchemy</groupId>
        <artifactId>alchemy</artifactId>
        <version>2.8</version>
    </parent>

    <artifactId>alchemy-thrift</artifactId>
    <version>2.1</version>
    <packaging>jar</packaging>
    <name>${project.artifactId}</name>

    <url>https://github.com/SirWellington/alchemy-thrift</url>
    <description>
        Part of the Alchemy Collection.
        Makes it Simple to work with Thrift in Java.
        Saves you from writing boiler-plate code,
        such as management of Clients,
        and serialization of Thrift Objects.

        This library also demonstrates how to incorporate thrift with maven,
        for incorporation into your continuous delivery and distribution of your thrift schemas.
    </description>

    <issueManagement>
        <system>GitHub Issues</system>
        <url>https://github.com/SirWellington/alchemy-thrift/issues</url>
    </issueManagement>

    <scm>
        <connection>scm:git:git@github.com:SirWellington/alchemy-thrift.git</connection>
        <developerConnection>scm:git:git@github.com:SirWellington/alchemy-thrift.git</developerConnection>
        <url>git@github.com:SirWellington/alchemy-thrift.git</url>
    </scm>


    <properties>

        <!--Java Compiler Properties-->
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>

        <!--Thrift Compiler Properties-->
        <thrift.compiler>thrift</thrift.compiler>
        <src.main>${project.basedir}/src/main</src.main>
        <src.thrift.dir>${src.main}/thrift</src.thrift.dir>
        <thrift.dest.dir>${project.build.directory}/generated-sources/thrift</thrift.dest.dir>
        <thrift.dest.dir.java>${project.build.directory}/generated-sources/java</thrift.dest.dir.java>
        <thrift.dest.dir.doc>${project.basedir}/src/main/doc</thrift.dest.dir.doc>
        <thrift.dest.dir.js>${project.basedir}/src/main/js</thrift.dest.dir.js>
        <thrift.dest.dir.node>${project.basedir}/src/main/nodejs</thrift.dest.dir.node>

    </properties>

    <dependencies>

        <!--=======================-->
        <!--UNIT TESTING-->
        <!--=======================-->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-library</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>alchemy-test</artifactId>
            <version>2.2.2</version>
            <scope>test</scope>
        </dependency>

        <!--=======================-->
        <!--ALCHEMY-->
        <!--=======================-->
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>alchemy-annotations</artifactId>
            <version>2.1.2</version>
        </dependency>


        <!--=======================-->
        <!--LOGGING-->
        <!--=======================-->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>


        <!--=======================-->
        <!-- APACHE THRIFT -->
        <!--=======================-->
        <dependency>
            <groupId>org.apache.thrift</groupId>
            <artifactId>libthrift</artifactId>
        </dependency>

    </dependencies>

    <build>
        <plugins>

            <!--COMPILE THE THRIFT SOURCE-->
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.8</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <configuration>
                            <target>
                                <!-- Define fileset of thrift files -->
                                <fileset id="thrift.src.files" dir="${src.thrift.dir}">
                                    <include name="**/*.thrift"/>
                                </fileset>

                                <mkdir dir="${thrift.dest.dir}"/>
                                <mkdir dir="${thrift.dest.dir.doc}"/>
                                <mkdir dir="${thrift.dest.dir.js}"/>
                                <mkdir dir="${thrift.dest.dir.node}"/>

                                <delete includeemptydirs="true">
                                    <fileset dir="${thrift.dest.dir.doc}" includes="**/*"/>
                                    <fileset dir="${thrift.dest.dir.js}" includes="**/*"/>
                                    <fileset dir="${thrift.dest.dir.node}" includes="**/*"/>
                                </delete>


                                <!--Generate Doc Files-->
                                <!-- Invoke thrift binary for each of these files -->
                                <apply executable="${thrift.compiler}" resultproperty="thrift.compile.result"
                                       failifexecutionfails="true" failonerror="true" resolveExecutable="true"
                                       searchpath="true" dir="." verbose="true">
                                    <arg value="-o"/>
                                    <arg value="${thrift.dest.dir}"/>
                                    <arg value="--gen"/>
                                    <arg value="html:standalone"/>
                                    <arg value="--gen"/>
                                    <arg value="java:handle_runtime_exceptions"/>
                                    <arg value="--gen"/>
                                    <arg value="js"/>
                                    <arg value="--gen"/>
                                    <arg value="js:node"/>
                                    <srcfile/>
                                    <fileset refid="thrift.src.files"/>
                                </apply>

                                <move todir="${thrift.dest.dir.doc}">
                                    <fileset dir="${thrift.dest.dir}/gen-html"/>
                                </move>

                                <move todir="${thrift.dest.dir.java}">
                                    <fileset dir="${thrift.dest.dir}/gen-java"/>
                                </move>

                                <move todir="${thrift.dest.dir.js}">
                                    <fileset dir="${thrift.dest.dir}/gen-js"/>
                                </move>
                                <move todir="${thrift.dest.dir.node}">
                                    <fileset dir="${thrift.dest.dir}/gen-nodejs"/>
                                </move>

                            </target>
                            <sourceRoot>
                                ${thrift.dest.dir.java}
                            </sourceRoot>

                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>


            <!--Jacoco Plugin, but excluding the generated code-->
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>*.generated.*</exclude>
                        <exclude>**/*Exception.*</exclude>
                    </excludes>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>report</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>post-unit-test</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

</project>
