<?xml version="1.0" encoding="UTF-8"?>
<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>org.mule.services</groupId>
        <artifactId>mule-core-services-parent</artifactId>
        <version>1.11.2</version>
        <relativePath />
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <name>HTTP Service Implementation</name>
    <description>Grizzly based implementation of the HTTP Service</description>

    <artifactId>mule-service-http</artifactId>
    <packaging>mule-service</packaging>
    <version>1.13.2</version>

    <properties>
        <!-- Add visibility required by the tests exclusively -->
        <surefire.args>
            -XX:+IgnoreUnrecognizedVMOptions
            --add-exports=org.mule.service.http/org.mule.service.http.impl.service=ALL-UNNAMED
            --add-exports=org.mule.service.http/org.mule.service.http.impl.functional=ALL-UNNAMED
            --add-exports=org.mule.service.http/org.mule.service.http.impl.functional.client=ALL-UNNAMED
            --add-exports=org.mule.runtime.core/org.mule.runtime.core.internal.config.builders=ALL-UNNAMED
            --add-exports=org.mule.runtime.core/org.mule.runtime.core.internal.context=ALL-UNNAMED
            --add-exports=org.mule.runtime.core/org.mule.runtime.core.internal.registry=ALL-UNNAMED
            --add-exports=org.mule.runtime.core/org.mule.runtime.core.internal.serialization=ALL-UNNAMED
            --add-exports=org.mule.runtime.core/org.mule.runtime.core.privileged.registry=ALL-UNNAMED
              --add-opens=org.eclipse.angus.mail/org.eclipse.angus.mail.util=ALL-UNNAMED
            --add-exports=org.mule.service.http.netty/org.mule.service.http.netty.impl.service=ALL-UNNAMED
            --add-exports=org.mule.service.http.netty/org.mule.service.http.netty.impl.message.content=ALL-UNNAMED
            --add-exports=org.mule.service.http/org.mule.service.http.impl.functional.server=ALL-UNNAMED
            --add-exports=org.mule.service.http.netty/org.mule.service.http.netty.impl.server=ALL-UNNAMED
              --add-reads=org.mule.service.http=org.bouncycastle.provider
            ${surefire.test.unit.open.args}
        </surefire.args>
        <javaModuleName>org.mule.service.http</javaModuleName>

        <asyncHttpClientVersion>1.14-MULE-030</asyncHttpClientVersion>
        <grizzlyVersion>2.3.36-MULE-028</grizzlyVersion>

        <skipExportTests>false</skipExportTests>
    </properties>

    <scm>
        <connection>scm:git:git://github.com/mulesoft/mule-http-service.git</connection>
        <developerConnection>scm:git:git@github.com:mulesoft/mule-http-service.git</developerConnection>
        <url>https://github.com/mulesoft/mule-http-service</url>
    </scm>

    <build>
        <plugins>
            <plugin>
                <groupId>org.mule.runtime.plugins</groupId>
                <artifactId>mule-service-maven-plugin</artifactId>
                <extensions>true</extensions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-test-jar</id>
                        <configuration>
                            <includes>
                                <include>org/mule/service/http/*</include>
                                <include>org/mule/service/http/impl/functional/**</include>
                                <include>org/mule/service/http/impl/*</include>
                                <include>tls/**</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.mule.runtime</groupId>
            <artifactId>mule-http-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.runtime</groupId>
            <artifactId>mule-core</artifactId>
            <version>${mule.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.runtime</groupId>
            <artifactId>mule-module-tls</artifactId>
            <version>${mule.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.glassfish.grizzly</groupId>
            <artifactId>grizzly-http-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mule.glassfish.grizzly</groupId>
            <artifactId>grizzly-http-servlet</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mule.glassfish.grizzly</groupId>
            <artifactId>connection-pool</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mule.glassfish.grizzly</groupId>
            <artifactId>grizzly-websockets</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mule.glassfish.grizzly</groupId>
            <artifactId>grizzly-http-client</artifactId>
        </dependency>

        <dependency>
            <groupId>org.mule.services</groupId>
            <artifactId>mule-netty-http-service</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-text</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.ben-manes.caffeine</groupId>
            <artifactId>caffeine</artifactId>
        </dependency>

        <dependency>
            <groupId>org.mule.services</groupId>
            <artifactId>mule-netty-http-service</artifactId>
            <type>test-jar</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.tests</groupId>
            <artifactId>mule-tests-unit</artifactId>
            <version>${mule.version}</version> 
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-slf4j-impl</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-slf4j2-impl</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.mule.services</groupId>
            <artifactId>mule-service-weave</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents.client5</groupId>
            <artifactId>httpclient5-fluent</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents.client5</groupId>
            <artifactId>httpclient5</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.github.peterwippermann.junit4</groupId>
            <artifactId>parameterized-suite</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcpkix-jdk18on</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bctls-jdk18on</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.openjdk.jmh</groupId>
            <artifactId>jmh-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.openjdk.jmh</groupId>
            <artifactId>jmh-generator-annprocess</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.wiremock</groupId>
            <artifactId>wiremock</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.mule</groupId>
                <artifactId>mule-javaee-runtime-bom</artifactId>
                <version>${muleBomVersion}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.mule.glassfish.grizzly</groupId>
                <artifactId>grizzly-http-server</artifactId>
                <version>${grizzlyVersion}</version>
            </dependency>
            <dependency>
                <groupId>org.mule.glassfish.grizzly</groupId>
                <artifactId>grizzly-http-servlet</artifactId>
                <version>${grizzlyVersion}</version>
            </dependency>
            <dependency>
                <groupId>org.mule.glassfish.grizzly</groupId>
                <artifactId>connection-pool</artifactId>
                <version>${grizzlyVersion}</version>
            </dependency>
            <dependency>
                <groupId>org.mule.glassfish.grizzly</groupId>
                <artifactId>grizzly-websockets</artifactId>
                <version>${grizzlyVersion}</version>
            </dependency>
            <dependency>
                <groupId>org.mule.glassfish.grizzly</groupId>
                <artifactId>grizzly-http-client</artifactId>
                <version>${asyncHttpClientVersion}</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-api</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <distributionManagement>
        <downloadUrl>http://www.mulesoft.org/display/MULE/Download</downloadUrl>
        <repository>
            <id>mule-releases</id>
            <name>Mule Release Repository</name>
            <url>https://repository-master.mulesoft.org/nexus/content/repositories/releases</url>
        </repository>
        <snapshotRepository>
            <id>mule-snapshots</id>
            <name>Mule Snapshot Repository</name>
            <url>https://repository-master.mulesoft.org/nexus/content/repositories/snapshots</url>
            <uniqueVersion>false</uniqueVersion>
        </snapshotRepository>
    </distributionManagement>

    <repositories>
        <repository>
            <id>mule</id>
            <name>Mule Repository</name>
            <url>https://repository.mulesoft.org/nexus/content/repositories/public/</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>mule-plugin</id>
            <name>Mule Repository</name>
            <url>https://repository.mulesoft.org/nexus/content/repositories/public/</url>
        </pluginRepository>
    </pluginRepositories>

    <profiles>
        <profile>
            <id>micro-benchmark</id>
            <activation>
                <property>
                    <name>micro.benchmark</name>
                </property>
            </activation>

            <dependencies>
                <dependency>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-slf4j-impl</artifactId>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-slf4j2-impl</artifactId>
                    <scope>test</scope>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <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>docker.server.port</portName>
                                    </portNames>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>default-testCompile</id>
                                <configuration>
                                    <proc>full</proc>
                                    <annotationProcessorPaths>
                                        <path>
                                            <groupId>org.openjdk.jmh</groupId>
                                            <artifactId>jmh-generator-annprocess</artifactId>
                                        </path>
                                    </annotationProcessorPaths>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <systemPropertyVariables>
                                <docker.server.port>${docker.server.port}</docker.server.port>
                            </systemPropertyVariables>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <version>0.40.2</version>
                        <configuration>
                            <images>
                                <image>
                                    <name>nginx:latest</name>
                                    <run>
                                        <ports>
                                            <port>${docker.server.port}:80</port>
                                        </ports>
                                        <volumes>
                                            <bind>
                                                <volume>${project.basedir}/src/test/resources/nginx/nginx.conf:/etc/nginx/nginx.conf:ro</volume>
                                            </bind>
                                        </volumes>
                                        <wait>
                                            <http>
                                                <url>http://localhost:${docker.server.port}/</url>
                                                <method>GET</method>
                                            </http>
                                            <time>30000</time>
                                        </wait>
                                    </run>
                                </image>
                            </images>
                        </configuration>
                        <executions>
                            <execution>
                                <id>start-http-server</id>
                                <phase>process-test-classes</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>stop-http-server</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>run-benchmark</id>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <classpathScope>test</classpathScope>
                            <executable>java</executable>
                            <workingDirectory>${basedir}/target</workingDirectory>
                            <arguments>
                                <argument>-Ddocker.server.port=${docker.server.port}</argument>
                                <argument>-Dio.netty.leakDetection.level=disabled</argument>
                                <argument>-Dio.netty.allocator.type=unpooled</argument>
                                <argument>-Dio.netty.noPreferDirect=true</argument>
                                <argument>-Dmule.http.client.selectors.count=4</argument>
                                <argument>-Dorg.mule.service.http.impl.service.client.GrizzlyHttpClient.DEFAULT_SELECTOR_THREAD_COUNT=4</argument>

                                <argument>-classpath</argument>
                                <classpath/>
                                <mainClass>org.openjdk.jmh.Main</mainClass>

                                <argument>-pmethod=GET</argument>
                                <argument>-pbodySize=1024</argument>
                            </arguments>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>no-micro-benchmark</id>
            <activation>
                <property>
                    <name>!micro.benchmark</name>
                </property>
            </activation>

            <dependencies>
                <dependency>
                    <groupId>com.github.valfirst</groupId>
                    <artifactId>slf4j-test</artifactId>
                    <scope>test</scope>
                </dependency>
            </dependencies>
        </profile>
    </profiles>
</project>
