<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>
  <parent>
    <groupId>org.eclipse.hono</groupId>
    <artifactId>hono-bom</artifactId>
    <version>0.5-M2</version>
    <relativePath>../bom</relativePath>
  </parent>
  <artifactId>hono-app</artifactId>
  <name>Hono Application</name>
  <description>A Spring Boot application for running a Hono server</description>

  <properties>
    <!-- name of Docker image -->
    <image.target>hono-server</image.target>
  </properties>

  <dependencies>
  	<dependency>
  		<groupId>org.eclipse.hono</groupId>
  		<artifactId>hono-server</artifactId>
  	</dependency>
  	<dependency>
  		<groupId>org.yaml</groupId>
  		<artifactId>snakeyaml</artifactId>
  	</dependency>
  	<dependency>
  		<groupId>org.eclipse.hono</groupId>
  		<artifactId>hono-legal</artifactId>
  	</dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <systemPropertyVariables>
            <java.util.logging.config.file>${project.build.testOutputDirectory}/logging.properties</java.util.logging.config.file>
          </systemPropertyVariables>
        </configuration>
      </plugin>
      <plugin>
        <!-- 
          Copy legal documents from "legal" module to "target/classes" folder
          so that we make sure to include legal docs in all modules.
         -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>build-docker-image</id>
      <activation>
        <property>
          <name>docker.host</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
          </plugin>
          <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <configuration>
              <verbose>true</verbose>
              <images>
                <image>
                  <build>
                    <from>anapsix/alpine-java:8</from>
                    <ports>
                      <port>5672</port>
                    </ports>
                    <runCmds>
                      <runCmd>adduser -S -D hono nogroup</runCmd>
                    </runCmds>
                    <user>hono</user>
                    <workdir>/home/hono</workdir>
                    <cmd>
                      <exec>
                        <arg>java</arg>
                        <arg>-Dvertx.disableDnsResolver=true</arg>
                        <arg>-Dnetworkaddress.cache.ttl=0</arg>
                        <arg>-Dnetworkaddress.cache.negative.ttl=0</arg>
                        <arg>-jar</arg>
                        <arg>
                          /opt/hono/${project.artifactId}-${project.version}.jar
                        </arg>
                      </exec>
                    </cmd>
                    <assembly>
                      <basedir>/opt/hono</basedir>
                      <descriptorRef>artifact</descriptorRef>
                    </assembly>
                  </build>
                </image>
              </images>
            </configuration>
            <executions>
              <execution>
                <phase>package</phase>
                <goals>
                  <goal>build</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

</project>