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

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    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">

    <parent>
        <groupId>io.gravitee.am.dataplane</groupId>
        <artifactId>gravitee-am-dataplane</artifactId>
        <version>4.8.40</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>

    <artifactId>gravitee-am-dataplane-jdbc</artifactId>
    <name>Gravitee IO - Access Management - DataPlane JDBC</name>

    <properties>
        <dozer.version>6.5.2</dozer.version>

        <liquibase-slf4j.version>4.0.0</liquibase-slf4j.version>

        <skip-repositories-tests>true</skip-repositories-tests>

        <maven-dependency-plugin.version>2.10</maven-dependency-plugin.version>
        <dozer-jaxb-runtime.version>2.4.0-b180830.0438</dozer-jaxb-runtime.version>
        <jdbcType>postgresql-tc~17.2</jdbcType>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.glassfish.jaxb</groupId>
                <artifactId>jaxb-runtime</artifactId>
                <version>${dozer-jaxb-runtime.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>

        <dependency>
            <groupId>io.gravitee.am.dataplane</groupId>
            <artifactId>gravitee-am-dataplane-api</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>io.gravitee.am.repository</groupId>
            <artifactId>gravitee-am-repository-api</artifactId>
            <version>${project.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>io.gravitee.am.repository</groupId>
            <artifactId>gravitee-am-repository-jdbc-api</artifactId>
            <version>${project.version}</version>
        </dependency>

        <!-- Spring dependencies -->
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>io.projectreactor</groupId>
            <artifactId>reactor-core</artifactId>
            <version>${reactor-core.version}</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.projectreactor.addons/reactor-adapter -->
        <dependency>
            <groupId>io.projectreactor.addons</groupId>
            <artifactId>reactor-adapter</artifactId>
            <version>${reactor-adapter.version}</version>
        </dependency>

        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-transport-native-unix-common</artifactId>
        </dependency>

        <!-- Liquibase -->
        <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
            <version>${liquibase.version}</version>
        </dependency>
        <dependency>
            <groupId>com.mattbertolini</groupId>
            <artifactId>liquibase-slf4j</artifactId>
            <version>${liquibase-slf4j.version}</version>
        </dependency>

        <!-- R2DBC -->
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>r2dbc-postgresql</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>reactor-core</artifactId>
                    <groupId>io.projectreactor</groupId>
                </exclusion>
            </exclusions>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>io.r2dbc</groupId>
            <artifactId>r2dbc-mssql</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>reactor-core</artifactId>
                    <groupId>io.projectreactor</groupId>
                </exclusion>
            </exclusions>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>io.asyncer</groupId>
            <artifactId>r2dbc-mysql</artifactId>
            <version>${r2dbc-mysql.version}</version>
            <exclusions>
                <exclusion>
                    <artifactId>reactor-core</artifactId>
                    <groupId>io.projectreactor</groupId>
                </exclusion>
            </exclusions>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.mariadb</groupId>
            <artifactId>r2dbc-mariadb</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>reactor-core</artifactId>
                    <groupId>io.projectreactor</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>r2dbc-spi</artifactId>
                    <groupId>io.r2dbc</groupId>
                </exclusion>
            </exclusions>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <!--
            Gravitee only uses this dependency to test the connectivity to MySQL databases
            and does not supply or bundle the mysql-connector-java in the software as per the license in:
            https://github.com/mysql/mysql-connector-j/blob/release/8.0/LICENSE
            -->
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${jdbc-mysql.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>${jdbc-postgresql.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <!--
            Gravitee only uses this dependency to test the connectivity to MariaDB databases
            and does not supply or bundle the mariadb-java-client in the software as per the license in:
            https://github.com/mariadb-corporation/mariadb-connector-j/blob/master/LICENSE
            -->
            <groupId>org.mariadb.jdbc</groupId>
            <artifactId>mariadb-java-client</artifactId>
            <version>${jdbc-mariadb.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>${jdbc-mssql.version}</version>
            <scope>provided</scope>
        </dependency>


        <!-- bean mapper -->
        <dependency>
            <groupId>com.github.dozermapper</groupId>
            <artifactId>dozer-core</artifactId>
            <version>${dozer.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <artifactId>commons-io</artifactId>
                    <groupId>commons-io</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>javax.el</groupId>
            <artifactId>javax.el-api</artifactId>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jdk8</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>${commons-io.version}</version>
        </dependency>

        <!-- Test dependencies -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>testcontainers</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>testcontainers-r2dbc</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <artifactId>r2dbc-spi</artifactId>
                    <groupId>io.r2dbc</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>testcontainers-postgresql</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <artifactId>r2dbc-spi</artifactId>
                    <groupId>io.r2dbc</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>testcontainers-mysql</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <artifactId>r2dbc-spi</artifactId>
                    <groupId>io.r2dbc</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>testcontainers-mariadb</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <artifactId>r2dbc-spi</artifactId>
                    <groupId>io.r2dbc</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>testcontainers-mssqlserver</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <artifactId>r2dbc-spi</artifactId>
                    <groupId>io.r2dbc</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>io.gravitee.am.dataplane</groupId>
            <artifactId>gravitee-am-dataplane-tests</artifactId>
            <version>${project.version}</version>
            <classifier>tests</classifier>
            <scope>test</scope>
        </dependency>

        <!--
        https://mvnrepository.com/artifact/org.yaml/snakeyaml
        SnakeYaml required by liquibase to parse changelogs.
        this dependency is provided by gravitee-node but we have to
        add it in the test scope to run JUnit with TestContainer...
        -->
        <dependency>
            <groupId>org.yaml</groupId>
            <artifactId>snakeyaml</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.gravitee.node</groupId>
            <artifactId>gravitee-node-monitoring</artifactId>
            <version>${gravitee-node.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <profiles>
        <profile>
            <id>postgres</id>
            <properties>
                <jdbcType>${testcontainer-upper-version-psql}</jdbcType>
            </properties>
        </profile>
        <profile>
            <id>mysql</id>
            <properties>
                <jdbcType>${testcontainer-upper-version-mysql}</jdbcType>
            </properties>
        </profile>
        <profile>
            <id>mariadb</id>
            <properties>
                <jdbcType>${testcontainer-upper-version-maria}</jdbcType>
            </properties>
        </profile>
        <profile>
            <id>mssql</id>
            <properties>
                <jdbcType>${testcontainer-upper-version-mssql}</jdbcType>
            </properties>
        </profile>
        <profile>
            <id>postgres-min</id>
            <properties>
                <jdbcType>${testcontainer-lower-version-psql}</jdbcType>
            </properties>
        </profile>
        <profile>
            <id>mysql-min</id>
            <properties>
                <jdbcType>${testcontainer-lower-version-mysql}</jdbcType>
            </properties>
        </profile>
        <profile>
            <id>mariadb-min</id>
            <properties>
                <jdbcType>${testcontainer-lower-version-maria}</jdbcType>
            </properties>
        </profile>
        <profile>
            <id>mssql-min</id>
            <properties>
                <jdbcType>${testcontainer-lower-version-mssql}</jdbcType>
            </properties>
        </profile>
        <profile>
            <id>cicd-jdbc</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <skipTests>false</skipTests>
                            <argLine>-Xmx1024m</argLine>
                            <systemPropertyVariables>
                                <jdbcType>${jdbcType}</jdbcType>
                            </systemPropertyVariables>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>cicd-full</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <skipTests>false</skipTests>
                            <argLine>-Xmx1024m</argLine>
                            <systemPropertyVariables>
                                <jdbcType>${testcontainer-upper-version-psql}</jdbcType>
                            </systemPropertyVariables>
                        </configuration>
                        <executions>
                            <execution>
                                <id>mysql-8</id>
                                <goals>
                                    <goal>test</goal>
                                </goals>
                                <configuration>
                                    <systemPropertyVariables>
                                        <jdbcType>${testcontainer-upper-version-mysql}</jdbcType>
                                    </systemPropertyVariables>
                                </configuration>
                            </execution>
                            <execution>
                                <id>mariadb-10.5</id>
                                <goals>
                                    <goal>test</goal>
                                </goals>
                                <configuration>
                                    <systemPropertyVariables>
                                        <jdbcType>${testcontainer-upper-version-maria}</jdbcType>
                                    </systemPropertyVariables>
                                </configuration>
                            </execution>
                            <execution>
                                <id>sqlserver-2019</id>
                                <goals>
                                    <goal>test</goal>
                                </goals>
                                <configuration>
                                    <systemPropertyVariables>
                                        <jdbcType>${testcontainer-upper-version-mssql}</jdbcType>
                                    </systemPropertyVariables>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <appendAssemblyId>false</appendAssemblyId>
                    <descriptors>
                        <descriptor>src/main/assembly/plugin-assembly.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>make-plugin-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>${maven-dependency-plugin.version}</version>
                <executions>
                    <execution>
                        <id>unpack-repository-tests</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <includeGroupIds>io.gravitee.am.dataplane</includeGroupIds>
                            <includeArtifactIds>gravitee-am-dataplane-tests</includeArtifactIds>
                            <includeClassifiers>tests</includeClassifiers>
                            <outputDirectory>${project.build.directory}/test-classes</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skipTests>${skip-repositories-tests}</skipTests>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
