<?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>1.5.2.Final</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>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>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.easytesting</groupId>
            <artifactId>fest-assert</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.confluent</groupId>
            <artifactId>kafka-connect-avro-converter</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.awaitility</groupId>
            <artifactId>awaitility</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <properties>
        <!-- By default we need to run these 5 containers, although the two init containers exit quickly -->
        <docker.image>mongo1,mongo-init</docker.image>

        <!-- The command line args passed to each mongod service -->
        <mongo.data.replicaset.name>rs0</mongo.data.replicaset.name>
        <mongo.cfg.replicaset.name>cfg</mongo.cfg.replicaset.name>
        <mongo.data.runOptions>--replSet ${mongo.data.replicaset.name} --oplogSize=2 --enableMajorityReadConcern</mongo.data.runOptions>
        <mongo.cfg.runOptions>--configsvr --replSet ${mongo.cfg.replicaset.name} --oplogSize=2 --enableMajorityReadConcern</mongo.cfg.runOptions>
        <mongo.router.runOptions>mongos --configdb ${mongo.cfg.replicaset.name}/config:27019</mongo.router.runOptions>
        <!-- 
        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>
    </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>
                  <!-- A container for the data server replica set -->
                  <image>
                    <name>mongo:${version.mongo.server}</name>
                    <alias>mongo1</alias>
                    <run>
                      <namingStrategy>alias</namingStrategy>
                      <cmd>${mongo.data.runOptions}</cmd>
                      <ports>
                        <!-- We won't use it thru this port, but we don't want to take 27017 on docker host -->
                        <port>27017:27017</port> 
                      </ports>
                      <log>
                        <prefix>mongo1</prefix>
                        <enabled>true</enabled>
                        <color>yellow</color>
                      </log>
                      <wait>
                        <log>.*waiting for connections on port 27017</log> <!-- internal port, multiline matching -->
                        <time>30000</time> <!-- 30 seconds max -->
                      </wait>
                    </run>
                  </image>
                  <!-- A container that initiates the data replica set and adds it as shard to router -->
                  <image>
                    <name>debezium/mongo-initiator:${version.mongo.server}</name>
                    <run>
                      <namingStrategy>none</namingStrategy>
                      <env>
                        <VERBOSE>true</VERBOSE>
                        <REPLICASET>${mongo.data.replicaset.name}</REPLICASET>
                      </env>
                      <links>
                        <link>mongo1:mongo1</link>
                      </links>
                      <log>
                        <prefix>mongo-init</prefix>
                        <enabled>true</enabled>
                        <color>green</color>
                      </log>
                      <wait>
                        <exit>0</exit>
                        <time>30000</time> <!-- 30 seconds max -->
                      </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 -->
                        <connector.mongodb.hosts>${mongo.data.replicaset.name}/${docker.host.address}:27017</connector.mongodb.hosts>
                        <connector.mongodb.members.auto.discover>false</connector.mongodb.members.auto.discover>
                        <connector.mongodb.name>mongo1</connector.mongodb.name>
                        <skipLongRunningTests>${skipLongRunningTests}</skipLongRunningTests>
                    </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>
                        <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>
                </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>
    </profiles>
</project>
