<?xml version="1.0" encoding="UTF-8"?>
<!--
 *
 * acme4j - ACME Java client
 *
 * Copyright (C) 2017 Richard "Shred" Körber
 *   http://acme4j.shredzone.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
-->
<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>org.shredzone.acme4j</groupId>
        <artifactId>acme4j</artifactId>
        <version>2.2</version>
    </parent>

    <artifactId>acme4j-it</artifactId>

    <name>acme4j IT</name>
    <description>acme4j Integration Tests</description>

    <properties>
        <!-- alpn-boot version must match the java version used in bammbamm -->
        <!-- see: https://www.eclipse.org/jetty/documentation/9.4.x/alpn-chapter.html#alpn-versions -->
        <alpn-java.version>8u162</alpn-java.version>
        <alpn-boot.version>8.1.12.v20180117</alpn-boot.version>

        <skipITs>true</skipITs>
        <sonar.coverage.exclusions>src/main/java/org/shredzone/acme4j/**</sonar.coverage.exclusions>
    </properties>

    <profiles>
        <profile>
            <!-- Profile with integration tests. Requires docker! -->
            <!-- mvn -P ci verify -->
            <id>ci</id>
            <properties>
                <skipITs>false</skipITs>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <configuration>
                            <excludes>
                                <exclude>org/shredzone/acme4j/it/boulder/**</exclude>
                            </excludes>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <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>
                </plugins>
            </build>
        </profile>
        <profile>
            <!-- Profile for testing against a local Boulder server. -->
            <!-- mvn -P boulder verify -->
            <id>boulder</id>
            <properties>
                <skipITs>false</skipITs>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <configuration>
                            <excludes>
                                <exclude>org/shredzone/acme4j/it/pebble/**</exclude>
                            </excludes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <build>
        <plugins>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.21.0</version>

                <configuration>
                    <logStdout>true</logStdout>
                    <verbose>true</verbose>
                    <removeAll>true</removeAll>

                    <images>
                        <image>
                            <alias>pebble</alias>
                            <name>acme4j/pebble:${project.version}</name>

                            <build>
                                <from>golang:1.10</from>
                                <optimise>true</optimise>
                                <runCmds>
                                    <run>go get -u -v -d gopkg.in/square/go-jose.v2</run>
                                    <run>go get -u -v -d github.com/jmhodges/clock</run>
                                    <run>go get -u -v -d github.com/letsencrypt/pebble || true</run>
                                    <run>go test github.com/letsencrypt/pebble/...</run>
                                    <run>go install github.com/letsencrypt/pebble/...</run>
                                </runCmds>
                                <ports>
                                    <port>14000</port>
                                </ports>
                                <cmd>
                                    <shell>
                                        pebble -strict -dnsserver bammbamm:53 -config /etc/pebble/pebble-config.json
                                    </shell>
                                </cmd>
                                <assembly>
                                    <mode>dir</mode>
                                    <targetDir>/etc/pebble</targetDir>
                                    <inline>
                                        <fileSet>
                                            <directory>src/test/pebble</directory>
                                            <outputDirectory>.</outputDirectory>
                                        </fileSet>
                                    </inline>
                                </assembly>
                            </build>

                            <run>
                                <namingStrategy>alias</namingStrategy>
                                <ports>
                                    <port>14000:14000</port>
                                </ports>
                                <links>
                                    <link>bammbamm</link>
                                </links>
                                <wait>
                                    <log>Pebble running</log>
                                </wait>
                                <!-- Comment out to perform tests with validation delays. -->
                                <env>
                                    <PEBBLE_VA_NOSLEEP>1</PEBBLE_VA_NOSLEEP>
                                </env>
                            </run>
                        </image>
                        <image>
                            <alias>bammbamm</alias>
                            <name>acme4j/bammbamm:${project.version}</name>

                            <build>
                                <from>openjdk:${alpn-java.version}-jre</from>
                                <ports>
                                    <port>53/udp</port>
                                    <port>5001</port>
                                    <port>5002</port>
                                    <port>14001</port>
                                </ports>
                                <cmd>
                                    <shell>
                                        java -Xbootclasspath/p:/maven/alpn-boot-${alpn-boot.version}.jar -cp "/maven/*" org.shredzone.acme4j.it.BammBamm
                                    </shell>
                                </cmd>
                                <assembly>
                                    <descriptorRef>artifact-with-dependencies</descriptorRef>
                                </assembly>
                            </build>

                            <run>
                                <namingStrategy>alias</namingStrategy>
                                <hostname>bammbamm</hostname>
                                <ports>
                                    <port>14001:14001</port>
                                </ports>
                                <wait>
                                    <log>Bammbamm running</log>
                                </wait>
                            </run>
                        </image>
                    </images>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.shredzone.acme4j</groupId>
            <artifactId>acme4j-client</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.shredzone.acme4j</groupId>
            <artifactId>acme4j-utils</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>org.mortbay.jetty.alpn</groupId>
            <artifactId>alpn-boot</artifactId>
            <version>${alpn-boot.version}</version>
        </dependency>
        <dependency>
            <groupId>org.nanohttpd</groupId>
            <artifactId>nanohttpd</artifactId>
            <version>${nanohttpd.version}</version>
        </dependency>
        <dependency>
            <groupId>org.nanohttpd</groupId>
            <artifactId>nanohttpd-nanolets</artifactId>
            <version>${nanohttpd.version}</version>
        </dependency>
        <dependency>
            <groupId>dnsjava</groupId>
            <artifactId>dnsjava</artifactId>
            <version>${dnsjava.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>${httpclient.version}</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
    </dependencies>
</project>
