<?xml version="1.0" encoding="UTF-8"?>
<!--

    See the NOTICE file distributed with this work for additional
    information regarding copyright ownership.

    This is free software; you can redistribute it and/or modify it
    under the terms of the GNU Lesser General Public License as
    published by the Free Software Foundation; either version 2.1 of
    the License, or (at your option) any later version.

    This software 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. See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this software; if not, write to the Free
    Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
    02110-1301 USA, or see the FSF site: http://www.fsf.org.

-->
<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>edu.toronto.cs.medsavant</groupId>
    <artifactId>medsavant-distribution</artifactId>
    <version>1.2.2</version>
  </parent>

  <artifactId>medsavant-server-deb</artifactId>
  <packaging>pom</packaging>
  <name>MedSavant - Server - Debian Distribution</name>
  <description>Distribution containing the MedSavantServer module and its dependencies as a Debian package.</description>

  <dependencies>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>medsavant-server</artifactId>
      <version>${project.version}</version>
    </dependency>
  </dependencies>

  <build>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
    </resources>

    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-resources</id>
            <goals>
              <goal>resources</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-dependencies</id>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
            <configuration>
              <excludeArtifactIds>medsavant-server</excludeArtifactIds>
              <outputDirectory>${project.build.directory}/deb/lib</outputDirectory>
            </configuration>
          </execution>
          <execution>
            <id>copy-server</id>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
            <configuration>
              <includeArtifactIds>medsavant-server</includeArtifactIds>
              <excludeTransitive>true</excludeTransitive>
              <outputDirectory>${project.build.directory}/deb</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.vafer</groupId>
        <artifactId>jdeb</artifactId>
        <version>1.0.1</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>jdeb</goal>
            </goals>
            <configuration>
              <timestamped>true</timestamped>
              <dataSet>
                <data>
                  <type>directory</type>
                  <src>${project.build.directory}/deb/lib</src>
                  <mapper>
                    <type>perm</type>
                    <prefix>/usr/local/medsavant-server-${project.version}/lib</prefix>
                  </mapper>
                </data>
                <data>
                  <type>file</type>
                  <src>${project.build.directory}/deb/medsavant-server-${project.version}.jar</src>
                  <mapper>
                    <type>perm</type>
                    <prefix>/usr/local/medsavant-server-${project.version}/</prefix>
                  </mapper>
                </data>
                <data>
                  <type>link</type>
                  <linkName>/usr/local/medsavant-server</linkName>
                  <linkTarget>medsavant-server-${project.version}</linkTarget>
                  <symlink>true</symlink>
                </data>
                <data>
                  <type>file</type>
                  <src>${project.build.outputDirectory}/medsavant.default</src>
                  <dst>/etc/default/medsavant-server</dst>
                </data>
                <data>
                  <type>file</type>
                  <src>${project.build.outputDirectory}/medsavant.properties</src>
                  <dst>/var/lib/medsavant-server/medsavant.properties</dst>
                </data>
                <data>
                  <type>file</type>
                  <src>${project.build.outputDirectory}/medsavant.init</src>
                  <dst>medsavant-server</dst>
                  <mapper>
                    <type>perm</type>
                    <filemode>744</filemode>
                    <prefix>/etc/init.d</prefix>
                  </mapper>
                </data>
              </dataSet>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
