<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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.mulesoft.connectors</groupId>
    <artifactId>mule4-mqtt3-connector</artifactId>
    <version>1.0.0</version>
    <packaging>mule-extension</packaging>
    <name>MQTT Connector</name>

    <parent>
        <groupId>org.mule.extensions</groupId>
        <artifactId>mule-ee-core-modules-parent</artifactId>
        <version>1.3.0</version>
    </parent>

    <properties>
        <formatterConfigPath>formatter.xml</formatterConfigPath>
        <licenseYear>2021</licenseYear>

        <munit.extensions.maven.plugin.version>1.1.1</munit.extensions.maven.plugin.version>
        <munit.version>2.3.5</munit.version>
        <maven.helper.plugin.version>3.2.0</maven.helper.plugin.version>
        <mavenResources.version>3.2.0</mavenResources.version>

        <ecliple.paho.client.version>1.2.5</ecliple.paho.client.version>
        <commons.lang.version>3.12.0</commons.lang.version>
        <docker.maven.plugin.version>0.37.0</docker.maven.plugin.version>
        <mule.sdk.api.version>0.4.0</mule.sdk.api.version>
        <groovy.version>2.4.16</groovy.version>
        <scripting.module.version>1.1.7</scripting.module.version>
        <file.connector.version>1.3.4</file.connector.version>
        <settings.file>${java.io.tmpdir}/effective-settings.xml</settings.file>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.eclipse.paho</groupId>
            <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
            <version>${ecliple.paho.client.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mule.sdk</groupId>
            <artifactId>mule-sdk-api</artifactId>
            <version>${mule.sdk.api.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>${commons.lang.version}</version>
        </dependency>

        <!--Test dependencies-->
        <dependency>
            <groupId>org.mule.modules</groupId>
            <artifactId>mule-scripting-module</artifactId>
            <classifier>mule-plugin</classifier>
            <version>${scripting.module.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.connectors</groupId>
            <artifactId>mule-file-connector</artifactId>
            <version>${file.connector.version}</version>
            <classifier>mule-plugin</classifier>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>com.mulesoft.munit</groupId>
                <artifactId>munit-extensions-maven-plugin</artifactId>
                <version>${munit.extensions.maven.plugin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <phase>integration-test</phase>
                    </execution>
                </executions>
                <configuration>
                    <argLines>
                        <argLine>
                            -javaagent:${settings.localRepository}/org/jacoco/org.jacoco.agent/${jacoco.version}/org.jacoco.agent-${jacoco.version}-runtime.jar=destfile=${session.executionRootDirectory}/target/jacoco.exec
                        </argLine>
                    </argLines>
                    <sharedLibraries>
                        <sharedLibrary>
                            <groupId>org.eclipse.paho</groupId>
                            <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
                        </sharedLibrary>
                    </sharedLibraries>
                    <runtimeConfiguration>
                        <discoverRuntimes>
                            <product>EE</product>
                            <includeSnapshots>true</includeSnapshots>
                            <minMuleVersion>4.3.0</minMuleVersion>
                        </discoverRuntimes>
                    </runtimeConfiguration>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>com.mulesoft.munit</groupId>
                        <artifactId>munit-runner</artifactId>
                        <version>${munit.version}</version>
                        <classifier>mule-plugin</classifier>
                    </dependency>
                    <dependency>
                        <groupId>com.mulesoft.munit</groupId>
                        <artifactId>munit-tools</artifactId>
                        <version>${munit.version}</version>
                        <classifier>mule-plugin</classifier>
                    </dependency>
                    <dependency>
                        <groupId>org.mule.modules</groupId>
                        <artifactId>mule-connection-test-module</artifactId>
                        <version>1.0.0</version>
                        <classifier>mule-plugin</classifier>
                    </dependency>
                </dependencies>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>${maven.helper.plugin.version}</version>
                <executions>
                    <execution>
                        <id>reserve-network-port</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>reserve-network-port</goal>
                        </goals>
                        <configuration>
                            <portNames>
                                <portName>mosquitto.port</portName>
                                <portName>mosquitto.port1</portName>
                                <portName>mosquitto.ws.port</portName>
                                <portName>mosquitto.ssl.port</portName>
                                <portName>solace.port</portName>
                                <portName>rabbitmq.port</portName>
                                <portName>connection.lost.port</portName>
                                <portName>toxiProxy.api.port</portName>
                            </portNames>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-help-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <phase>process-test-resources</phase>
                        <id>copy-settings</id>
                        <goals>
                            <goal>effective-settings</goal>
                        </goals>
                        <configuration>
                            <output>${settings.file}</output>
                            <showPasswords>true</showPasswords>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-invoker-plugin</artifactId>
                <version>3.2.2</version>
                <configuration>
                    <debug>false</debug>
                    <streamLogs>true</streamLogs>
                    <noLog>true</noLog>
                    <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
                    <properties>
                        <maven.settings.local>${settings.file}</maven.settings.local>
                    </properties>
                    <environmentVariables>
                        <mosquitto.port>${mosquitto.port}</mosquitto.port>
                        <mqtt3-connector-version>${project.version}</mqtt3-connector-version>
                    </environmentVariables>
                </configuration>
                <executions>
                    <execution>
                        <id>tita-test</id>
                        <!--use test phase because that's when maven surefire plugin resolves properties-->
                        <phase>install</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>docker</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <version>${docker.maven.plugin.version}</version>
                        <configuration>
                            <images>
                                <image>
                                    <name>eclipse-mosquitto:2.0.11</name>
                                    <alias>eclipse-mosquitto-1</alias>
                                    <run>
                                        <ports>
                                            <port>mosquitto.port:1883</port>
                                            <port>mosquitto.port1:1884</port>
                                            <port>mosquitto.ws.port:8080</port>
                                            <port>mosquitto.ssl.port:8883</port>
                                        </ports>
                                        <log>
                                            <enabled>true</enabled>
                                        </log>
                                        <volumes>
                                            <bind>
                                                <volume>${basedir}/src/test/resources/tls:/mosquitto/ssl</volume>
                                                <volume>${basedir}/src/test/resources/mosquitto.conf:/mosquitto/config/mosquitto.conf:ro</volume>
                                                <volume>${basedir}/src/test/resources/mosquitto.passwd:/mosquitto/config/mosquitto.passwd</volume>
                                            </bind>
                                        </volumes>
                                    </run>
                                </image>
                                <image>
                                    <name>shopify/toxiproxy</name>
                                    <alias>toxiproxy</alias>
                                    <run>
                                        <ports>
                                            <port>${toxiProxy.api.port}:8474</port>
                                            <port>${connection.lost.port}:${connection.lost.port}</port>
                                        </ports>
                                        <links>
                                            <link>eclipse-mosquitto-1</link>
                                        </links>
                                    </run>
                                </image>
                                <image>
                                    <name>solace/solace-pubsub-standard</name>
                                    <alias>solace</alias>
                                    <run>
                                        <shm-size>2147483648</shm-size>
                                        <env>
                                            <username_admin_globalaccesslevel>admin</username_admin_globalaccesslevel>
                                            <username_admin_password>admin</username_admin_password>
                                        </env>
                                        <ports>
                                            <port>solace.port:1883</port>
                                        </ports>
                                    </run>
                                </image>
                                <image>
                                    <name>rabbitmqtt</name>
                                    <alias>rabbitmqtt</alias>
                                    <build>
                                        <dockerFileDir>${project.basedir}/src/test/resources/docker/rabbitmq</dockerFileDir>
                                    </build>
                                    <run>
                                        <ports>
                                            <port>rabbitmq.port:1883</port>
                                        </ports>
                                        <ulimits>
                                            <ulimit>
                                                <name>nofile</name>
                                                <hard>10240</hard>
                                                <soft>10240</soft>
                                            </ulimit>
                                        </ulimits>
                                        <log>
                                            <enabled>true</enabled>
                                        </log>
                                        <wait>
                                            <log>Server startup complete</log>
                                            <time>500000</time>
                                            <kill>1000</kill>
                                            <shutdown>500</shutdown>
                                        </wait>
                                    </run>
                                </image>
                            </images>
                            <verbose>true</verbose>
                        </configuration>
                        <dependencies>
                            <dependency>
                                <groupId>org.slf4j</groupId>
                                <artifactId>slf4j-api</artifactId>
                                <version>1.7.32</version>
                            </dependency>
                            <dependency>
                                <groupId>org.slf4j</groupId>
                                <artifactId>jcl-over-slf4j</artifactId>
                                <version>1.7.32</version>
                            </dependency>
                        </dependencies>
                        <executions>
                            <execution>
                                <id>start</id>
                                <phase>test-compile</phase>
                                <goals>
                                    <goal>stop</goal>
                                    <goal>remove</goal>
                                    <goal>build</goal>
                                    <goal>start</goal>
                                </goals>
                                <configuration>
                                    <showLogs>true</showLogs>
                                    <logStdout>true</logStdout>
                                </configuration>
                            </execution>
                            <execution>
                                <id>stop</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                    <goal>remove</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>
