<?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.savant</groupId>
    <artifactId>savant-distribution</artifactId>
    <version>2.0.5</version>
  </parent>

  <artifactId>savant-windows-installer</artifactId>
  <packaging>pom</packaging>
  <name>Savant - Windows Installer Distribution</name>
  <description>Distribution containing the Savant Genome Browser and its dependencies as a Windows installer.</description>

  <dependencies>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>savant-installer</artifactId>
      <version>${project.version}</version>
    </dependency>

    <!-- Even though this dependency is defined in Launch4J's pom.xml we still need it to
         construct the correct maven.compile.classpath for executing the Launch4J Ant task below -->
    <dependency>
      <groupId>com.thoughtworks.xstream</groupId>
      <artifactId>xstream</artifactId>
      <version>1.2</version>
      <optional>true</optional>
    </dependency>
  </dependencies>
  <build>
    <resources>
      <!-- Copy and filter the launch4j.xml file -->
      <resource>
        <directory>${basedir}/src/main/resources</directory>
        <includes>
          <include>launch4j.xml</include>
        </includes>
        <filtering>true</filtering>
      </resource>
      <!-- Copy and don't filter the other resource files -->
      <resource>
        <directory>${basedir}/src/main/resources</directory>
        <excludes>
          <exclude>launch4j.xml</exclude>
        </excludes>
        <filtering>false</filtering>
      </resource>
    </resources>

    <plugins>
      <!-- Prepare the resources -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <phase>process-resources</phase>
            <goals>
              <goal>resources</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <!-- Copy the standalone installer -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>copy</id>
            <phase>package</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>launch4j</groupId>
                  <artifactId>launch4j</artifactId>
                  <version>3.0.2</version>
                </artifactItem>
                <artifactItem>
                  <groupId>${project.groupId}</groupId>
                  <artifactId>savant-installer</artifactId>
                  <version>${project.version}</version>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
          <execution>
            <id>unpack</id>
            <phase>package</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>launch4j</groupId>
                  <artifactId>launch4j</artifactId>
                  <version>3.0.2</version>
                  <classifier>${launch4jOs}</classifier>
                  <type>zip</type>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.3</version>
        <executions>
          <execution>
            <id>run-launch4j</id>
            <phase>package</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <tasks>
                <property name="classpath.compile" refid="maven.compile.classpath" />
                <taskdef name="launch4j" classname="net.sf.launch4j.ant.Launch4jTask" classpath="${classpath.compile}:${project.build.directory}/dependency/launch4j-3.0.2.jar" />
                <launch4j configFile="${project.build.directory}/classes/launch4j.xml" />
              </tasks>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <!-- Use the Maven build-helper plugin to attach the generated installer EXE to this
           project's main artifact -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.8</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>attach-artifact</goal>
            </goals>
            <configuration>
              <artifacts>
                <artifact>
                  <file>${project.build.directory}/${project.artifactId}-${project.version}.exe</file>
                  <type>exe</type>
                </artifact>
              </artifacts>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <id>unix</id>
      <activation>
        <os>
          <family>unix</family>
        </os>
      </activation>
      <properties>
        <launch4jOs>linux</launch4jOs>
      </properties>
    </profile>
    <profile>
      <id>mac</id>
      <activation>
        <os>
          <family>mac</family>
        </os>
      </activation>
      <properties>
        <launch4jOs>macosx-x86</launch4jOs>
      </properties>
    </profile>
    <profile>
      <id>windows</id>
      <activation>
        <os>
          <family>windows</family>
        </os>
      </activation>
      <properties>
        <launch4jOs>win32</launch4jOs>
      </properties>
    </profile>
  </profiles>
</project>
