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

<!--
    Copyright (C) 2019 Vitasystems GmbH and Hannover Medical School.

    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>0.21.0</version>
        <relativePath>/bom/pom.xml</relativePath>
    </parent>

    <groupId>org.ehrbase.openehr</groupId>
    <artifactId>server</artifactId>
    <version>0.21.0</version>
    <packaging>pom</packaging>

    <modules>
        <module>bom</module>
        <module>api</module>
        <module>application</module>
        <module>base</module>
        <module>jooq-pq</module>
        <module>rest-ehr-scape</module>
        <module>rest-openehr</module>
        <module>service</module>
        <module>test-coverage</module>
        <module>plugin</module>
    </modules>



    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!-- PostgreSQL Database Properties -->
        <database.host>localhost</database.host>
        <database.port>5432</database.port>
        <database.user>ehrbase</database.user>
        <database.pass>ehrbase</database.pass>
        <database.name>ehrbase</database.name>
        <test.profile>unit</test.profile>
    </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.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>
                </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>
                <version>${maven-surefire-plugin.version}</version>
                <configuration>
                    <skipTests>true</skipTests>
                    <!-- SETS THE VM ARGUMENT LINE USED WHEN UNIT TESTS ARE RUN. -->
                    <argLine>${surefireArgLine}</argLine>
                </configuration>
                <executions>
                    <execution>
                        <id>${test.profile} tests</id>
                        <phase>test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <skipTests>false</skipTests>
                            <includes>
                                <include>${include.tests}</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </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>
                <version>${maven-failsafe-plugin.version}</version>
                <configuration>
                    <skipITs>${skipIntegrationTests}</skipITs>
                    <additionalClasspathElements>
                        <additionalClasspathElement>${basedir}/target/classes</additionalClasspathElement>
                    </additionalClasspathElements>
                </configuration>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                        <configuration>
                            <!-- SETS THE VM ARGUMENT LINE USED WHEN INTEGRATION TESTS ARE RUN. -->
                            <argLine>${failsafeArgLine}</argLine>
                            <includes>
                                <include>**/*IT.java</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>3.0.0</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>
        </plugins>


    </build>

    <profiles>
        <!-- RUN UNIT TESTS ONLY -->
        <profile>
            <id>fast</id>
            <properties>
                <include.tests>**/*Test.java</include.tests>
                <test.profile>unit</test.profile>
            </properties>
        </profile>

        <!-- RUN INTEGRATION TESTS ONLY -->
        <profile>
            <id>slow</id>
            <properties>
                <include.tests>**/*IT.java</include.tests>
                <test.profile>integration</test.profile>
            </properties>
        </profile>

        <!-- RUN ALL JAVA TESTS (UNIT & INTEGRATION) -->
        <profile>
            <id>full</id>
            <properties>
                <include.tests>**/*</include.tests>
                <test.profile>all</test.profile>
            </properties>
        </profile>

        <profile>
            <id>release</id>
            <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>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
