<?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>io.github.mraysmit</groupId>
    <artifactId>raftlog</artifactId>
    <version>1.1.0</version>
    <packaging>pom</packaging>

    <name>RaftLog</name>
    <description>Minimal Write-Ahead Log for Raft Consensus - A high-performance, crash-safe WAL implementation with CRC32C checksums, atomic metadata updates, and comprehensive recovery guarantees.</description>
    <url>https://github.com/mraysmit/raftlog</url>
    <inceptionYear>2024</inceptionYear>

    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <developers>
        <developer>
            <id>mraysmit</id>
            <name>Mark Andrew Ray-Smith</name>
            <organization>Cityline Ltd</organization>
            <organizationUrl>https://cityline.com</organizationUrl>
            <roles>
                <role>architect</role>
                <role>developer</role>
            </roles>
        </developer>
    </developers>

    <scm>
        <connection>scm:git:https://github.com/mraysmit/raftlog.git</connection>
        <developerConnection>scm:git:https://github.com/mraysmit/raftlog.git</developerConnection>
        <url>https://github.com/mraysmit/raftlog</url>
        <tag>HEAD</tag>
    </scm>

    <issueManagement>
        <system>GitHub Issues</system>
        <url>https://github.com/mraysmit/raftlog/issues</url>
    </issueManagement>

    <modules>
        <module>raftlog-core</module>
        <module>raftlog-demo</module>
    </modules>

    <properties>
        <!-- Java Version -->
        <maven.compiler.source>21</maven.compiler.source>
        <maven.compiler.target>21</maven.compiler.target>
        <maven.compiler.release>21</maven.compiler.release>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <!-- Dependency Versions -->
        <slf4j.version>2.0.12</slf4j.version>
        <logback.version>1.5.6</logback.version>
        <junit.version>5.10.2</junit.version>
        <junit.platform.version>1.10.2</junit.platform.version>

        <!-- Plugin Versions -->
        <maven.compiler.plugin.version>3.12.1</maven.compiler.plugin.version>
        <maven.surefire.plugin.version>3.2.5</maven.surefire.plugin.version>
        <maven.failsafe.plugin.version>3.2.5</maven.failsafe.plugin.version>
        <maven.jar.plugin.version>3.3.0</maven.jar.plugin.version>
        <maven.source.plugin.version>3.3.0</maven.source.plugin.version>
        <maven.javadoc.plugin.version>3.6.3</maven.javadoc.plugin.version>
        <maven.gpg.plugin.version>3.2.7</maven.gpg.plugin.version>
        <maven.release.plugin.version>3.0.1</maven.release.plugin.version>
        <maven.enforcer.plugin.version>3.4.1</maven.enforcer.plugin.version>
        <maven.toolchains.plugin.version>3.1.0</maven.toolchains.plugin.version>
        <maven.shade.plugin.version>3.5.2</maven.shade.plugin.version>
        <jacoco.plugin.version>0.8.12</jacoco.plugin.version>
        <central.publishing.plugin.version>0.10.0</central.publishing.plugin.version>

        <!-- Test Configuration -->
        <test.parallel>classes</test.parallel>
        <test.threadCount>4</test.threadCount>
        <test.groups />
        <test.excludedGroups />
    </properties>

    <dependencyManagement>
        <dependencies>
            <!-- ======================= -->
            <!-- Module Dependencies     -->
            <!-- ======================= -->
            <dependency>
                <groupId>io.github.mraysmit</groupId>
                <artifactId>raftlog-core</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>io.github.mraysmit</groupId>
                <artifactId>raftlog-demo</artifactId>
                <version>${project.version}</version>
            </dependency>

            <!-- ======================= -->
            <!-- Logging                 -->
            <!-- ======================= -->
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>${slf4j.version}</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-simple</artifactId>
                <version>${slf4j.version}</version>
            </dependency>
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
                <version>${logback.version}</version>
            </dependency>
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-core</artifactId>
                <version>${logback.version}</version>
            </dependency>

            <!-- ======================= -->
            <!-- Testing                 -->
            <!-- ======================= -->
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter</artifactId>
                <version>${junit.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-api</artifactId>
                <version>${junit.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-engine</artifactId>
                <version>${junit.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-params</artifactId>
                <version>${junit.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.junit.platform</groupId>
                <artifactId>junit-platform-suite-api</artifactId>
                <version>${junit.platform.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.junit.platform</groupId>
                <artifactId>junit-platform-launcher</artifactId>
                <version>${junit.platform.version}</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <pluginManagement>
            <plugins>
                <!-- Compiler Plugin -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>${maven.compiler.plugin.version}</version>
                    <configuration>
                        <release>${maven.compiler.release}</release>
                        <compilerArgs>
                            <arg>-Xlint:all</arg>
                            <arg>-Xlint:-processing</arg>
                        </compilerArgs>
                        <showWarnings>true</showWarnings>
                        <showDeprecation>true</showDeprecation>
                    </configuration>
                </plugin>

                <!-- Toolchains Plugin -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-toolchains-plugin</artifactId>
                    <version>${maven.toolchains.plugin.version}</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>toolchain</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <toolchains>
                            <jdk>
                                <version>21</version>
                            </jdk>
                        </toolchains>
                    </configuration>
                </plugin>

                <!-- Enforcer Plugin -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-enforcer-plugin</artifactId>
                    <version>${maven.enforcer.plugin.version}</version>
                    <executions>
                        <execution>
                            <id>enforce-versions</id>
                            <goals>
                                <goal>enforce</goal>
                            </goals>
                            <configuration>
                                <rules>
                                    <requireMavenVersion>
                                        <version>[3.8.0,)</version>
                                        <message>Maven 3.8.0 or higher is required.</message>
                                    </requireMavenVersion>
                                    <requireJavaVersion>
                                        <version>[21,)</version>
                                        <message>Java 21 or higher is required.</message>
                                    </requireJavaVersion>
                                    <banDuplicatePomDependencyVersions />
                                    <dependencyConvergence />
                                </rules>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <!-- Surefire Plugin (Unit Tests) -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${maven.surefire.plugin.version}</version>
                    <configuration>
                        <groups>${test.groups}</groups>
                        <excludedGroups>${test.excludedGroups}</excludedGroups>
                        <parallel>${test.parallel}</parallel>
                        <threadCount>${test.threadCount}</threadCount>
                        <forkCount>1</forkCount>
                        <reuseForks>true</reuseForks>
                        <argLine>-XX:+EnableDynamicAgentLoading</argLine>
                        <systemPropertyVariables>
                            <java.io.tmpdir>${project.build.directory}/test-tmp</java.io.tmpdir>
                        </systemPropertyVariables>
                    </configuration>
                </plugin>

                <!-- Failsafe Plugin (Integration Tests) -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>${maven.failsafe.plugin.version}</version>
                    <configuration>
                        <groups>${test.groups}</groups>
                        <excludedGroups>${test.excludedGroups}</excludedGroups>
                        <argLine>-XX:+EnableDynamicAgentLoading</argLine>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>integration-test</goal>
                                <goal>verify</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

                <!-- JAR Plugin -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>${maven.jar.plugin.version}</version>
                    <configuration>
                        <archive>
                            <manifest>
                                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                                <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                            </manifest>
                            <manifestEntries>
                                <Built-By>${project.developers[0].name}</Built-By>
                                <Build-Timestamp>${maven.build.timestamp}</Build-Timestamp>
                            </manifestEntries>
                        </archive>
                    </configuration>
                </plugin>

                <!-- Shade Plugin -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>${maven.shade.plugin.version}</version>
                </plugin>

                <!-- JaCoCo Plugin (Code Coverage) -->
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>${jacoco.plugin.version}</version>
                    <executions>
                        <execution>
                            <id>prepare-agent</id>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>report</id>
                            <phase>test</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>check</id>
                            <goals>
                                <goal>check</goal>
                            </goals>
                            <configuration>
                                <rules>
                                    <rule>
                                        <element>BUNDLE</element>
                                        <limits>
                                            <limit>
                                                <counter>LINE</counter>
                                                <value>COVEREDRATIO</value>
                                                <minimum>0.70</minimum>
                                            </limit>
                                            <limit>
                                                <counter>BRANCH</counter>
                                                <value>COVEREDRATIO</value>
                                                <minimum>0.60</minimum>
                                            </limit>
                                        </limits>
                                    </rule>
                                </rules>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <!-- Release Plugin -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-release-plugin</artifactId>
                    <version>${maven.release.plugin.version}</version>
                    <configuration>
                        <tagNameFormat>v@{project.version}</tagNameFormat>
                        <autoVersionSubmodules>true</autoVersionSubmodules>
                        <releaseProfiles>release</releaseProfiles>
                        <goals>deploy</goals>
                        <preparationGoals>clean verify</preparationGoals>
                        <completionGoals>clean</completionGoals>
                        <scmCommentPrefix>[release] </scmCommentPrefix>
                        <checkModificationExcludes>
                            <checkModificationExclude>pom.xml</checkModificationExclude>
                        </checkModificationExcludes>
                    </configuration>
                </plugin>

                <!-- Source Plugin -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>${maven.source.plugin.version}</version>
                    <executions>
                        <execution>
                            <id>attach-sources</id>
                            <goals>
                                <goal>jar-no-fork</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

                <!-- Javadoc Plugin -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>${maven.javadoc.plugin.version}</version>
                    <executions>
                        <execution>
                            <id>attach-javadocs</id>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <source>21</source>
                        <detectJavaApiLink>false</detectJavaApiLink>
                        <quiet>true</quiet>
                        <doclint>none</doclint>
                        <additionalOptions>
                            <additionalOption>-Xdoclint:none</additionalOption>
                        </additionalOptions>
                    </configuration>
                </plugin>

                <!-- GPG Signing Plugin -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-gpg-plugin</artifactId>
                    <version>${maven.gpg.plugin.version}</version>
                    <executions>
                        <execution>
                            <id>sign-artifacts</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>sign</goal>
                            </goals>
                            <configuration>
                                <gpgArguments>
                                    <arg>--pinentry-mode</arg>
                                    <arg>loopback</arg>
                                </gpgArguments>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>

        <plugins>
            <!-- Apply enforcer to all builds -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
            </plugin>

            <!-- Sonatype Central Portal publishing (replaces legacy maven-deploy-plugin) -->
            <plugin>
                <groupId>org.sonatype.central</groupId>
                <artifactId>central-publishing-maven-plugin</artifactId>
                <version>${central.publishing.plugin.version}</version>
                <extensions>true</extensions>
                <configuration>
                    <publishingServerId>central</publishingServerId>
                    <autoPublish>true</autoPublish>
                    <waitUntil>published</waitUntil>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <!-- ======================= -->
        <!-- Core Tests Only         -->
        <!-- ======================= -->
        <profile>
            <id>core-tests</id>
            <properties>
                <test.groups>core</test.groups>
                <test.excludedGroups>integration,performance,slow</test.excludedGroups>
            </properties>
        </profile>

        <!-- ======================= -->
        <!-- Integration Tests       -->
        <!-- ======================= -->
        <profile>
            <id>integration-tests</id>
            <properties>
                <test.groups>integration</test.groups>
                <test.excludedGroups />
            </properties>
        </profile>

        <!-- ======================= -->
        <!-- Performance Tests       -->
        <!-- ======================= -->
        <profile>
            <id>performance-tests</id>
            <properties>
                <test.groups>performance</test.groups>
                <test.excludedGroups />
                <test.parallel>none</test.parallel>
            </properties>
        </profile>

        <!-- ======================= -->
        <!-- All Tests               -->
        <!-- ======================= -->
        <profile>
            <id>all-tests</id>
            <properties>
                <test.groups />
                <test.excludedGroups />
                <test.parallel>classes</test.parallel>
                <test.threadCount>2</test.threadCount>
            </properties>
        </profile>

        <!-- ======================= -->
        <!-- Code Coverage           -->
        <!-- ======================= -->
        <profile>
            <id>coverage</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>prepare-agent</id>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>report</id>
                                <phase>test</phase>
                                <goals>
                                    <goal>report</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <argLine>${argLine} -XX:+EnableDynamicAgentLoading</argLine>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- ======================= -->
        <!-- Release Profile         -->
        <!-- ======================= -->
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- ======================= -->
        <!-- Quick Build (Skip Tests)-->
        <!-- ======================= -->
        <profile>
            <id>quick</id>
            <properties>
                <maven.test.skip>true</maven.test.skip>
                <skipTests>true</skipTests>
            </properties>
        </profile>

        <!-- ======================= -->
        <!-- CI Build                -->
        <!-- ======================= -->
        <profile>
            <id>ci</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>prepare-agent</id>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>report</id>
                                <phase>test</phase>
                                <goals>
                                    <goal>report</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <argLine>${argLine} -XX:+EnableDynamicAgentLoading</argLine>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
            <properties>
                <test.parallel>classes</test.parallel>
                <test.threadCount>2</test.threadCount>
            </properties>
        </profile>

    </profiles>

</project>
