<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>4.0.6</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>
  
  <groupId>br.com.tasknoteapp</groupId>
  <artifactId>server</artifactId>
  <version>21</version>
  <name>tasknote-api</name>
  <description>Java backend REST API to serve TaskNote frontend client</description>
  
  <!-- URL -->
  <url/>

  <!-- License -->
  <licenses>
    <license/>
  </licenses>
  
  <!-- Developers -->
  <developers>
    <developer/>
  </developers>

  <scm>
    <connection/>
    <developerConnection/>
    <tag/>
    <url/>
  </scm>
  
  <!-- Properties -->
  <properties>
    <java.version>25</java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <skip.integration.tests>true</skip.integration.tests>
    <skip.unit.tests>true</skip.unit.tests>
    <jacoco.skip>true</jacoco.skip>
    <checkstyle.skip>true</checkstyle.skip>
    <checkstyle.failsOnError>true</checkstyle.failsOnError>
    <checkstyle.includeTestSourceDirectory>true</checkstyle.includeTestSourceDirectory>
    <jacoco.output.data>${project.build.directory}/coverage-reports</jacoco.output.data>
    <timestamp>${maven.build.timestamp}</timestamp>
    <maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
    <failsafe.version>3.5.5</failsafe.version>
    <surefire.version>3.5.5</surefire.version>
    <jacoco.version>0.8.14</jacoco.version>
    <checkstyle.version>3.6.0</checkstyle.version>
    <springboot.version>4.0.6</springboot.version>
    <jjwt.version>0.12.6</jjwt.version>
  </properties>

  <!-- Profiles -->
  <profiles>
    <!-- All tests -->
    <profile>
      <id>tests</id>
      <properties>
        <build.profile.id>tests</build.profile.id>
        <skip.integration.tests>false</skip.integration.tests>
        <skip.unit.tests>false</skip.unit.tests>
        <jacoco.skip>false</jacoco.skip>
        <checkstyle.skip>false</checkstyle.skip>
      </properties>
    </profile>

    <!-- Prod -->
    <profile>
      <id>prod</id>
      <properties>
        <build.profile.id>prod</build.profile.id>
      </properties>
    </profile>
  </profiles>

  <!-- Dependencies -->
  <dependencies>
    
    <!-- Spring -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-webmvc</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-restclient</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-validation</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-mail</artifactId>
    </dependency>

    <!-- Database -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
      <groupId>org.postgresql</groupId>
      <artifactId>postgresql</artifactId>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-flyway</artifactId>
    </dependency>
    <dependency>
      <groupId>org.flywaydb</groupId>
      <artifactId>flyway-core</artifactId>
    </dependency>
    <dependency>
      <groupId>org.flywaydb</groupId>
      <artifactId>flyway-database-postgresql</artifactId>
    </dependency>

    <!-- Testing -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test-classic</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-security-test</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
      <scope>test</scope>
    </dependency>

    <!-- Authentication -->
    <dependency>
      <groupId>io.jsonwebtoken</groupId>
      <artifactId>jjwt-api</artifactId>
      <version>${jjwt.version}</version>
    </dependency>
    <dependency>
      <groupId>io.jsonwebtoken</groupId>
      <artifactId>jjwt-impl</artifactId>
      <version>${jjwt.version}</version>
    </dependency>
    <dependency>
      <groupId>io.jsonwebtoken</groupId>
      <artifactId>jjwt-gson</artifactId>
      <version>${jjwt.version}</version>
    </dependency>

  </dependencies>

  <build>
    <plugins> 
      <plugin>
        <groupId>org.hibernate.orm</groupId>
        <artifactId>hibernate-maven-plugin</artifactId>
        <version>${hibernate.version}</version>
        <executions>
          <execution>
            <id>enhance</id>
            <goals>
              <goal>enhance</goal>
            </goals>
            <configuration>
              <enableLazyInitialization>true</enableLazyInitialization>
              <enableDirtyTracking>true</enableDirtyTracking>
              <enableAssociationManagement>false</enableAssociationManagement>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>${failsafe.version}</version>
        <executions>
          <execution>
            <id>integration-tests</id>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
            <configuration>
              <argLine>@{argLine} -Xmx1024m</argLine>
              <useSystemClassLoader>false</useSystemClassLoader>
              <skipTests>${skip.integration.tests}</skipTests>
              <includes>
                <include>**/*IntTest.java</include>
              </includes>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
	      <version>${surefire.version}</version>
        <configuration>
          <argLine>@{argLine} -Xmx1024m</argLine>
          <skipTests>${skip.unit.tests}</skipTests>
          <excludes>
            <exclude>**/*IntTest.java</exclude>
          </excludes>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>${jacoco.version}</version>
        <configuration>
          <skip>${jacoco.skip}</skip>
          <excludes>
            <exclude>**/config/**</exclude>
            <exclude>**/entity/**</exclude>
            <exclude>**/exception/**</exclude>
            <exclude>**/filter/**</exclude>
            <exclude>**/*$*Builder*</exclude>
            <exclude>**/RestExceptionEndpoint.*</exclude>
            <exclude>**/JavaApiApiApplication.*</exclude>
          </excludes>
        </configuration>
        <executions>
          <execution>
            <id>pre-unit-test</id>
            <goals>
              <goal>prepare-agent</goal>
            </goals>
            <configuration>
              <destFile>${jacoco.output.data}/jacoco-ut.exec</destFile>
            </configuration>
          </execution>
          <execution>
            <id>post-unit-test</id>
            <phase>test</phase>
            <goals>
              <goal>report</goal>
            </goals>
            <configuration>
              <dataFile>${jacoco.output.data}/jacoco-ut.exec</dataFile>
              <outputDirectory>${jacoco.output.data}/jacoco-ut</outputDirectory>
            </configuration>
          </execution>
          <execution>
            <id>pre-integration-test</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>prepare-agent-integration</goal>
            </goals>
            <configuration>
              <destFile>${jacoco.output.data}/jacoco-it.exec</destFile>
            </configuration>
          </execution>
          <execution>
            <id>post-integration-test</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>report-integration</goal>
            </goals>
            <configuration>
              <dataFile>${jacoco.output.data}/jacoco-it.exec</dataFile>
              <outputDirectory>${jacoco.output.data}/jacoco-it</outputDirectory>
            </configuration>
          </execution>
          <execution>
            <id>merge-unit-and-integration</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>merge</goal>
            </goals>
            <configuration>
              <fileSets>
                <fileSet>
                  <directory>${jacoco.output.data}</directory>
                  <includes>
                    <include>*.exec</include>
                  </includes>
                </fileSet>
              </fileSets>
              <destFile>${project.build.directory}/jacoco.exec</destFile>
            </configuration>
          </execution>
          <execution>
            <id>merged-reports</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>report</goal>
            </goals>
            <configuration>
              <dataFile>${project.build.directory}/jacoco.exec</dataFile>
              <outputDirectory>${jacoco.output.data}/merged-test-report</outputDirectory>
            </configuration>
          </execution>
          <execution>
            <id>coverage-check</id>
            <goals>
              <goal>check</goal>
            </goals>
            <configuration>
              <rules>
                <rule>
                  <element>BUNDLE</element>
                  <limits>
                    <limit>
                      <counter>LINE</counter>
                      <value>COVEREDRATIO</value>
                      <minimum>75%</minimum>
                    </limit>
                  </limits>
                </rule>
              </rules>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>${checkstyle.version}</version>
        <dependencies>
          <dependency>
            <groupId>com.puppycrawl.tools</groupId>
            <artifactId>checkstyle</artifactId>
            <version>13.3.0</version>
          </dependency>
        </dependencies>
        <configuration>
          <skip>${checkstyle.skip}</skip>
          <failsOnError>${checkstyle.failsOnError}</failsOnError>
          <includeTestSourceDirectory>
            ${checkstyle.includeTestSourceDirectory}
          </includeTestSourceDirectory>
          <configLocation>.mvn/google_checks.xml</configLocation>
          <consoleOutput>true</consoleOutput>
          <linkXRef>false</linkXRef>
        </configuration>
        <executions>
          <execution>
            <id>validate</id>
            <phase>validate</phase>
            <goals>
              <goal>check</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.graalvm.buildtools</groupId>
        <artifactId>native-maven-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-maven-plugin</artifactId>
	<version>${springboot.version}</version>
        <configuration>
          <image>
            <name>ghcr.io/rmcampos/tasknote/api:latest</name>
            <buildpacks>
                <buildpack>file://${project.basedir}/buildpacks/healthcheck</buildpack>
                <buildpack>urn:cnb:builder:paketo-buildpacks/java-native-image</buildpack>
            </buildpacks>
        </image>
      </configuration>
        <executions>
          <execution>
              <goals>
                  <goal>build-info</goal>
              </goals>
              <configuration>
                  <additionalProperties>
                      <timestamp>${maven.build.timestamp}</timestamp>
                  </additionalProperties>
              </configuration>
          </execution>
      </executions>
      </plugin>
    </plugins>

    <finalName>tasknote-api</finalName>
  </build>

</project>
