<?xml version="1.0" encoding="UTF-8"?>

<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>com.tigerbeetle</groupId>
  <artifactId>tigerbeetle-java</artifactId>
  <version>0.15.3</version>
  <name>TigerBeetle Java client</name>
  <description>The distributed financial accounting database designed for mission critical safety and performance.</description>
  <developers>
    <developer>
      <name>The TigerBeetle contributors</name>
      <email>hi@tigerbeetle.com</email>
    </developer>
  </developers>
  <organization>
    <name>TigerBeetle, Inc.</name>
    <url>https://www.tigerbeetle.com</url>
  </organization>
  <url>https://www.tigerbeetle.com</url>
  <scm>
    <url>https://github.com/tigerbeetle/tigerbeetle</url>
  </scm>

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

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    <!-- JaCoCo thresholds -->
    <jacoco.unit-tests.limit.instruction-ratio>95%</jacoco.unit-tests.limit.instruction-ratio>
    <jacoco.unit-tests.limit.branch-ratio>85%</jacoco.unit-tests.limit.branch-ratio>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>[4.13.1,)</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <profiles>
    <profile>
      <id>Windows</id>
      <activation>
        <os>
          <family>Windows</family>
        </os>
      </activation>
      <properties>
        <executable.extension>.exe</executable.extension>
        <script.extension>.bat</script.extension>
      </properties>
    </profile>
    <profile>
      <id>unix</id>
      <activation>
        <os>
          <family>unix</family>
        </os>
      </activation>
      <properties>
        <executable.extension></executable.extension>
        <script.extension>.sh</script.extension>
      </properties>
    </profile>
  </profiles>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
          <configuration>
            <workingDirectory>${project.basedir}</workingDirectory>
          </configuration>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.0.2</version>
          <configuration>
            <!-- Excludes object files created during zig compilation  -->
            <excludes>
              <exclude>**/*.o</exclude>
              <exclude>**/*.obj</exclude>
              <exclude>**/*.pdb</exclude>
              <exclude>**/win*/*.lib</exclude>
            </excludes>
          </configuration>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-javadoc-plugin</artifactId>
          <version>3.4.1</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-source-plugin</artifactId>
          <version>3.2.1</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-gpg-plugin</artifactId>
          <version>3.0.1</version>
        </plugin>
        <plugin>
          <groupId>org.jacoco</groupId>
          <artifactId>jacoco-maven-plugin</artifactId>
          <version>0.8.8</version>
          <configuration>
            <excludes>
              <!-- Excluding exceptions classes -->
              <exclude>com/tigerbeetle/InitializationException.class</exclude>
              <exclude>com/tigerbeetle/RequestException.class</exclude>
              <exclude>com/tigerbeetle/ConcurrencyExceededException.class</exclude>
              <exclude>com/tigerbeetle/AssertionError.class</exclude>

              <!-- Excluding JNILoader platform specifics -->
              <exclude>com/tigerbeetle/JNILoader$OS.class</exclude>
              <exclude>com/tigerbeetle/JNILoader$Arch.class</exclude>
              <exclude>com/tigerbeetle/JNILoader$Abi.class</exclude>

              <!-- Excluding enums -->
              <exclude>com/tigerbeetle/PacketStatus.class</exclude>
              <exclude>com/tigerbeetle/PacketAcquireStatus.class</exclude>
              <exclude>com/tigerbeetle/InitializationStatus.class</exclude>
              <exclude>com/tigerbeetle/TransferFlags.class</exclude>
              <exclude>com/tigerbeetle/AccountFilterFlags.class</exclude>
            </excludes>
          </configuration>
        </plugin>
        <plugin>
          <groupId>net.revelc.code.formatter</groupId>
          <artifactId>formatter-maven-plugin</artifactId>
          <version>2.19.0</version>
          <configuration>
            <lineEnding>LF</lineEnding>
            <configFile>${project.basedir}/eclipse-formatter.xml</configFile>
            <!-- Excluding all autogenerated files -->
            <excludes>
              <exclude>com/tigerbeetle/AccountBatch.java</exclude>
              <exclude>com/tigerbeetle/AccountFlags.java</exclude>
              <exclude>com/tigerbeetle/CreateAccountResult.java</exclude>
              <exclude>com/tigerbeetle/CreateAccountResultBatch.java</exclude>
              <exclude>com/tigerbeetle/CreateTransferResult.java</exclude>
              <exclude>com/tigerbeetle/CreateTransferResultBatch.java</exclude>
              <exclude>com/tigerbeetle/InitializationStatus.java</exclude>
              <exclude>com/tigerbeetle/PacketStatus.java</exclude>
              <exclude>com/tigerbeetle/TransferBatch.java</exclude>
              <exclude>com/tigerbeetle/TransferFlags.java</exclude>
              <exclude>com/tigerbeetle/AccountFilterFlags.java</exclude>
              <exclude>com/tigerbeetle/AccountFilterBatch.java</exclude>
              <exclude>com/tigerbeetle/AccountBalanceBatch.java</exclude>
            </excludes>
          </configuration>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-pmd-plugin</artifactId>
          <version>3.19.0</version>
          <configuration>
            <linkXRef>false</linkXRef>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>

    <plugins>
      <!-- JNI tests -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>3.1.0</version>
        <configuration>
          <workingDirectory>${project.basedir}/../../../</workingDirectory>
          <executable>${project.basedir}/../../../zig/zig${executable.extension}</executable>
        </configuration>
        <executions>
          <execution>
            <!-- Zig test:jni -->
            <?m2e ignore?>
            <id>zig-jni-test</id>
            <phase>validate</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <environmentVariables>
                  <JAVA_HOME>${java.home}</JAVA_HOME>
              </environmentVariables>
              <arguments>
                <argument>build</argument>
                <argument>test:jni</argument>
              </arguments>
            </configuration>
          </execution>
          <execution>
            <!-- Zig build -->
            <?m2e ignore?>
            <id>zig-build</id>
            <phase>validate</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <arguments>
                <argument>build</argument>
                <argument>java_client</argument>
                <argument>-Drelease</argument>
                <argument>-Dconfig=production</argument>
              </arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- Formatter -->
      <plugin>
        <groupId>net.revelc.code.formatter</groupId>
        <artifactId>formatter-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>format</id>
            <phase>validate</phase>
            <goals>
              <goal>format</goal>
            </goals>
          </execution>
          <execution>
            <!-- Format linter -->
            <id>format-validate</id>
            <goals>
              <goal>validate</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <!-- Code Coverage using JaCoCo -->
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>jacoco-initialize</id>
            <goals>
              <goal>prepare-agent</goal>
            </goals>
          </execution>
          <execution>
            <id>jacoco-check</id>
            <phase>test</phase>
            <goals>
              <goal>check</goal>
            </goals>
            <configuration>
              <rules>
                <rule>
                  <element>BUNDLE</element>
                  <limits>
                    <limit>
                      <counter>INSTRUCTION</counter>
                      <value>COVEREDRATIO</value>
                      <minimum>${jacoco.unit-tests.limit.instruction-ratio}</minimum>
                    </limit>
                    <limit>
                      <counter>BRANCH</counter>
                      <value>COVEREDRATIO</value>
                      <minimum>${jacoco.unit-tests.limit.branch-ratio}</minimum>
                    </limit>
                  </limits>
                </rule>
              </rules>
            </configuration>
          </execution>
          <!-- could be replaced by a online tool such as codecov -->
          <execution>
            <id>jacoco-report</id>
            <phase>test</phase>
            <goals>
              <goal>report</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <!-- Sign artifacts -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-gpg-plugin</artifactId>
        <executions>
            <execution>
                <id>sign-artifacts</id>
                <phase>deploy</phase>
                <goals>
                    <goal>sign</goal>
                </goals>
                <configuration>
                    <gpgArguments>
                        <arg>--pinentry-mode</arg>
                        <arg>loopback</arg>
                    </gpgArguments>
                </configuration>
            </execution>
        </executions>
      </plugin>

      <!-- Source code jar -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <executions>
            <execution>
                <id>attach-sources</id>
                <goals>
                    <goal>jar</goal>
                </goals>
            </execution>
        </executions>
      </plugin>

      <!-- Javadoc jar -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <executions>
          <execution>
            <id>attach-javadocs</id>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <!-- PMD -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-pmd-plugin</artifactId>
        <executions>
          <execution>
            <id>pdm-check</id>
            <phase>test</phase>
            <goals>
              <goal>check</goal>
            </goals>
            <configuration>
              <verbose>true</verbose>
              <excludeFromFailureFile>${project.basedir}/exclude-pmd.properties</excludeFromFailureFile>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- Maven central -->
      <plugin>
        <groupId>org.sonatype.plugins</groupId>
        <artifactId>nexus-staging-maven-plugin</artifactId>
        <version>1.6.13</version>
        <extensions>true</extensions>
        <configuration>
            <serverId>ossrh</serverId>
            <nexusUrl>https://s01.oss.sonatype.org</nexusUrl>
            <autoReleaseAfterClose>true</autoReleaseAfterClose>
            <stagingProgressTimeoutMinutes>30</stagingProgressTimeoutMinutes>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <distributionManagement>
    <snapshotRepository>
      <id>ossrh</id>
      <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
    </snapshotRepository>
    <repository>
      <id>ossrh</id>
      <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
    </repository>
  </distributionManagement>
</project>
