<!--

    Copyright © 2016-2018 The Thingsboard Authors

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<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.thingsboard</groupId>
        <version>2.2.0-SNAPSHOT</version>
        <artifactId>transport</artifactId>
    </parent>
    <groupId>org.thingsboard.transport</groupId>
    <artifactId>coap</artifactId>
    <packaging>jar</packaging>

    <name>Thingsboard CoAP Transport Service</name>
    <url>https://thingsboard.io</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <main.dir>${basedir}/../..</main.dir>
        <pkg.name>tb-coap-transport</pkg.name>
        <pkg.unixLogFolder>/var/log/${pkg.name}</pkg.unixLogFolder>
        <pkg.installFolder>/usr/share/${pkg.name}</pkg.installFolder>
        <pkg.win.dist>${project.build.directory}/windows</pkg.win.dist>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.thingsboard.common.transport</groupId>
            <artifactId>coap</artifactId>
        </dependency>
        <dependency>
            <groupId>org.thingsboard.common</groupId>
            <artifactId>queue</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.sun.winsw</groupId>
            <artifactId>winsw</artifactId>
            <classifier>bin</classifier>
            <type>exe</type>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>${pkg.name}-${project.version}</finalName>
        <resources>
            <resource>
                <directory>${project.basedir}/src/main/resources</directory>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-conf</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/conf</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/main/resources</directory>
                                    <excludes>
                                        <exclude>logback.xml</exclude>
                                    </excludes>
                                    <filtering>false</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-service-conf</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/conf</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/main/conf</directory>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                            <filters>
                                <filter>src/main/filters/unix.properties</filter>
                            </filters>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-win-conf</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${pkg.win.dist}/conf</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/main/resources</directory>
                                    <excludes>
                                        <exclude>logback.xml</exclude>
                                    </excludes>
                                    <filtering>false</filtering>
                                </resource>
                                <resource>
                                    <directory>src/main/conf</directory>
                                    <excludes>
                                        <exclude>tb-coap-transport.conf</exclude>
                                    </excludes>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                            <filters>
                                <filter>src/main/filters/windows.properties</filter>
                            </filters>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-control</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/control</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/main/scripts/control</directory>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                            <filters>
                                <filter>src/main/filters/unix.properties</filter>
                            </filters>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-windows-control</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${pkg.win.dist}</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/main/scripts/windows</directory>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                            <filters>
                                <filter>src/main/filters/windows.properties</filter>
                            </filters>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-winsw-service</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.sun.winsw</groupId>
                                    <artifactId>winsw</artifactId>
                                    <classifier>bin</classifier>
                                    <type>exe</type>
                                    <destFileName>service.exe</destFileName>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${pkg.win.dist}</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>**/logback.xml</exclude>
                    </excludes>
                    <archive>
                        <manifestEntries>
                            <Implementation-Title>ThingsBoard CoAP Transport Service</Implementation-Title>
                            <Implementation-Version>${project.version}</Implementation-Version>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>org.thingsboard.server.coap.ThingsboardCoapTransportApplication</mainClass>
                    <classifier>boot</classifier>
                    <layout>ZIP</layout>
                    <executable>true</executable>
                    <excludeDevtools>true</excludeDevtools>
                    <embeddedLaunchScriptProperties>
                        <confFolder>${pkg.installFolder}/conf</confFolder>
                        <logFolder>${pkg.unixLogFolder}</logFolder>
                        <logFilename>${pkg.name}.out</logFilename>
                        <initInfoProvides>${pkg.name}</initInfoProvides>
                    </embeddedLaunchScriptProperties>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.fortasoft</groupId>
                <artifactId>gradle-maven-plugin</artifactId>
                <configuration>
                    <tasks>
                        <task>build</task>
                        <task>buildDeb</task>
                        <task>buildRpm</task>
                    </tasks>
                    <args>
                        <arg>-PprojectBuildDir=${project.build.directory}</arg>
                        <arg>-PprojectVersion=${project.version}</arg>
                        <arg>-PmainJar=${project.build.directory}/${project.build.finalName}-boot.${project.packaging}</arg>
                        <arg>-PpkgName=${pkg.name}</arg>
                        <arg>-PpkgInstallFolder=${pkg.installFolder}</arg>
                        <arg>-PpkgLogFolder=${pkg.unixLogFolder}</arg>
                    </args>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>invoke</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <finalName>${pkg.name}</finalName>
                    <descriptors>
                        <descriptor>src/main/assembly/windows.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <configuration>
                    <file>${project.build.directory}/${pkg.name}.deb</file>
                    <artifactId>${project.artifactId}</artifactId>
                    <groupId>${project.groupId}</groupId>
                    <version>${project.version}</version>
                    <classifier>deb</classifier>
                    <packaging>deb</packaging>
                </configuration>
                <executions>
                    <execution>
                        <id>install-deb</id>
                        <phase>package</phase>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>jenkins</id>
            <name>Jenkins Repository</name>
            <url>http://repo.jenkins-ci.org/releases</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
</project>
