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

    <parent>
        <groupId>io.debezium</groupId>
        <artifactId>debezium-parent</artifactId>
        <version>2.5.2.Final</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>debezium-connector-db2</artifactId>
    <version>2.5.2.Final</version>
    <name>Debezium Connector for IBM DB2 Server</name>
    <packaging>jar</packaging>

    <scm>
        <connection>scm:git:git@github.com:debezium/debezium-connector-db2.git</connection>
        <developerConnection>scm:git:git@github.com:debezium/debezium-connector-db2.git</developerConnection>
        <url>https://github.com/debezium/debezium-connector-db2</url>
      <tag>v2.5.2.Final</tag>
    </scm>

    <properties>
        <!-- Debezium parent -->
        <version.debezium>${project.version}</version.debezium>

        <!--
          Specify the properties that will be used for setting up the integration tests' Docker container.
          Note that the `dockerhost.ip` property is computed from the IP address of DOCKER_HOST, which will
          work on all platforms. We'll set some of these as system properties during integration testing.
        -->
        <db2.port>50000</db2.port>
        <db2.user>db2inst1</db2.user>
        <db2.password>admin</db2.password>
        <db2.dbname>testdb</db2.dbname>
        <docker.dbs>debezium/db2-cdc-it</docker.dbs>
        <docker.filter>${docker.dbs}</docker.filter>
        <docker.skip>false</docker.skip>
        <docker.showLogs>true</docker.showLogs>

        <!-- Apicurion container properties -->
        <apicurio.port>8080</apicurio.port>
        <apicurio.init.timeout>60000</apicurio.init.timeout> <!-- 60 seconds -->

        <!-- Flaky Test Support -->
        <fail.flaky.tests>true</fail.flaky.tests>

        <!-- Order in which Maven Failsafe plugin runs integration tests, the default is in alphabetical order -->
        <runOrder>alphabetical</runOrder>
    </properties>

    <repositories>
        <repository>
            <id>oss</id>
            <name>OSS Sonatype Nexus</name>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
            </snapshots>
        </repository>
    </repositories>

    <!-- Managing versions here to ensure the right ones are applied during releases -->
    <dependencyManagement>
        <dependencies>
            <!-- Debezium artifacts -->
            <dependency>
                <groupId>io.debezium</groupId>
                <artifactId>debezium-core</artifactId>
                <version>${version.debezium}</version>
            </dependency>
            <dependency>
                <groupId>io.debezium</groupId>
                <artifactId>debezium-embedded</artifactId>
                <version>${version.debezium}</version>
            </dependency>
            <dependency>
                <groupId>io.debezium</groupId>
                <artifactId>debezium-storage-kafka</artifactId>
                <version>${version.debezium}</version>
            </dependency>
            <dependency>
                <groupId>io.debezium</groupId>
                <artifactId>debezium-storage-file</artifactId>
                <version>${version.debezium}</version>
            </dependency>

            <!-- Building -->
            <dependency>
                <groupId>io.debezium</groupId>
                <artifactId>debezium-ide-configs</artifactId>
                <version>${version.debezium}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>io.debezium</groupId>
                <artifactId>debezium-checkstyle</artifactId>
                <version>${version.debezium}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>io.debezium</groupId>
                <artifactId>debezium-assembly-descriptors</artifactId>
                <version>${version.debezium}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>io.debezium</groupId>
                <artifactId>debezium-revapi</artifactId>
                <version>${version.debezium}</version>
                <scope>provided</scope>
            </dependency>

            <!-- Testing -->
            <dependency>
                <groupId>io.debezium</groupId>
                <artifactId>debezium-core</artifactId>
                <version>${version.debezium}</version>
                <type>test-jar</type>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>io.debezium</groupId>
                <artifactId>debezium-embedded</artifactId>
                <version>${version.debezium}</version>
                <type>test-jar</type>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>io.debezium</groupId>
            <artifactId>debezium-core</artifactId>
        </dependency>
        <dependency>
            <groupId>io.debezium</groupId>
            <artifactId>debezium-storage-kafka</artifactId>
        </dependency>
        <dependency>
            <groupId>io.debezium</groupId>
            <artifactId>debezium-storage-file</artifactId>
        </dependency>
        <!-- Db2 JDBC driver -->
        <!-- https://mvnrepository.com/artifact/com.ibm.db2/jcc -->
        <dependency>
            <groupId>com.ibm.db2</groupId>
            <artifactId>jcc</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>connect-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Building -->
        <dependency>
            <groupId>io.debezium</groupId>
            <artifactId>debezium-ide-configs</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>io.debezium</groupId>
            <artifactId>debezium-checkstyle</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>io.debezium</groupId>
            <artifactId>debezium-assembly-descriptors</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>io.debezium</groupId>
            <artifactId>debezium-revapi</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Testing -->
        <dependency>
            <groupId>io.debezium</groupId>
            <artifactId>debezium-embedded</artifactId>
            <type>test-jar</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.debezium</groupId>
            <artifactId>debezium-core</artifactId>
            <type>test-jar</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.debezium</groupId>
            <artifactId>debezium-embedded</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.confluent</groupId>
            <artifactId>kafka-connect-avro-converter</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.apicurio</groupId>
            <artifactId>apicurio-registry-utils-converter</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.awaitility</groupId>
            <artifactId>awaitility</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <configuration>
                    <watchInterval>500</watchInterval>
                    <logDate>default</logDate>
                    <verbose>true</verbose>
                    <images>
                        <image>
                            <!-- A Docker image using the SQL Server -->
                            <name>${docker.dbs}</name>
                            <build>
                               <dockerFileDir>${project.basedir}/src/test/docker/db2-cdc-docker</dockerFileDir>
                            </build>
                            <run>
                                <namingStrategy>none</namingStrategy>
                                <privileged>true</privileged>
                                <env>
                                    <LICENSE>accept</LICENSE>
                                    <DB2INST1_PASSWORD>${db2.password}</DB2INST1_PASSWORD>
                                    <DBNAME>${db2.dbname}</DBNAME>
                                </env>
                                <ports>
                                    <port>${db2.port}:50000</port>
                                </ports>
                                <log>
                                    <prefix>DB2 &gt;&gt;&gt;</prefix>
                                    <enabled>true</enabled>
                                    <color>yellow</color>
                                </log>
                                <wait>
                                    <time>900000</time> <!-- 900 seconds max -->
                                    <log>STOP    : DATABASE: TESTDB   : DEACTIVATED: NO</log>
                                </wait>
                            </run>
                        </image>
                        <image>
                            <name>apicurio/apicurio-registry-mem:${version.apicurio}</name>
                            <run>
                                <namingStrategy>none</namingStrategy>
                                <ports>
                                    <port>${apicurio.port}:8080</port>
                                </ports>
                                <log>
                                    <prefix>apicurio</prefix>
                                    <enabled>true</enabled>
                                    <color>blue</color>
                                </log>
                                <wait>
                                    <log>.*apicurio-registry-app.*started in.*</log>
                                    <time>${apicurio.init.timeout}</time>
                                </wait>
                            </run>
                        </image>
                    </images>
                </configuration>
                <!--
                Connect this plugin to the maven lifecycle around the integration-test phase:
                start the container in pre-integration-test and stop it in post-integration-test.
                -->
                <executions>
                    <execution>
                        <id>start</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>build</goal>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- 
            Unlike surefire, the failsafe plugin ensures 'post-integration-test' phase always runs, even
            when there are failed integration tests. We rely upon this to always shut down the Docker container
            after the integration tests (defined as '*IT.java') are run.
            -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>verify</id>
                        <goals>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <skipTests>${skipITs}</skipTests>
                    <enableAssertions>true</enableAssertions>
                    <systemPropertyVariables>
                        <!-- Make these available to the tests via system properties -->
                        <database.hostname>${docker.host.address}</database.hostname>
                        <database.dbname>${db2.dbname}</database.dbname>
                        <database.port>${db2.port}</database.port>
                        <database.user>${db2.user}</database.user>
                        <database.password>${db2.password}</database.password>
                        <skipLongRunningTests>${skipLongRunningTests}</skipLongRunningTests>
                        <failFlakyTests>${fail.flaky.tests}</failFlakyTests>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
        </plugins>
        <resources>
            <!-- Apply the properties set in the POM to the resource files -->
            <resource>
                <filtering>true</filtering>
                <directory>src/main/resources</directory>
                <includes>
                    <include>*</include>
                    <include>**/*</include>
                </includes>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>*</include>
                    <include>**/*</include>
                </includes>
            </testResource>
        </testResources>
    </build>
    <!--
    Define several useful profiles
    -->
    <profiles>
        <profile>
            <id>assembly</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <dependencies>
                            <dependency>
                                <groupId>io.debezium</groupId>
                                <artifactId>debezium-assembly-descriptors</artifactId>
                                <version>${project.version}</version>
                            </dependency>
                        </dependencies>
                        <executions>
                            <execution>
                                <id>default</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                                <configuration>
                                    <finalName>${project.artifactId}-${project.version}</finalName>
                                    <attach>true</attach>  <!-- we want attach & deploy these to Maven -->
                                    <descriptorRefs>
                                        <descriptorRef>${assembly.descriptor}</descriptorRef>
                                    </descriptorRefs>
                                    <tarLongFileMode>posix</tarLongFileMode>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <!--  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              Do not perform any Docker-related functionality
              To use, specify "-DskipITs" on the Maven command line.
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
        <profile>
            <id>skip-integration-tests</id>
            <activation>
                <activeByDefault>false</activeByDefault>
                <property>
                    <name>skipITs</name>
                </property>
            </activation>
            <properties>
                <docker.skip>true</docker.skip>
            </properties>
        </profile>
        <profile>
            <id>quick</id>
            <activation>
                <activeByDefault>false</activeByDefault>
                <property>
                    <name>quick</name>
                </property>
            </activation>
            <properties>
                <skipITs>true</skipITs>
                <docker.skip>true</docker.skip>
            </properties>
        </profile>
        <profile>
            <id>apicurio</id>
            <activation>
                <activeByDefault>false</activeByDefault>
                <property>
                    <name>apicurio</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <configuration>
                            <systemPropertyVariables>
                                <use.apicurio>true</use.apicurio>
                            </systemPropertyVariables>
                            <runOrder>${runOrder}</runOrder>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
            <properties>
                <docker.filter>${docker.dbs},apicurio/apicurio-registry-mem:${version.apicurio}</docker.filter>
            </properties>
        </profile>
    </profiles>
</project>
