<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.mulesoft.mule.runtime.modules</groupId>
        <artifactId>mule-modules</artifactId>
        <version>4.7.2</version>
    </parent>

    <artifactId>mule-module-cluster-ee</artifactId>
    <name>Mule Clustering/HA</name>

    <properties>
        <surefire.args>
            ${surefire.slf4j.module.args}
        </surefire.args>

        <javaModuleName>com.mulesoft.mule.runtime.cluster</javaModuleName>
        <skipExportTests>false</skipExportTests>
        <formatterConfigPath>../../formatter.xml</formatterConfigPath>

        <docker.maven.plugin.version>0.43.2</docker.maven.plugin.version>
        <!--suppress UnresolvedMavenProperty -->
        <docker.skip>${skipTests}</docker.skip>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <configuration>
                    <!-- exclude some files that deal with the license -->
                    <excludes>
                        <exclude>**/ClusterLicenseCheck.java</exclude>
                        <exclude>**/ClusterCoreExtensionTestCase.java</exclude>
                        <exclude>**/muleLicenseKey.lic</exclude>
                        <exclude>**/ClusterCoreExtension.java</exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>reserve-network-port</id>
                        <phase>generate-test-resources</phase>
                        <goals>
                            <goal>reserve-network-port</goal>
                        </goals>
                        <configuration>
                            <portNames>
                                <portName>configuration.mysql.port</portName>
                                <portName>configuration.mssql.port</portName>
                                <portName>configuration.postgres.port</portName>
                            </portNames>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <!-- Module layer is created by the tests-runner, don't need surefire to config the boot layer for the JVM -->
                    <useModulePath>false</useModulePath>

                    <forkCount>1</forkCount>
                    <reuseForks>false</reuseForks>
                    <workingDirectory>${project.build.directory}</workingDirectory>
                    <systemPropertyVariables>
                        <configuredPortMySQL>${configuration.mysql.port}</configuredPortMySQL>
                        <configuredPortMicrosoftSQLServer>${configuration.mssql.port}</configuredPortMicrosoftSQLServer>
                        <configuredPortPostgreSQL>${configuration.postgres.port}</configuredPortPostgreSQL>
                        <buildDirectory>${project.build.directory}</buildDirectory>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>${docker.maven.plugin.version}</version>
                <configuration>
                    <images>
                        <image>
                            <name>mysql:8.1.0</name>
                            <run>
                                <env>
                                    <MYSQL_ROOT_PASSWORD>password</MYSQL_ROOT_PASSWORD>
                                    <MYSQL_DATABASE>xe</MYSQL_DATABASE>
                                </env>
                                <ports>
                                    <port>${configuration.mysql.port}:3306</port>
                                </ports>
                                <ulimits>
                                    <ulimit>
                                        <name>nofile</name>
                                        <hard>10240</hard>
                                        <soft>10240</soft>
                                    </ulimit>
                                </ulimits>
                                <log>
                                    <enabled>true</enabled>
                                </log>
                                <wait>
                                    <log>mysqld: ready for connections.</log>
                                    <time>500000</time>
                                </wait>
                            </run>
                        </image>
                        <image>
                            <name>mcr.microsoft.com/azure-sql-edge:latest</name>
                            <run>
                                <env>
                                    <MSSQL_SA_PASSWORD>P@ssw0rd</MSSQL_SA_PASSWORD>
                                    <ACCEPT_EULA>1</ACCEPT_EULA>
                                </env>
                                <ports>
                                    <port>${configuration.mssql.port}:1433</port>
                                </ports>
                                <ulimits>
                                    <ulimit>
                                        <name>nofile</name>
                                        <hard>10240</hard>
                                        <soft>10240</soft>
                                    </ulimit>
                                </ulimits>
                                <log>
                                    <enabled>true</enabled>
                                </log>
                                <wait>
                                    <log>Service Broker manager has started.</log>
                                    <time>500000</time>
                                </wait>
                            </run>
                        </image>
                        <image>
                            <name>postgres:15.3</name>
                            <run>
                                <env>
                                    <POSTGRES_PASSWORD>password</POSTGRES_PASSWORD>
                                </env>
                                <ports>
                                    <port>${configuration.postgres.port}:5432</port>
                                </ports>
                                <ulimits>
                                    <ulimit>
                                        <name>nofile</name>
                                        <hard>10240</hard>
                                        <soft>10240</soft>
                                    </ulimit>
                                </ulimits>
                                <log>
                                    <enabled>true</enabled>
                                </log>
                                <wait>
                                    <log>(?s)database system is ready to accept connections.*database system is ready to accept connections</log>
                                    <time>500000</time>
                                </wait>
                            </run>
                        </image>
                    </images>
                    <verbose>true</verbose>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-api</artifactId>
                        <version>1.7.24</version>
                    </dependency>
                    <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>jcl-over-slf4j</artifactId>
                        <version>1.7.24</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>start</id>
                        <phase>process-test-classes</phase>
                        <goals>
                            <goal>build</goal>
                            <goal>start</goal>
                        </goals>
                        <configuration>
                            <showLogs>true</showLogs>
                            <logStdout>true</logStdout>
                        </configuration>
                    </execution>
                    <execution>
                        <id>stop</id>
                        <phase>test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.mule.runtime</groupId>
            <artifactId>mule-core</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>com.mulesoft.mule.runtime</groupId>
            <artifactId>mule-core-ee</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>com.hazelcast</groupId>
            <artifactId>hazelcast</artifactId>
        </dependency>
        <dependency>
            <groupId>com.mchange</groupId>
            <artifactId>c3p0</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mule.runtime</groupId>
            <artifactId>mule-module-spring-config</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mule.runtime</groupId>
            <artifactId>mule-module-deployment</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>commons-dbutils</groupId>
            <artifactId>commons-dbutils</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mule</groupId>
            <artifactId>mule-encryption</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>fluent-hc</artifactId>
        </dependency>
        
        <!-- For unit tests -->
        <dependency>
            <groupId>com.mulesoft.mule.tests</groupId>
            <artifactId>mule-tests-allure</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.tests</groupId>
            <artifactId>mule-tests-runner</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.tests</groupId>
            <artifactId>mule-tests-functional</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.tests</groupId>
            <artifactId>mule-tests-unit</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.tests</groupId>
            <artifactId>mule-tests-infrastructure</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.mulesoft.mule.runtime.modules</groupId>
            <artifactId>mule-module-bti-ee</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.mulesoft.mule.runtime.modules</groupId>
            <artifactId>mule-module-kryo-serializer-ee</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.hazelcast</groupId>
            <artifactId>hazelcast</artifactId>
            <classifier>tests</classifier>
            <scope>test</scope>
        </dependency>
        <!-- ActiveMQ Dependencies-->
        <dependency>
            <groupId>org.mule.tests</groupId>
            <artifactId>mule-activemq-broker</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derby</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.connectors</groupId>
            <artifactId>mule-vm-connector</artifactId>
            <classifier>mule-plugin</classifier>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.connectors</groupId>
            <artifactId>mule-objectstore-connector</artifactId>
            <classifier>mule-plugin</classifier>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.modules</groupId>
            <artifactId>mule-aggregators-module</artifactId>
            <classifier>mule-plugin</classifier>
            <scope>test</scope>
        </dependency>

        <!--TODO: MULE-10837-->
        <dependency>
            <groupId>org.mule.runtime</groupId>
            <artifactId>mule-module-service</artifactId>
            <version>${project.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.services</groupId>
            <artifactId>mule-service-scheduler</artifactId>
            <classifier>mule-service</classifier>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.runtime</groupId>
            <artifactId>mule-dwb-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.mulesoft.services</groupId>
            <artifactId>mule-service-weave-ee</artifactId>
            <classifier>mule-service</classifier>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.tests.plugin</groupId>
            <artifactId>mule-tests-component-plugin</artifactId>
            <version>${project.version}</version>
            <classifier>mule-plugin</classifier>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.tests</groupId>
            <artifactId>test-components</artifactId>
            <version>${muleTestComponentsVersion}</version>
            <classifier>mule-plugin</classifier>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <id>no-large-tests</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.22.2</version>
                        <configuration>
                            <skipTests>true</skipTests>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>docker-windows</id>
            <activation>
                <os>
                    <family>windows</family>
                </os>
            </activation>
            <properties>
                <docker.skip>true</docker.skip>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <systemPropertyVariables>
                                <skipTestsWhichRequireDocker>true</skipTestsWhichRequireDocker>
                            </systemPropertyVariables>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>
