<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.github.yuizho</groupId>
    <artifactId>db-raccoon</artifactId>
    <version>0.2.0</version>
    <name>db-raccoon</name>
    <url>https://github.com/yuizho/db-raccoon</url>
    <description>A JUnit5 extension to make the test data setup easier.</description>

    <licenses>
        <license>
            <name>MIT License</name>
            <url>http://opensource.org/licenses/MIT</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <developers>
        <developer>
            <name>Yui Ito</name>
            <email>yuizho3@gmail.com</email>
        </developer>
    </developers>

    <scm>
        <url>https://github.com/yuizho/db-raccoon</url>
        <connection>scm:git:git://github.com/yuizho/db-raccoon.git</connection>
        <developerConnection>scm:git:git://github.com/yuizho/db-raccoon.git</developerConnection>
    </scm>

    <distributionManagement>
        <snapshotRepository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
        <repository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
        </repository>
    </distributionManagement>

    <properties>
        <java.version>1.8</java.version>
        <kotlin.version>1.3.61</kotlin.version>
        <jupiter.version>5.6.0</jupiter.version>
        <commons-csv.version>1.8</commons-csv.version>
        <slf4j.version>1.7.30</slf4j.version>
        <assertj.version>3.15.0</assertj.version>
        <mockito.version>3.2.4</mockito.version>
        <mockk.version>1.9.3</mockk.version>
        <h2.version>1.4.200</h2.version>
        <mysql.version>8.0.19</mysql.version>
        <postgres.version>12.2</postgres.version>
        <postgres-jdbc.version>42.2.9</postgres-jdbc.version>
        <surefire-plugin.version>2.22.2</surefire-plugin.version>
        <failsafe-plugin.version>2.22.2</failsafe-plugin.version>
        <dokka-plugin.version>0.9.18</dokka-plugin.version>
        <assembly-plugin.version>3.2.0</assembly-plugin.version>
        <flyway-plugin.version>6.2.2</flyway-plugin.version>
        <jacoco-plugin.version>0.8.5</jacoco-plugin.version>
        <docker-plugin.version>0.33.0</docker-plugin.version>
        <test-mysql.port>13306</test-mysql.port>
        <test-mysql.user>test</test-mysql.user>
        <test-mysql.password>password</test-mysql.password>
        <test-mysql.db>testdb</test-mysql.db>
        <test-postgres.port>15432</test-postgres.port>
        <test-postgres.user>test</test-postgres.user>
        <test-postgres.password>password</test-postgres.password>
        <test-postgres.db>testdb</test-postgres.db>
    </properties>

    <dependencies>
        <!-- libs -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${jupiter.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-csv</artifactId>
            <version>${commons-csv.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>


        <!-- kotlin -->
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib-jdk8</artifactId>
            <version>${kotlin.version}</version>
        </dependency>

        <!-- testing -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${jupiter.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-params</artifactId>
            <version>${jupiter.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-test</artifactId>
            <version>${kotlin.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <version>${assertj.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>${mockito.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.mockk</groupId>
            <artifactId>mockk</artifactId>
            <version>${mockk.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>${slf4j.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>${h2.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>${postgres-jdbc.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <id>deploy</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>3.2.1</version>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>1.6</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                                <configuration>
                                    <!-- Prevent `gpg` from using pinentry programs -->
                                    <gpgArguments>
                                        <arg>--pinentry-mode</arg>
                                        <arg>loopback</arg>
                                    </gpgArguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <build>
        <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
        <testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
        <plugins>
            <!-- https://junit.org/junit5/docs/current/user-guide/#running-tests-build-maven -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${surefire-plugin.version}</version>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>${failsafe-plugin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-maven-plugin</artifactId>
                <version>${kotlin.version}</version>
                <executions>
                    <execution>
                        <id>compile</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>test-compile</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <executions>
                    <execution>
                        <id>compile</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>testCompile</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco-plugin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>report</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.jetbrains.dokka</groupId>
                <artifactId>dokka-maven-plugin</artifactId>
                <version>${dokka-plugin.version}</version>
                <executions>
                    <execution>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>dokka</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>${assembly-plugin.version}</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <descriptors>
                        <descriptor>src/assembly/dokka.xml</descriptor>
                    </descriptors>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.sonatype.plugins</groupId>
                <artifactId>nexus-staging-maven-plugin</artifactId>
                <version>1.6.8</version>
                <extensions>true</extensions>
                <configuration>
                    <serverId>ossrh</serverId>
                    <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                    <autoReleaseAfterClose>false</autoReleaseAfterClose>
                </configuration>
            </plugin>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>${docker-plugin.version}</version>
                <configuration>
                    <images>
                        <image>
                            <alias>db-raccoon-mysql-test</alias>
                            <name>mysql:${mysql.version}</name>
                            <run>
                                <!-- docker:start -->
                                <namingStrategy>alias</namingStrategy>
                                <ports>${test-mysql.port}:3306</ports>
                                <env>
                                    <MYSQL_ROOT_PASSWORD>root</MYSQL_ROOT_PASSWORD>
                                    <MYSQL_DATABASE>${test-mysql.db}</MYSQL_DATABASE>
                                    <MYSQL_USER>${test-mysql.user}</MYSQL_USER>
                                    <MYSQL_PASSWORD>${test-mysql.password}</MYSQL_PASSWORD>
                                </env>
                                <volumes>
                                    <bind>
                                        <!-- set the timezone of host -->
                                        <volume>/etc/localtime:/etc/localtime:ro</volume>
                                    </bind>
                                </volumes>
                            </run>
                        </image>
                        <image>
                            <alias>db-raccoon-postgres-test</alias>
                            <name>postgres:${postgres.version}</name>
                            <run>
                                <!-- docker:start -->
                                <namingStrategy>alias</namingStrategy>
                                <ports>${test-postgres.port}:5432</ports>
                                <wait>
                                    <time>20000</time>
                                </wait>
                                <env>
                                    <POSTGRES_PASSWORD>${test-postgres.password}</POSTGRES_PASSWORD>
                                    <POSTGRES_USER>${test-postgres.user}</POSTGRES_USER>
                                    <POSTGRES_DB>${test-postgres.db}</POSTGRES_DB>
                                </env>
                                <volumes>
                                    <bind>
                                        <!-- set the timezone of host -->
                                        <volume>/etc/localtime:/etc/localtime:ro</volume>
                                    </bind>
                                </volumes>
                            </run>
                        </image>
                    </images>
                    <keepContainer>false</keepContainer>
                </configuration>
                <executions>
                    <execution>
                        <id>prepare integration test</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>cleanup integration test</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.flywaydb</groupId>
                <artifactId>flyway-maven-plugin</artifactId>
                <version>${flyway-plugin.version}</version>
                <dependencies>
                    <dependency>
                        <groupId>com.h2database</groupId>
                        <artifactId>h2</artifactId>
                        <version>${h2.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>${mysql.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.postgresql</groupId>
                        <artifactId>postgresql</artifactId>
                        <version>${postgres-jdbc.version}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>h2-test-migration</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>migrate</goal>
                        </goals>
                        <configuration>
                            <url>jdbc:h2:file:./target/db-raccoon</url>
                            <user>sa</user>
                            <locations>
                                <location>filesystem:${project.basedir}/src/test/resources/db/h2_migration/</location>
                            </locations>
                        </configuration>
                    </execution>
                    <execution>
                        <id>mysql-test-migration</id>
                        <!-- this goal is executed after docker-plugin goal -->
                        <!-- https://stackoverflow.com/a/2451031 -->
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>migrate</goal>
                        </goals>
                        <configuration>
                            <url>jdbc:mysql://127.0.0.1:${test-mysql.port}/${test-mysql.db}</url>
                            <user>${test-mysql.user}</user>
                            <password>${test-mysql.password}</password>
                            <locations>
                                <location>filesystem:${project.basedir}/src/test/resources/db/mysql_migration/
                                </location>
                            </locations>
                        </configuration>
                    </execution>
                    <execution>
                        <id>postgres-test-migration</id>
                        <!-- this goal is executed after docker-plugin goal -->
                        <!-- https://stackoverflow.com/a/2451031 -->
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>migrate</goal>
                        </goals>
                        <configuration>
                            <url>jdbc:postgresql://127.0.0.1:${test-postgres.port}/${test-postgres.db}</url>
                            <user>${test-postgres.user}</user>
                            <password>${test-postgres.password}</password>
                            <locations>
                                <location>filesystem:${project.basedir}/src/test/resources/db/postgres_migration/
                                </location>
                            </locations>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <pluginRepositories>
        <pluginRepository>
            <id>jcenter</id>
            <name>JCenter</name>
            <url>https://jcenter.bintray.com/</url>
        </pluginRepository>
    </pluginRepositories>
</project>
