<?xml version="1.0" encoding="UTF-8"?>
<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>com.willwinder</groupId>
        <artifactId>ugs-platform-parent</artifactId>
        <version>2.0-SNAPSHOT</version>
    </parent>

    <artifactId>ugs-platform-app</artifactId>
    <version>2.0-SNAPSHOT</version>
    <packaging>nbm-application</packaging>

    <name>ugs-platform-app</name>

    <dependencies>
        <dependency>
            <groupId>org.netbeans.cluster</groupId>
            <artifactId>platform</artifactId>
            <version>${netbeans.version}</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>ugs-platform-branding</artifactId>
            <version>${project.version}</version>
        </dependency>
        <!-- NbModuleSuite functional in RELEASE70 or later: -->
        <dependency>
            <groupId>org.netbeans.api</groupId>
            <artifactId>org-netbeans-modules-nbjunit</artifactId>
            <version>${netbeans.version}</version>
            <scope>test</scope> <!-- beyond platform cluster, this often needs to be dropped down to compile/runtime, some other modules in IDE clusters depend on it -->
        </dependency>
        <!-- To use Jelly Tools in your functional tests, add or replace with:
        <dependency>
            <groupId>org.netbeans.api</groupId>
            <artifactId>org-netbeans-modules-jellytools-platform</artifactId>
            <version>${netbeans.version}</version>
            <scope>test</scope>
        </dependency>
        -->
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>ugs-platform-visualizer</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>ugs-platform-ugscore</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>ugs-platform-ugslib</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>ugs-platform-plugin-workflow</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>ugs-platform-gcode-editor</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>ugs-platform-surfacescanner</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>ProbeModule</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>nbm-maven-plugin</artifactId>
                <configuration>
                    <!-- Set up the gephi.conf for the final artifact -->
                    <etcConfFile>${basedir}/target/${brandingToken}.conf</etcConfFile>
                </configuration>
            </plugin>
            <!-- Permits NbModuleSuite to be run in integration-test phase: -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${ugs.maven-surefire-plugin.version}</version>
                <configuration>
                    <systemPropertyVariables>
                        <all.clusters>${all.clusters}</all.clusters>
                        <branding.token>${brandingToken}</branding.token>
                    </systemPropertyVariables>
                </configuration>
            </plugin>

            <!-- Copy ressources gephi.conf and Info.plist with filtering (replacing 'project.version' by the actual version -->
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>generate-app-conf-file</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/target/</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/main/resources</directory>
                                    <includes>
                                        <include>${brandingToken}.conf</include>
                                        <include>Info.plist</include>
                                    </includes>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                            <escapeString>\</escapeString>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>deployment</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>nbm-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>extra</id>
                                <goals>
                                    <goal>autoupdate</goal>
                                    <goal>webstart-app</goal>
                                    <goal>build-installers</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
          <id>create-dmg</id>
          <properties>
              <skipCreateDmg>false</skipCreateDmg>
          </properties>
          <build>
            <plugins>
              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                  <!-- Create the Mac OS X application bundle and dmg file -->
                  <execution>
                      <id>create-app-bundle</id>
                      <phase>package</phase>
                      <goals>
                          <goal>run</goal>
                      </goals>
                      <configuration>
                          <skip>${skipCreateDmg}</skip>
                          <target>
                              <!-- Clean -->
                              <delete includeEmptyDirs="true" failonerror="false" removeNotFollowedSymlinks="true">
                                  <fileset dir="${project.build.directory}/${ugs.appbundle.name}.app" followsymlinks="false"/>
                                  <fileset dir="${project.build.directory}/${ugs.app.title}" followsymlinks="false"/>
                                  <fileset dir="${project.build.directory}/${project.artifactId}-${project.version}.dmg" followsymlinks="false"/>
                              </delete>
                              <delete file="${project.build.directory}/${project.artifactId}-${project.version}.dmg" failonerror="false"/>

                              <!-- Create folders -->
                              <mkdir dir="${project.build.directory}/${ugs.appbundle.name}.app"/>
                              <mkdir dir="${project.build.directory}/${ugs.appbundle.name}.app/Contents/MacOS"/>

                              <!-- Copy application -->
                              <copy todir="${project.build.directory}/${ugs.appbundle.name}.app/Contents/Resources/${brandingToken}">
                                  <fileset dir="${project.build.directory}/${brandingToken}"/>
                              </copy>

                              <!-- Copy logo and configuration files -->
                              <copy tofile="${project.build.directory}/${ugs.appbundle.name}.app/Contents/Resources/${brandingToken}.icns" file="src/main/app-resources/${brandingToken}.icns" />
                              <copy tofile="${project.build.directory}/${ugs.appbundle.name}.app/Contents/Info.plist" file="${project.build.directory}/Info.plist"/>

                              <!-- Move bin/ugsplatform script into MacOS/ugsplatform and modify the script so it founds its resources -->
                              <move file="${project.build.directory}/${ugs.appbundle.name}.app/Contents/Resources/${brandingToken}/bin/${brandingToken}" todir="${project.build.directory}/${ugs.appbundle.name}.app/Contents/MacOS"/>
                              <replace file="${project.build.directory}/${ugs.appbundle.name}.app/Contents/MacOS/${brandingToken}" token="`dirname &quot;$PRG&quot;`" value="`dirname &quot;$PRG&quot;`&quot;/../Resources/${brandingToken}/bin&quot;"/>
                              <chmod file="${project.build.directory}/${ugs.appbundle.name}.app/Contents/MacOS/${brandingToken}" perm="ugo+rx"/>

                              <!-- Download and untar JRE -->
                              <exec dir="${project.build.directory}" executable="curl" failonerror="true">
                                  <arg line="-L"/>
                                  <arg line="-C"/>
                                  <arg line="-"/>
                                  <arg line="-b"/>
                                  <arg line="&quot;oraclelicense=accept-securebackup-cookie&quot;"/>
                                  <arg line="-O"/>
                                  <arg line="${ugs.bundle.java.url}/${ugs.mac.bundle.jvm.version}.tar.gz"/>
                              </exec>

                              <!-- Unzip archive -->
                              <mkdir dir="${project.build.directory}/${ugs.appbundle.name}.app/Contents/PlugIns"/>
                              <exec dir="${project.build.directory}" executable="tar" failonerror="true">
                                  <arg line="-zxf"/>
                                  <arg line="${ugs.mac.bundle.jvm.version}.tar.gz"/>
                                  <arg line="-C &quot;${ugs.appbundle.name}.app/Contents/PlugIns&quot;"/>
                              </exec>

                              <!-- Remove quarantine bit set recursively on JRE -->
                              <!--
                              <exec dir="${project.build.directory}" os="Mac OS X" executable="xattr" failonerror="true">
                                  <arg line="-rd"/>
                                  <arg line="com.apple.quarantine"/>
                                  <arg line="&quot;${ugs.appbundle.name}.app/Contents/PlugIns&quot;"/>
                              </exec>
                              -->

                              <!-- Get the JRE folder name -->
                              <path id="jre_name_osx">
                                  <dirset dir="${project.build.directory}/${ugs.appbundle.name}.app/Contents/PlugIns" includes="jre*" />
                              </path>
                              <property name="bundle.mac.jvm.path" refid="jre_name_osx" />
                              <basename property="bundle.mac.jvm.name" file="${bundle.mac.jvm.path}"/>

                              <!-- Configure relative JRE path into ugsplatform.conf -->
                              <replace file="${project.build.directory}/${ugs.appbundle.name}.app/Contents/Resources/${brandingToken}/etc/${brandingToken}.conf" token="#jdkhome=&quot;/path/to/jdk&quot;" value="jdkhome=&quot;../../PlugIns/${bundle.mac.jvm.name}/Contents/Home&quot;"/>
                              <chmod file="${project.build.directory}/${ugs.appbundle.name}.app/Contents/PlugIns/**" perm="+x" type="both"/>

                              <!-- Fix JRE by replacing libjli.dylib symlink with real file -->
                              <delete file="${project.build.directory}/${ugs.appbundle.name}.app/Contents/PlugIns/${bundle.mac.jvm.name}/Contents/MacOS/libjli.dylib"/>
                              <copy file="${project.build.directory}/${ugs.appbundle.name}.app/Contents/PlugIns/${bundle.mac.jvm.name}/Contents/Home/lib/jli/libjli.dylib" todir="${project.build.directory}/${ugs.appbundle.name}.app/Contents/PlugIns/${bundle.mac.jvm.name}/Contents/MacOS"/>

                              <!-- Codesign JRE -->
                              <!--
                              <exec dir="${project.build.directory}" os="Mac OS X" executable="codesign" failonerror="true">
                                  <arg value="-fs"/>
                                  <arg value="${ugs.codesign.identity}"/>
                                  <arg value="-v"/>
                                  <arg value="${ugs.appbundle.name}.app/Contents/PlugIns/${bundle.mac.jvm.name}/"/>
                              </exec>
                              -->

                              <!-- Codesign app -->
                              <!--
                              <exec dir="${project.build.directory}" os="Mac OS X" executable="codesign" failonerror="true">
                                  <arg value="-fs"/>
                                  <arg value="${ugs.codesign.identity}"/>
                                  <arg value="-v"/>
                                  <arg value="${ugs.appbundle.name}.app"/>
                              </exec>
                              -->

                              <!-- Create application folder and add Applications dynamic link -->
                              <mkdir dir="${project.build.directory}/${ugs.app.title}"/>
                              <move file="${project.build.directory}/${ugs.appbundle.name}.app" todir="${project.build.directory}/${ugs.app.title}/" />
                              <symlink link="${project.build.directory}/${ugs.app.title}/Applications" resource="/Applications" failonerror="false" />

                              <!-- Create DMG (Mac OS X) -->
                              <exec dir="${project.build.directory}" os="Mac OS X" executable="hdiutil" failonerror="true">
                                  <arg value="create"/>
                                  <arg value="-noanyowners"/>
                                  <arg value="-imagekey"/>
                                  <arg value="zlib-level=9"/>
                                  <arg value="-srcfolder"/>
                                  <arg value="${project.build.directory}/${ugs.app.title}"/>
                                  <arg value="${project.artifactId}-${project.version}.dmg"/>
                              </exec>

                              <!-- Create DMG (Linux), only for testing -->
                              <exec dir="${project.build.directory}" os="Linux" executable="genisoimage" failonerror="true">
                                  <arg value="-V"/>
                                  <arg value="${ugs.appbundle.name}"/>
                                  <arg value="-U"/>
                                  <arg value="-D"/>
                                  <arg value="-l"/>
                                  <arg value="-allow-multidot"/>
                                  <arg value="-max-iso9660-filenames"/>
                                  <arg value="-relaxed-filenames"/>
                                  <arg value="-no-iso-translate"/>
                                  <arg value="-r"/>
                                  <arg value="-o"/>
                                  <arg value="${project.artifactId}-${project.version}.dmg"/>
                                  <arg value="-root"/>
                                  <arg value="${project.build.directory}/${ugs.app.title}"/>
                                  <arg value="${project.build.directory}/${ugs.app.title}"/>
                              </exec>
                          </target>
                      </configuration>
                  </execution>
                </executions>
              </plugin>
            </plugins>
          </build>
        </profile>

     <!-- Create the RaspberryPi application bundle -->
     <profile>
       <id>create-raspberry-pi</id>
       <properties>
           <skipCreateRPi>false</skipCreateRPi>
       </properties>
       <build>
         <plugins>
           <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-antrun-plugin</artifactId>
             <executions>
               <execution>
                 <id>create-rpi-bundle</id>
                 <phase>package</phase>
                 <goals>
                     <goal>run</goal>
                 </goals>
                 <configuration>
                   <skip>${skipCreateRPi}</skip>
                   <target>
                     <!-- Clean -->
                     <delete includeEmptyDirs="true" failonerror="false" removeNotFollowedSymlinks="true">
                       <fileset dir="${project.build.directory}/${ugs.appbundle.name}.pi" followsymlinks="false"/>
                     </delete>
                     <delete file="${project.build.directory}/${project.artifactId}-${project.version}.pi.tar.gz" failonerror="false"/>

                     <!-- Create folders -->
                     <mkdir dir="${project.build.directory}/${ugs.appbundle.name}.pi"/>

                     <!-- Copy application -->
                     <copy todir="${project.build.directory}/${ugs.appbundle.name}.pi">
                       <fileset dir="${project.build.directory}/${brandingToken}"/>
                     </copy>

                     <!-- Download and untar JRE -->
                     <exec dir="${project.build.directory}" executable="curl" failonerror="true">
                       <arg line="-L"/>
                       <arg line="-C"/>
                       <arg line="-"/>
                       <arg line="-b"/>
                       <arg line="&quot;oraclelicense=accept-securebackup-cookie&quot;"/>
                       <arg line="-O"/>
                       <arg line="${ugs.bundle.java.url}/${ugs.rpi.bundle.jvm.version}.tar.gz"/>
                     </exec>

                     <!-- Unzip archive -->
                     <exec dir="${project.build.directory}" executable="tar" failonerror="true">
                       <arg line="-zxf"/>
                       <arg line="${ugs.rpi.bundle.jvm.version}.tar.gz"/>
                       <arg line="-C &quot;${ugs.appbundle.name}.pi&quot;"/>
                     </exec>

                     <!-- Download ARM JavaFX binaries -->
                     <exec dir="${project.build.directory}" executable="curl" failonerror="true">
                       <arg line="${ugs.rpi.bundle.javafx.url}"/>
                       <arg line="-o"/>
                       <arg line="${project.build.directory}/gluon.javafx.zip"/>
                     </exec>

                     <!-- Get the JRE folder name -->
                     <path id="jre_name">
                       <dirset dir="${project.build.directory}/${ugs.appbundle.name}.pi" includes="jdk*" />
                     </path>
                     <property name="bundle.rpi.jvm.path" refid="jre_name" />
                     <basename property="bundle.rpi.jvm.name" file="${bundle.rpi.jvm.path}"/>

                     <!-- Unzip into build directory -->
                     <mkdir dir="${project.build.directory}/gluon"/>
                     <exec dir="${project.build.directory}" executable="tar" failonerror="true">
                       <arg line="-zxf"/>
                       <arg line="gluon.javafx.zip"/>
                       <arg line="-C ${project.build.directory}/gluon"/>
                     </exec>

                     <!-- Get the JavaFX folder name -->
                     <path id="javafx_name">
                       <dirset dir="${project.build.directory}/gluon" includes="*" />
                     </path>
                     <property name="bundle.javafx.path" refid="javafx_name" />

                     <!-- Sync JavaFX libraries into JDK -->
                     <exec dir="${project.build.directory}" executable="rsync" failonerror="true">
                       <arg line="-a"/>
                       <arg line="${bundle.javafx.path}/"/>
                       <arg line="&quot;${bundle.rpi.jvm.path}/&quot;"/>
                     </exec>

                     <!-- Configure relative JRE path into ugsplatform.conf -->
                     <replace file="${project.build.directory}/${ugs.appbundle.name}.pi/etc/${brandingToken}.conf" token="#jdkhome=&quot;/path/to/jdk&quot;" value="jdkhome=&quot;../${bundle.rpi.jvm.name}&quot;"/>
                     <chmod file="${project.build.directory}/${ugs.appbundle.name}.pi/bin/**" perm="+x" type="both"/>

                     <!-- Create Archive -->
                     <exec dir="${project.build.directory}" executable="tar" failonerror="true">
                       <env key="GZIP" value="-9"/>
                       <arg value="-czvf"/>
                       <arg value="${project.artifactId}-${project.version}.pi.tar.gz"/>
                       <arg value="${project.build.directory}/${ugs.appbundle.name}.pi"/>
                     </exec>
                   </target>
                 </configuration>
               </execution>
             </executions>
           </plugin>
         </plugins>
       </build>
     </profile>

      <profile>
        <id>create-autoupdate</id>
        <build>
          <plugins>
            <!-- NBM Plugin settings. Enable the autoupdate generation -->
            <plugin>
              <groupId>org.codehaus.mojo</groupId>
              <artifactId>nbm-maven-plugin</artifactId>
              <executions>
                <execution>
                  <id>autoupdate</id>
                  <goals>
                    <goal>autoupdate</goal>
                  </goals>
                  <configuration>
                    <outputDirectory>${project.build.directory}/site</outputDirectory>
                  </configuration>
                </execution>
              </executions>
            </plugin>
          </plugins>
        </build>
      </profile>

      <!-- Profile that pushes autoupdate files to sourceforge -->
      <profile>
        <id>push-autoupdate-sf</id>
        <properties>
          <sourceforge.path>/home/frs/project/u/ug/ugs-update-center/</sourceforge.path>
        </properties>
        <build>
          <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-antrun-plugin</artifactId>
              <executions>
                <execution>
                  <id>copy-to-sourceforge</id>
                  <phase>install</phase>
                  <goals>
                    <goal>run</goal>
                  </goals>
                  <configuration>
                    <target>

                      <!-- remove extra files -->
                      <delete dir="${project.build.directory}/site/${project.version}/" failonerror="false"/>
                      <copy todir="${project.build.directory}/site/${project.version}">
                        <fileset dir="${project.build.directory}/site/netbeans_site/" includes="**"/>
                      </copy>

                      <!-- copy autoupdate files to sourceforge -->
                      <scp todir="${sourceforge.login}:${sourceforge.password}@frs.sourceforge.net:${sourceforge.path}" sftp="true" trust="true">
                        <fileset dir="${project.build.directory}/site/">
                          <include name="**/${project.version}/"/>
                        </fileset>
                      </scp>
                    </target>
                  </configuration>
                </execution>
              </executions>
                <dependencies>
                  <!-- scp dependencies -->
                  <dependency>
                    <groupId>org.apache.ant</groupId>
                    <artifactId>ant-jsch</artifactId>
                    <version>1.10.1</version>
                  </dependency>
                  <dependency>
                    <groupId>com.jcraft</groupId>
                    <artifactId>jsch</artifactId>
                    <version>0.1.54</version>
                  </dependency>
                  <!-- ftp dependencies -->
                  <dependency>
                    <groupId>commons-net</groupId>
                    <artifactId>commons-net</artifactId>
                    <version>1.4.1</version>
                  </dependency>
                  <dependency>
                    <groupId>org.apache.ant</groupId>
                    <artifactId>ant-commons-net</artifactId>
                    <version>1.8.1</version>
                  </dependency>
                </dependencies>
            </plugin>
          </plugins>
        </build>
      </profile>

      <!-- Profile that pushes the /site folder to GitHub's gh-pages -->
      <!--
         Usage:
            mvn install -P create-autoupdate,push-autoupdate

         Configuration:
            The site-maven-plugin uses the <scm> settings from a parent POM.
            
            settings.xml entry for github credentials

            <server>
              <id>github</id>
              <username>username</username>
              <password>password</password>
            </server>

         Note: This is slow. After a 'mvn clean' this command took 6:20 min.
      -->
      <profile>
        <id>push-autoupdate-gh</id>
        <properties>
          <github.global.server>github</github.global.server>
        </properties>
        <build>
          <plugins>
            <!-- Copy parent's site into target/site -->
            <!--
            <plugin>
              <artifactId>maven-antrun-plugin</artifactId>
              <executions>
                <execution>
                  <phase>site</phase>
                  <configuration>
                    <target>
                      <copy todir="${project.build.directory}/site">
                        <fileset dir="${basedir}/../../target/site"/>
                      </copy>
                    </target>
                  </configuration>
                  <goals>
                    <goal>run</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
            -->
            <!-- Publish site folder to GitHub's gh-pages branch -->
            <plugin>
              <groupId>com.github.github</groupId>
              <artifactId>site-maven-plugin</artifactId>
              <configuration>
                <message>Creating site for ${project.version}</message>
                <path>${project.version}</path>
                <merge>true</merge>
                <!--<repositoryName>ugs-platform-updates</repositoryName>-->
                <repositoryName>gh-site-test</repositoryName>
                <repositoryOwner>winder</repositoryOwner>
              </configuration>
              <executions>
                <execution>
                  <goals>
                    <goal>site</goal>
                  </goals>
                  <phase>install</phase>
                </execution>
              </executions>
            </plugin>
          </plugins>
        </build>
      </profile>
    </profiles>
</project>
