<?xml version="1.0"?>
<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>com.feedzai</groupId>
    <artifactId>pdb</artifactId>
    <version>2.7.0</version>
    <name>pdb</name>

    <parent>
        <groupId>org.sonatype.oss</groupId>
        <artifactId>oss-parent</artifactId>
        <version>9</version>
    </parent>

    <url>https://github.com/feedzai/pdb</url>
    <organization>
        <name>Feedzai</name>
        <url>http://www.feedzai.com</url>
    </organization>

    <scm>
        <connection>scm:git:git@github.com:feedzai/pdb.git</connection>
        <developerConnection>scm:git:git@github.com:feedzai/pdb.git</developerConnection>
        <url>git@github.com:feedzai/pdb.git</url>
        <tag>pdb-2.7.0</tag>
    </scm>

    <licenses>
        <license>
            <name>The Apache Software License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <properties>
        <project.source>1.8</project.source>

        <maven-javadoc-plugin.version>3.0.0</maven-javadoc-plugin.version>
        <maven-source-plugin.version>3.0.1</maven-source-plugin.version>
        <maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
    </properties>

    <developers>
        <developer>
            <id>rpvilao</id>
            <name>Rui Vilao</name>
            <email>rui.vilao@feedzai.com</email>
        </developer>
    </developers>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.46</version>
            </dependency>
            <dependency>
                <groupId>org.postgresql</groupId>
                <artifactId>postgresql</artifactId>
                <version>42.2.14</version>
            </dependency>
            <dependency>
                <groupId>com.oracle.ojdbc</groupId>
                <artifactId>ojdbc8</artifactId>
                <version>19.3.0.0</version>
            </dependency>
            <dependency>
                <groupId>com.h2database</groupId>
                <artifactId>h2</artifactId>
                <version>1.4.200</version>
            </dependency>
            <dependency>
                <groupId>com.ibm.db2</groupId>
                <artifactId>jcc</artifactId>
                <version>11.1.4.4</version>
            </dependency>
            <dependency>
                <groupId>com.microsoft.sqlserver</groupId>
                <artifactId>mssql-jdbc</artifactId>
                <version>7.2.2.jre8</version>
            </dependency>
            <dependency>
                <groupId>org.jmockit</groupId>
                <artifactId>jmockit</artifactId>
                <version>1.35</version>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
            </dependency>
            <dependency>
                <groupId>org.assertj</groupId>
                <artifactId>assertj-core</artifactId>
                <version>3.10.0</version>
            </dependency>
            <dependency>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
                <version>18.0</version>
            </dependency>
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
                <version>1.2.3</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>1.7.25</version>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>3.7</version>
            </dependency>
            <dependency>
                <groupId>commons-codec</groupId>
                <artifactId>commons-codec</artifactId>
                <version>1.10</version>
            </dependency>
            <dependency>
                <groupId>com.google.inject</groupId>
                <artifactId>guice</artifactId>
                <version>4.1.0</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <!-- MySQL -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- PostgreSql -->
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- Oracle -->
        <dependency>
            <groupId>com.oracle.ojdbc</groupId>
            <artifactId>ojdbc8</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- H2 -->
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- MS SQL Server -->
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- IBM DB2 -->
        <dependency>
            <groupId>com.ibm.db2</groupId>
            <artifactId>jcc</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- JMockit -->
        <dependency>
            <groupId>org.jmockit</groupId>
            <artifactId>jmockit</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- Junit + AssertJ -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- Guava -->
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
        </dependency>
        <!-- logback -->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- SLF4J -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
        <!-- Commons-lang 3 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
        </dependency>
        <!-- Commons-codec -->
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
        </dependency>
        <!-- Guice -->
        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-release-plugin</artifactId>
                    <version>2.5.3</version>
                </plugin>
                <plugin>
                    <groupId>com.mycila</groupId>
                    <artifactId>license-maven-plugin</artifactId>
                    <version>3.0</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.7.0</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.21.0</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>${maven-source-plugin.version}</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>${maven-javadoc-plugin.version}</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                </plugin>
                <plugin>
                    <groupId>io.fabric8</groupId>
                    <artifactId>docker-maven-plugin</artifactId>
                    <version>0.30.0</version>
                    <executions>
                        <execution>
                            <id>start</id>
                            <phase>test-compile</phase>
                            <goals>
                                <goal>stop</goal>
                                <goal>start</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>stop</id>
                            <phase>test</phase>
                            <goals>
                                <goal>stop</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <verbose>true</verbose>
                        <useColor>true</useColor>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-gpg-plugin</artifactId>
                    <version>${maven-gpg-plugin.version}</version>
                </plugin>
            </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${project.source}</source>
                    <target>${project.source}</target>
                </configuration>
            </plugin>
            <!-- maven-surefire-plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <!-- By default only run the H2 tests. -->
                    <failIfNoTests>false</failIfNoTests>
                    <systemProperties>
                        <instances>h2</instances>
                    </systemProperties>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.mycila</groupId>
                <artifactId>license-maven-plugin</artifactId>
                <configuration>
                    <includes>
                        <include>src/main/**/*.java</include>
                        <include>src/test/**/*.java</include>
                    </includes>
                    <useDefaultExcludes>true</useDefaultExcludes>
                    <properties>
                        <year>2014</year>
                    </properties>
                    <mapping>
                        <java>SLASHSTAR_STYLE</java>
                    </mapping>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <configuration>
                    <localCheckout>true</localCheckout>
                    <pushChanges>false</pushChanges>
                </configuration>
            </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>
                        <phase>deploy</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>${maven-javadoc-plugin.version}</version>
                <configuration>
                    <doclint>none</doclint>
                </configuration>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </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>deploy</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- explicitly define maven-deploy-plugin after others to force exec order -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <executions>
                    <execution>
                        <id>deploy</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>deploy</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <distributionManagement>
        <snapshotRepository>
            <id>sonatype-nexus-snapshots</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>

    <profiles>
        <profile>
            <id>h2remote</id>
            <dependencies>
                <dependency>
                    <groupId>com.h2database</groupId>
                    <artifactId>h2</artifactId>
                </dependency>
            </dependencies>

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <systemProperties>
                                <instances>h2remote</instances>
                            </systemProperties>
                        </configuration>
                    </plugin>

                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.6.0</version>
                        <executions>
                            <execution>
                                <phase>test-compile</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <executable>java</executable>
                            <arguments>
                                <argument>-classpath</argument>
                                <!-- automatically creates the classpath using all project dependencies,
                                     also adding the project build directory -->
                                <classpath />
                                <argument>org.h2.tools.Server</argument>
                                <!-- make db available via tcp -->
                                <argument>-tcp</argument>
                                <!-- set local file inside test output directory -->
                                <argument>-baseDir</argument>
                                <argument>${project.build.testOutputDirectory}/pdb-h2-remote</argument>
                                <!-- allows databases to be created when accessed -->
                                <argument>-ifNotExists</argument>
                            </arguments>
                            <async>true</async>
                            <asyncDestroyOnShutdown>true</asyncDestroyOnShutdown>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>mysql</id>
            <properties>
                <image.mysql>mysql:5.7.22</image.mysql>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <systemProperties>
                                <instances>mysql</instances>
                            </systemProperties>
                        </configuration>
                    </plugin>

                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <configuration>
                            <images>
                                <image>
                                    <name>${image.mysql}</name>
                                    <alias>pdb-mysql</alias>
                                    <run>
                                        <namingStrategy>alias</namingStrategy>
                                        <hostname>pdb-mysql</hostname>
                                        <ports>
                                            <port>3306:3306</port>
                                        </ports>
                                        <env>
                                            <MYSQL_ROOT_PASSWORD>AaBb12.#</MYSQL_ROOT_PASSWORD>
                                        </env>
                                        <cmd>--max-allowed-packet=16000000 --innodb-log-file-size=160000000</cmd>
                                        <wait>
                                            <time>40000</time>
                                            <log>MySQL init process done. Ready for start up.</log>
                                        </wait>
                                    </run>
                                </image>
                            </images>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>sqlserver</id>
            <properties>
                <image.sqlserver>mcr.microsoft.com/mssql/server:2017-CU17</image.sqlserver>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <systemProperties>
                                <instances>sqlserver</instances>
                            </systemProperties>
                        </configuration>
                    </plugin>

                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <configuration>
                            <images>
                                <image>
                                    <name>${image.sqlserver}</name>
                                    <alias>pdb-sqlserver</alias>
                                    <run>
                                        <namingStrategy>alias</namingStrategy>
                                        <hostname>pdb-sqlserver</hostname>
                                        <ports>
                                            <port>1433:1433</port>
                                        </ports>
                                        <env>
                                            <ACCEPT_EULA>Y</ACCEPT_EULA>
                                            <SA_PASSWORD>AaBb12.#</SA_PASSWORD>
                                        </env>
                                        <wait>
                                            <time>40000</time>
                                            <log>Service Broker manager has started</log>
                                            <exec>
                                                <!--
                                                Prepare a new "pdb" database for tests with READ_COMMITTED_SNAPSHOT enabled
                                                 (required for SQL server to have the same behavior as other DBs in READ_COMMITTED
                                                 isolation level) and ALLOW_SNAPSHOT_ISOLATION enabled to allow using the
                                                 TRANSACTION_SNAPSHOT level (equivalent to SERIALIZABLE in PostgreSQL and Oracle).
                                                A new database needs to be used because the flags can't be enabled on "master" database.
                                                -->
                                                <postStart>/opt/mssql-tools/bin/sqlcmd -l 45 -U sa -P AaBb12.# -Q CREATE\ DATABASE\ pdb;\ ALTER\ DATABASE\ pdb\ SET\ READ_COMMITTED_SNAPSHOT\ ON;\ ALTER\ DATABASE\ pdb\ SET\ ALLOW_SNAPSHOT_ISOLATION\ ON</postStart>
                                            </exec>
                                        </wait>
                                    </run>
                                </image>
                            </images>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>postgresql</id>
            <properties>
                <image.postgresql>postgres:9.6.14</image.postgresql>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <systemProperties>
                                <instances>postgresql</instances>
                            </systemProperties>
                        </configuration>
                    </plugin>

                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <configuration>
                            <images>
                                <image>
                                    <name>${image.postgresql}</name>
                                    <alias>pdb-postgresql</alias>
                                    <run>
                                        <namingStrategy>alias</namingStrategy>
                                        <hostname>pdb-postgresql</hostname>
                                        <ports>
                                            <port>5432:5432</port>
                                        </ports>
                                        <env>
                                            <POSTGRES_PASSWORD>AaBb12.#</POSTGRES_PASSWORD>
                                        </env>
                                        <wait>
                                            <time>40000</time>
                                            <log>PostgreSQL init process complete; ready for start up</log>
                                        </wait>
                                    </run>
                                </image>
                            </images>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>cockroach</id>
            <properties>
                <image.cockroach>cockroachdb/cockroach:v19.2.0</image.cockroach>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <systemProperties>
                                <instances>cockroach</instances>
                            </systemProperties>
                            <excludedGroups>com.feedzai.commons.sql.abstraction.engine.impl.cockroach.SkipTestCockroachDB</excludedGroups>
                        </configuration>
                    </plugin>

                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <configuration>
                            <images>
                                <image>
                                    <name>${image.cockroach}</name>
                                    <alias>pdb-cockroach</alias>
                                    <run>
                                        <namingStrategy>alias</namingStrategy>
                                        <hostname>pdb-cockroach</hostname>
                                        <ports>
                                            <port>8080:8080</port>
                                            <port>26257:26257</port>
                                        </ports>
                                        <cmd>start --insecure</cmd>
                                        <wait>
                                            <time>40000</time>
                                            <log>CockroachDB node starting</log>
                                        </wait>
                                    </run>
                                </image>
                            </images>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>oracle</id>
            <properties>
                <image.oracle>iatebes/oracle_11g:latest</image.oracle>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <!--
                             The following line is a workaround for "ORA-01882: timezone region not found"
                             that occurs when the Oracle DB server doesn't have the system timezone
                             -->
                            <argLine>-Doracle.jdbc.timezoneAsRegion=false</argLine>
                            <systemProperties>
                                <instances>oracle</instances>
                            </systemProperties>
                        </configuration>
                    </plugin>

                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <configuration>
                            <images>
                                <image>
                                    <name>${image.oracle}</name>
                                    <alias>pdb-oracle</alias>
                                    <run>
                                        <namingStrategy>alias</namingStrategy>
                                        <hostname>pdb-oracle</hostname>
                                        <ports>
                                            <port>1521:1521</port>
                                        </ports>
                                        <wait>
                                            <time>40000</time>
                                            <log>Disconnected from Oracle Database 11g</log>
                                        </wait>
                                    </run>
                                </image>
                            </images>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>db2</id>
            <properties>
                <image.db2>ibmcom/db2:11.5.0.0</image.db2>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <systemProperties>
                                <instances>db2</instances>
                            </systemProperties>
                        </configuration>
                    </plugin>

                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <configuration>
                            <images>
                                <image>
                                    <name>${image.db2}</name>
                                    <alias>pdb-db2</alias>
                                    <run>
                                        <namingStrategy>alias</namingStrategy>
                                        <hostname>pdb-db2</hostname>
                                        <ports>
                                            <port>50000:50000</port>
                                        </ports>
                                        <privileged>true</privileged>
                                        <env>
                                            <LICENSE>accept</LICENSE>
                                            <DB2INST1_PASSWORD>AaBb12.#</DB2INST1_PASSWORD>
                                            <DBNAME>testdb</DBNAME>
                                        </env>
                                        <wait>
                                            <time>360000</time>
                                            <log>All databases are now active.</log>
                                        </wait>
                                    </run>
                                </image>
                            </images>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
