<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-adapters</artifactId>
    <version>0.5-M4</version>
  </parent>
  <artifactId>hono-adapter-mqtt-vertx</artifactId>
  <name>Hono MQTT Adapter</name>

  <dependencies>
    <dependency>
      <groupId>io.vertx</groupId>
      <artifactId>vertx-mqtt-server</artifactId>
      <version>${vertx-mqtt.version}</version>
      <scope>system</scope>
      <systemPath>${project.basedir}/lib/vertx-mqtt-server-3.4.0-20161128.154251-24.jar</systemPath>
    </dependency>
    <dependency>
      <groupId>io.netty</groupId>
      <artifactId>netty-codec-mqtt</artifactId>
      <version>${netty.version}</version>
    </dependency>
    <dependency>
      <groupId>org.eclipse.hono</groupId>
      <artifactId>hono-client</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-autoconfigure</artifactId>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-logging</artifactId>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>org.eclipse.hono</groupId>
      <artifactId>hono-legal</artifactId>
    </dependency>
    <dependency>
      <groupId>org.eclipse.hono</groupId>
      <artifactId>hono-demo-certs</artifactId>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
          <includeSystemScope>true</includeSystemScope>
        </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>
        <!--
          Execution and configuration for copying certificates from related module
          to "target/classes" folder so that we can include them in the image.
         -->
        <executions>
          <execution>
            <id>copy_demo_certs</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
              <includeArtifactIds>hono-demo-certs</includeArtifactIds>
              <outputDirectory>${project.build.outputDirectory}/certs</outputDirectory>
              <excludes>META-INF/**</excludes>
            </configuration>
          </execution>
        </executions>
      </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>1883</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.cacheDirBase=/tmp</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>
                      <mode>dir</mode>
                      <basedir>/</basedir>
                      <inline>
                        <fileSets>
                          <fileSet>
                            <directory>${project.basedir}/target/classes/certs</directory>
                            <outputDirectory>etc/hono/certs</outputDirectory>
                            <includes>
                              <include>trusted-certs.pem</include>
                              <include>mqttKeyStore.p12</include>
                            </includes>
                          </fileSet>
                          <fileSet>
                            <directory>${project.basedir}/target</directory>
                            <outputDirectory>opt/hono</outputDirectory>
                            <includes>
                              <include>${project.artifactId}-${project.version}.jar</include>
                            </includes>
                          </fileSet>
                        </fileSets>
                      </inline>
                    </assembly>
                  </build>
                </image>
              </images>
            </configuration>
            <executions>
              <execution>
                <phase>package</phase>
                <goals>
                  <goal>build</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>fabric8-maven-plugin</artifactId>
            <version>3.2.14</version>
            <configuration>
              <mode>openshift</mode>
            </configuration>
            <executions>
              <execution>
                <phase>package</phase>
                <goals>
                  <goal>resource</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

</project>
