<?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>3.0.8.Final-redhat-00004</version>
        <relativePath>../debezium-parent/pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>debezium-connector-mongodb</artifactId>
    <name>Debezium Connector for MongoDB</name>
    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>io.debezium</groupId>
            <artifactId>debezium-core</artifactId>
        </dependency>
        <dependency>
            <groupId>io.debezium</groupId>
            <artifactId>debezium-sink</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>connect-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>connect-transforms</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongodb-driver-sync</artifactId>
        </dependency>

        <!-- Testing -->
        <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>
            <type>test-jar</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.debezium</groupId>
            <artifactId>debezium-embedded</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.debezium</groupId>
            <artifactId>debezium-testing-testcontainers</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.platform</groupId>
                    <artifactId>junit-platform-launcher</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.junit.jupiter</groupId>
                    <artifactId>junit-jupiter</artifactId>
                </exclusion>
            </exclusions>
        </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>org.mockito</groupId>
            <artifactId>mockito-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>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>com.google.protobuf</groupId>
                    <artifactId>protobuf-java</artifactId>
                </exclusion>
            </exclusions>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <properties>
        <!-- 
        Set this property to 'true' in a profile to skip the integration tests and not even run the Docker containers.
        -->
        <docker.skip>false</docker.skip>
        <docker.exposeContainerInfo>docker.container</docker.exposeContainerInfo>
        <!-- Apicurio container properties -->
        <apicurio.port>8080</apicurio.port>
        <apicurio.init.timeout>60000</apicurio.init.timeout> <!-- 60 seconds -->
        <!-- Mongo configuration -->
        <!-- See MongoDbPlatform enum for possible options -->
        <mongodb.platform>mongodb_docker</mongodb.platform>
        <!-- Mongo test containers -->
        <!-- port range used to allocate ports -->
        <mongodb.docker.desktop.ports>27017:27117</mongodb.docker.desktop.ports>
        <mongodb.replica.size>1</mongodb.replica.size>
        <mongodb.shard.size>2</mongodb.shard.size>
        <mongodb.shard.replica.size>${mongodb.replica.size}</mongodb.shard.replica.size>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <configuration>
                    <watchInterval>500</watchInterval>
                    <logDate>default</logDate>
                    <verbose>true</verbose>
                    <!--autoPull>always</autoPull-->
                    <images>
                        <image>
                            <name>quay.io/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 -->
                        <version.mongo.server>${version.mongo.server}</version.mongo.server>
                        <mongodb.docker.desktop.ports>${mongodb.docker.desktop.ports}</mongodb.docker.desktop.ports>
                        <mongodb.replica.size>${mongodb.replica.size}</mongodb.replica.size>
                        <mongodb.shard.size>${mongodb.shard.size}</mongodb.shard.size>
                        <mongodb.shard.replica.size>${mongodb.shard.replica.size}</mongodb.shard.replica.size>
                        <mongodb.platform>${mongodb.platform}</mongodb.platform>
                        <mongodb.connection.string>${mongodb.connection.string}</mongodb.connection.string>
                        <skipLongRunningTests>${skipLongRunningTests}</skipLongRunningTests>
                    </systemPropertyVariables>
                    <runOrder>${runOrder}</runOrder>
                    <argLine>--add-opens java.base/java.net=ALL-UNNAMED</argLine>
                </configuration>
            </plugin>
            <plugin>
                <groupId>io.debezium</groupId>
                <artifactId>debezium-schema-generator</artifactId>
                <version>${project.version}</version>
                <executions>
                    <execution>
                        <id>generate-connector-metadata</id>
                        <goals>
                            <goal>generate-api-spec</goal>
                        </goals>
                        <phase>prepare-package</phase>
                        <configuration>
                            <outputDirectory>${project.build.outputDirectory}/META-INF/resources/</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </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>document-db</id>
            <activation>
            </activation>
            <properties>
                <mongodb.platform>document_db</mongodb.platform>
            </properties>
        </profile>
        <profile>
            <id>assembly</id>
            <activation>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <version>${version.assembly.plugin}</version>
                        <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>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>${version.failsafe.plugin}</version>
                        <configuration>
                            <systemPropertyVariables>
                                <isAssemblyProfileActive>true</isAssemblyProfileActive>
                            </systemPropertyVariables>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>quick</id>
            <activation>
                <property>
                    <name>quick</name>
                </property>
            </activation>
            <properties>
                <skipITs>true</skipITs>
                <docker.skip>true</docker.skip>
            </properties>
        </profile>
        <!--  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              Do not perform any Docker-related functionality
              To use, specify "-DskipITs" on the Maven command line.
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
        <profile>
            <id>skip-integration-tests</id>
            <activation>
                <property>
                    <name>skipITs</name>
                </property>
            </activation>
            <properties>
                <docker.skip>true</docker.skip>
            </properties>
        </profile>
        <profile>
            <id>apicurio</id>
            <activation>
                <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>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
            <properties>
                <docker.filter>quay.io/apicurio/apicurio-registry-mem:${version.apicurio}</docker.filter>
            </properties>
        </profile>
    </profiles>
</project>
