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

  <properties>
    <hono.username>mqtt-adapter@HONO</hono.username>
    <hono.password>mqtt-secret</hono.password>
  </properties>

  <dependencies>
    <dependency>
      <groupId>io.vertx</groupId>
      <artifactId>vertx-mqtt-server</artifactId>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
      <plugin>
        <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>io.fabric8</groupId>
            <artifactId>fabric8-maven-plugin</artifactId>
            <configuration>
              <images>
                <image>
                  <build>
                    <from>${java-base-image.name}</from>
                    <ports>
                      <port>1883</port>
                      <port>8883</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>-jar</arg>
                        <arg>/opt/hono/${project.artifactId}-${project.version}-${classifier.spring.boot.artifact}.jar</arg>
                      </exec>
                    </cmd>
                    <assembly>
                      <mode>dir</mode>
                      <basedir>/</basedir>
                      <inline>
                        <fileSets>
                          <fileSet>
                            <directory>${project.build.directory}/certs</directory>
                            <outputDirectory>etc/hono/certs</outputDirectory>
                            <includes>
                              <include>mqtt-adapter-*.pem</include>
                              <include>trusted-certs.pem</include>
                            </includes>
                          </fileSet>
                          <fileSet>
                            <directory>${project.build.directory}</directory>
                            <outputDirectory>opt/hono</outputDirectory>
                            <includes>
                              <include>${project.artifactId}-${project.version}-${classifier.spring.boot.artifact}.jar</include>
                            </includes>
                          </fileSet>
                        </fileSets>
                      </inline>
                    </assembly>
                  </build>
                </image>
              </images>
              <resources>
                <env>
                  <HONO_MQTT_BIND_ADDRESS>0.0.0.0</HONO_MQTT_BIND_ADDRESS>
                  <HONO_MQTT_INSECURE_PORT_BIND_ADDRESS>0.0.0.0</HONO_MQTT_INSECURE_PORT_BIND_ADDRESS>
                  <HONO_MQTT_INSECURE_PORT_ENABLED>true</HONO_MQTT_INSECURE_PORT_ENABLED>
                  <HONO_MQTT_KEY_PATH>/etc/hono/certs/mqtt-adapter-key.pem</HONO_MQTT_KEY_PATH>
                  <HONO_MQTT_CERT_PATH>/etc/hono/certs/mqtt-adapter-cert.pem</HONO_MQTT_CERT_PATH>
                  <HONO_MQTT_MAX_INSTANCES>1</HONO_MQTT_MAX_INSTANCES>
                </env>
              </resources>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

</project>
