<?xml version="1.0" encoding="UTF-8"?>
<!--
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// © 2011-2022 Telenav, Inc.
// Licensed under Apache License, Version 2.0
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-->

<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>com.telenav.cactus</groupId>
        <artifactId>cactus</artifactId>
        <version>1.4.10</version>
    </parent>

    <artifactId>cactus-metadata</artifactId>
    <description>
        The cactus-metadata project generates build metadata consumed by
        KivaKit and other projects.
    </description>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <useModulePath>false</useModulePath>
                </configuration>
            </plugin>

            <!-- Create Executable JAR -->

            <plugin>

                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>${maven-shade-plugin.version}</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>

                        <configuration>

                            <finalName>cactus-metadata-${project.version}</finalName>
                            <minimizeJar>false</minimizeJar>
                            <transformers>
                                <transformer implementation = "org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.telenav.cactus.metadata.BuildMetadataUpdater</mainClass>
                                </transformer>
                            </transformers>
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>module-info.class</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                            <artifactSet>
                                <includes>
                                    <include>*:*</include>
                                </includes>
                            </artifactSet>

                        </configuration>

                    </execution>
                </executions>

            </plugin>

            <!-- Create Build Metadata -->

            <plugin>

                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>3.0.0</version>
                <executions>

                    <execution>

                        <id>project-metadata</id>
                        <phase>validate</phase>
                        <configuration>

                            <target name = "build-metadata">

                                <property name = "project.groupId" value = "${project.groupId}"/>
                                <property name = "project.artifactId" value = "${project.artifactId}"/>
                                <property name = "project.version" value = "${project.version}"/>
                                <property name = "project.name" value = "${project.name}"/>
                                <condition property = "source.exists">
                                    <available file = "src" type = "dir"/>
                                </condition>
                                <taskdef classpathref = "maven.plugin.classpath" resource = "net/sf/antcontrib/antcontrib.properties"/>
                                <if>
                                    <equals arg1 = "${source.exists}" arg2 = "true"/>
                                    <then>
                                        <echo file = "src/main/java/project.properties">
                                            project-name = ${project.name}${line.separator}project-version
                                            = ${project.version}${line.separator}project-group-id
                                            = ${project.groupId}${line.separator}project-artifact-id
                                            = ${project.artifactId}
                                        </echo>
                                    </then>
                                    <else>
                                        <echo file = "${project.basedir}/project.properties">
                                            project-name = ${project.name}${line.separator}project-version
                                            = ${project.version}${line.separator}project-group-id
                                            = ${project.groupId}${line.separator}project-artifact-id
                                            = ${project.artifactId}
                                        </echo>
                                    </else>
                                </if>

                            </target>

                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>

                    </execution>

                </executions>
                <dependencies>
                    <dependency>
                        <groupId>ant-contrib</groupId>
                        <artifactId>ant-contrib</artifactId>
                        <version>20020829</version>
                    </dependency>
                </dependencies>

            </plugin>

        </plugins>

    </build>
    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-params</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>
