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

<!--
    Copyright (c) 2024 vitasystems GmbH.

    This file is part of Project EHRbase

    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>

  <parent>
    <groupId>org.ehrbase.openehr</groupId>
    <artifactId>bom</artifactId>
    <version>2.33.0</version>
    <relativePath>/bom/pom.xml</relativePath>
  </parent>

  <artifactId>server</artifactId>
  <version>2.33.0</version>
  <packaging>pom</packaging>
  <name>EHRbase server</name>
  <description>EHRbase openEHR server</description>

  <repositories>
    <!-- Repository for openEHR-SDK snapshots -->
    <repository>
      <id>central-snapshots</id>
      <url>https://central.sonatype.com/repository/maven-snapshots</url>
      <releases>
        <enabled>false</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
  </repositories>

  <modules>
    <module>bom</module>
    <module>application</module>
    <module>api</module>
    <module>cli</module>
    <module>jooq-pg</module>
    <module>rest-ehr-scape</module>
    <module>rest-openehr</module>
    <module>service</module>
    <module>test-coverage</module>
    <module>plugin</module>
    <module>rm-db-format</module>
    <module>aql-engine</module>
    <module>configuration</module>
  </modules>

  <properties>
    <maven.compiler.source>25</maven.compiler.source>
    <maven.compiler.target>25</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <!-- PostgreSQL Database Properties -->
    <database.host>localhost</database.host>
    <!-- use a port different from the default postgres port, so people do not have to stop their postgres servers-->
    <database.port>5449</database.port>
    <database.user>ehrbase</database.user>
    <database.pass>ehrbase</database.pass>
    <database.name>ehrbase</database.name>
    <database.timeout>120000</database.timeout>
    <database.external>false</database.external>
    <skipTests>false</skipTests>
    <skipITs>false</skipITs>
    <failsafeArgLine/>
    <surefireArgLine/>
  </properties>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>versions-maven-plugin</artifactId>
        <configuration>
          <generateBackupPoms>false</generateBackupPoms>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>${maven-jacoco-plugin.version}</version>
        <executions>
          <!-- SET ARG LINE PROPERTY FOR SUREFIRE -->
          <execution>
            <id>agent for unit tests</id>
            <goals>
              <goal>prepare-agent</goal>
            </goals>
            <configuration>
              <propertyName>surefireArgLine</propertyName>
            </configuration>
          </execution>
          <!-- SET ARG LINE PROPERTY FOR FAILSAFE -->
          <execution>
            <id>agent for integration tests</id>
            <goals>
              <goal>prepare-agent-integration</goal>
            </goals>
            <configuration>
              <propertyName>failsafeArgLine</propertyName>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <!-- HANDLES JUNIT UNIT TESTS -->
        <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <!-- SETS THE VM ARGUMENT LINE USED WHEN UNIT TESTS ARE RUN. -->
          <argLine>@{surefireArgLine}</argLine>
          <skipTests>${skipTests}</skipTests>
            <!-- Ensure tests have a stable local to prevent localized
            XML parsing error messages -->
            <systemPropertyVariables>
                <user.language>en</user.language>
                <user.region>US</user.region>
            </systemPropertyVariables>
          <includes>
            <include>**/*Test.java</include>
          </includes>
        </configuration>
      </plugin>
      <plugin>
        <!-- HANDLES JUNIT INTEGRATION TESTS -->
        <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-failsafe-plugin -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <configuration>
          <skipITs>${skipITs}</skipITs>
          <additionalClasspathElements>
            <additionalClasspathElement>${basedir}/target/classes</additionalClasspathElement>
          </additionalClasspathElements>
          <!-- SETS THE VM ARGUMENT LINE USED WHEN INTEGRATION TESTS ARE RUN. -->
          <argLine>@{failsafeArgLine}</argLine>
          <includes>
            <include>**/*IT.java</include>
          </includes>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>3.6.3</version>
        <configuration>
          <rules>
            <bannedDependencies>
              <searchTransitive>true</searchTransitive>
              <excludes>
                <exclude>org.apache.logging.log4j</exclude>
              </excludes>

            </bannedDependencies>
            <requireMavenVersion>
              <version>3.0</version>
            </requireMavenVersion>
          </rules>
          <fail>true</fail>
        </configuration>
        <executions>
          <execution>
            <id>enforce-banned-dependencies</id>
            <goals>
              <goal>enforce</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>com.diffplug.spotless</groupId>
        <artifactId>spotless-maven-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <!-- RUN UNIT TESTS ONLY -->
    <profile>
      <id>fast</id>
      <properties>
        <skipTests>false</skipTests>
        <skipITs>true</skipITs>
      </properties>
    </profile>

    <!-- RUN INTEGRATION TESTS ONLY -->
    <profile>
      <id>slow</id>
      <properties>
        <skipTests>true</skipTests>
        <skipITs>false</skipITs>
      </properties>
    </profile>

    <!-- RUN ALL JAVA TESTS (UNIT & INTEGRATION) -->
    <profile>
      <id>full</id>
      <properties>
        <skipTests>false</skipTests>
        <skipITs>false</skipITs>
      </properties>
    </profile>

    <profile>
      <id>release</id>
      <properties>
        <skipTests>true</skipTests>
        <skipITs>true</skipITs>
      </properties>
      <build>
        <plugins>
          <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>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <executions>
              <execution>
                <id>attach-javadocs</id>
                <goals>
                  <goal>jar</goal>
                </goals>
                <configuration>
                  <additionalJOption>-Xdoclint:none</additionalJOption>
                </configuration>
              </execution>
            </executions>
          </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>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
