<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2021 ABSA Group Limited
  ~
  ~ 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>

    <groupId>za.co.absa</groupId>
    <artifactId>root-pom</artifactId>
    <version>1.0.13</version>

    <packaging>pom</packaging>

    <name>root-pom</name>
    <description>ABSA OSS Root POM</description>

    <url>https://absaoss.github.io/</url>

    <scm>
        <url>${scm.url}</url>
        <connection>${scm.connection}</connection>
        <developerConnection>${scm.developerConnection}</developerConnection>
        <tag>release/1.0.13</tag>
    </scm>

    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <url>https://www.apache.org/licenses/LICENSE-2.0</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <organization>
        <name>ABSA Group Limited</name>
        <url>https://www.absa.africa</url>
    </organization>

    <developers>
        <developer>
            <id>AbsaOSS/absaoss</id>
            <name>ABSA R&amp;D team</name>
            <timezone>Europe/Prague</timezone>
            <url>https://github.com/orgs/AbsaOSS/teams/absaoss</url>
        </developer>
    </developers>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <!-- SCM -->

        <scm.url><!-- defined externally --></scm.url>
        <scm.connection><!-- defined externally --></scm.connection>
        <scm.developerConnection><!-- defined externally --></scm.developerConnection>

        <!-- Docker -->

        <!-- [REQUIRED] Must be defined in submodules -->
        <docker.imageName><!-- defined in submodules --></docker.imageName>

        <docker.versionTagPrefix><!-- defined externally --></docker.versionTagPrefix>
        <docker.versionTagSuffix><!-- defined externally --></docker.versionTagSuffix>
        <docker.versionTagName>${dockerfile.versionTagPrefix}${project.version}${dockerfile.versionTagSuffix}</docker.versionTagName>

        <docker.latestTagPrefix><!-- defined externally --></docker.latestTagPrefix>
        <docker.latestTagSuffix><!-- defined externally --></docker.latestTagSuffix>
        <docker.latestTagName>${dockerfile.latestTagPrefix}latest${dockerfile.latestTagSuffix}</docker.latestTagName>

        <!--
            One of `docker.repositoryUrl`, `docker.repositoryPrefix` or `docker.repository`
            properties is required to be explicitly provided in the `mvn` command,
            so that the resulted `docker.repository` property has a correct value.
        -->

        <docker.repositoryUrl><!-- defined externally --></docker.repositoryUrl>
        <docker.repositoryPrefix>${dockerfile.repositoryUrl}/</docker.repositoryPrefix>
        <docker.repositorySuffix><!-- defined externally --></docker.repositorySuffix>
        <docker.repository>${dockerfile.repositoryPrefix}${dockerfile.imageName}${dockerfile.repositorySuffix}</docker.repository>

        <docker.platforms><!-- defined externally --></docker.platforms>

        <!--
            The properties with the prefix `dockerfile.*` are deprecated, and stay here for backward compatibility only.
            Outside of this POM, use their shorter variant `docker.*` instead.
            Inside this POM, we should stick to `dockerfile.*` for now, to support both variants.
        -->

        <dockerfile.imageName>${docker.imageName}</dockerfile.imageName>
        <dockerfile.versionTagPrefix>${docker.versionTagPrefix}</dockerfile.versionTagPrefix>
        <dockerfile.versionTagSuffix>${docker.versionTagSuffix}</dockerfile.versionTagSuffix>
        <dockerfile.versionTagName>${docker.versionTagName}</dockerfile.versionTagName>
        <dockerfile.latestTagPrefix>${docker.latestTagPrefix}</dockerfile.latestTagPrefix>
        <dockerfile.latestTagSuffix>${docker.latestTagSuffix}</dockerfile.latestTagSuffix>
        <dockerfile.latestTagName>${docker.latestTagName}</dockerfile.latestTagName>
        <dockerfile.repositoryUrl>${docker.repositoryUrl}</dockerfile.repositoryUrl>
        <dockerfile.repositoryPrefix>${docker.repositoryPrefix}</dockerfile.repositoryPrefix>
        <dockerfile.repositorySuffix>${docker.repositorySuffix}</dockerfile.repositorySuffix>
        <dockerfile.repository>${docker.repository}</dockerfile.repository>

        <!-- Test -->
        <jacoco.version>0.8.11</jacoco.version>
        <!-- Optional extra argLine values for scalatest plugin. Client project could override this value. -->
        <scalatest.argLine.extra />
    </properties>

    <profiles>

        <!-- Enables license check routine -->
        <profile>
            <id>license-check</id>
            <activation>
                <property>
                    <name>license-check</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.rat</groupId>
                        <artifactId>apache-rat-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>validate</phase>
                                <goals>
                                    <goal>check</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <excludes>
                                <exclude>.github/**</exclude>
                                <exclude>**/*.json</exclude>
                                <exclude>**/*.log</exclude>
                                <exclude>dependency-reduced-pom.xml</exclude>
                                <exclude>.sonarcloud.properties</exclude>
                                <exclude>.editorconfig</exclude>
                                <exclude>CODE_OF_CONDUCT.md</exclude>
                                <exclude>CONTRIBUTING.md</exclude>
                                <exclude>node_modules/</exclude>
                            </excludes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- Release routine configuration -->
        <profile>
            <id>release</id>
            <activation>
                <property>
                    <name>release</name>
                </property>
            </activation>
            <properties>
                <project.scm.id>absaoss-scm</project.scm.id>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-release-plugin</artifactId>
                        <configuration>
                            <tagNameFormat>release/@{project.version}</tagNameFormat>
                            <providerImplementations>
                                <git>jgit</git>
                            </providerImplementations>
                        </configuration>
                        <dependencies>
                            <dependency>
                                <groupId>org.apache.maven.scm</groupId>
                                <artifactId>maven-scm-api</artifactId>
                                <version>1.11.2</version>
                            </dependency>
                            <dependency>
                                <groupId>org.apache.maven.scm</groupId>
                                <artifactId>maven-scm-provider-jgit</artifactId>
                                <version>1.11.2</version>
                            </dependency>
                            <dependency>
                                <groupId>org.eclipse.jgit</groupId>
                                <artifactId>org.eclipse.jgit</artifactId>
                                <version>5.5.1.201910021850-r</version>
                            </dependency>
                        </dependencies>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- Enables OSSRH deploy routine -->
        <profile>
            <id>ossrh</id>
            <activation>
                <property>
                    <name>ossrh</name>
                </property>
            </activation>
            <distributionManagement>
                <snapshotRepository>
                    <id>ossrh</id>
                    <url>https://oss.sonatype.org/content/repositories/snapshots</url>
                </snapshotRepository>
                <repository>
                    <id>ossrh</id>
                    <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
                </repository>
            </distributionManagement>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <goals>
                                    <goal>jar-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>attach-docs</id>
                                <goals>
                                    <goal>javadoc-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <!-- Prevent `gpg` from using pinentry programs -->
                            <gpgArguments>
                                <arg>--pinentry-mode</arg>
                                <arg>loopback</arg>
                            </gpgArguments>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.sonatype.plugins</groupId>
                        <artifactId>nexus-staging-maven-plugin</artifactId>
                        <extensions>true</extensions>
                        <configuration>
                            <serverId>ossrh</serverId>
                            <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                            <autoReleaseAfterClose>true</autoReleaseAfterClose>
                            <autoDropAfterRelease>true</autoDropAfterRelease>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- Enables Docker image(s) build / deploy -->
        <profile>
            <id>docker</id>
            <activation>
                <property>
                    <name>docker</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>docker-build</id>
                                <phase>install</phase>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>docker-push</id>
                                <phase>deploy</phase>
                                <goals>
                                    <goal>push</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <skip>true</skip>
                            <images>
                                <image>
                                    <name>${dockerfile.repository}</name>
                                    <build>
                                        <contextDir>${project.basedir}</contextDir>
                                        <tags>
                                            <tag>${dockerfile.versionTagName}</tag>
                                            <tag>${dockerfile.latestTagName}</tag>
                                        </tags>
                                        <filter>false</filter>
                                        <buildx>
                                            <platforms>
                                                <platform>${docker.platforms}</platform>
                                            </platforms>
                                        </buildx>
                                        <args>
                                            <PROJECT_NAME>${project.name}</PROJECT_NAME>
                                            <PROJECT_GROUP_ID>${project.groupId}</PROJECT_GROUP_ID>
                                            <PROJECT_ARTIFACT_ID>${project.artifactId}</PROJECT_ARTIFACT_ID>
                                            <PROJECT_VERSION>${project.version}</PROJECT_VERSION>
                                            <PROJECT_BASEDIR>${project.basedir}</PROJECT_BASEDIR>
                                            <PROJECT_BUILD_DIRECTORY>${project.build.directory}</PROJECT_BUILD_DIRECTORY>
                                            <PROJECT_BUILD_FINAL_NAME>${project.build.finalName}</PROJECT_BUILD_FINAL_NAME>
                                        </args>
                                    </build>

                                </image>
                            </images>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- Enables JaCoCo code coverage measuring -->
        <profile>
            <id>code-coverage</id>
            <activation>
                <property>
                    <name>code-coverage</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>za.co.absa.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <version>${jacoco.version}</version>
                        <executions>
                            <execution>
                                <id>jacoco-prepare-agent</id>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                                <configuration>
                                    <propertyName>jacoco-agent.scalatest.argLine</propertyName>
                                </configuration>
                            </execution>
                            <execution>
                                <id>jacoco-report</id>
                                <goals>
                                    <goal>report</goal>
                                </goals>
                                <configuration>
                                    <title>${project.name} - scala:${scala.version}</title>
                                    <doMethodFiltration>true</doMethodFiltration>
                                    <doScalaMethodFiltration>true</doScalaMethodFiltration>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>com.github.cerveada</groupId>
                        <artifactId>scalatest-maven-plugin</artifactId>
                        <configuration>
                            <argLine>${jacoco-agent.scalatest.argLine} ${scalatest.argLine.extra}</argLine>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

    </profiles>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>

        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-release-plugin</artifactId>
                    <version>2.5.3</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>3.2.0</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.rat</groupId>
                    <artifactId>apache-rat-plugin</artifactId>
                    <version>0.13</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>3.2.0</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-gpg-plugin</artifactId>
                    <version>1.6</version>
                </plugin>
                <plugin>
                    <groupId>org.sonatype.plugins</groupId>
                    <artifactId>nexus-staging-maven-plugin</artifactId>
                    <version>1.7.0</version>
                </plugin>
                <plugin>
                    <groupId>io.fabric8</groupId>
                    <artifactId>docker-maven-plugin</artifactId>
                    <version>0.43.1</version>
                </plugin>
                <plugin>
                    <groupId>com.github.cerveada</groupId>
                    <artifactId>scalatest-maven-plugin</artifactId>
                    <configuration>
                        <argLine>${scalatest.argLine.extra}</argLine>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

</project>
