<?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>

    <groupId>org.devzendo</groupId>
    <artifactId>transputer-emulator</artifactId>
    <version>0.0.1</version>
    <packaging>pom</packaging>
    <name>Transputer Emulator</name>
    <description>This is an emulator of the 32-bit Inmos T414/T800/T801/T805 Transputer family, and a Node Server that
        interfaces it to a host OS, providing boot/debug/IO facilities.
        (Apache License v2) 2005-2019 Matt Gumbley, DevZendo.org
    </description>
    <url>https://devzendo.github.io/parachute</url>

    <organization>
        <name>DevZendo.org</name>
        <url>http://devzendo.org/</url>
    </organization>

    <licenses>
        <license>
            <name>The Apache Software License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <scm>
        <url>https://bitbucket.org/devzendo/transputer-emulator/</url>
        <connection>scm:hg:https://bitbucket.org/devzendo/transputer-emulator/</connection>
        <developerConnection>scm:hg:https://bitbucket.org/devzendo/transputer-emulator/</developerConnection>
    </scm>

    <developers>
        <developer>
            <id>matt.gumbley</id>
            <name>Matt Gumbley</name>
            <email>matt.gumbley@devzendo.org</email>
        </developer>
    </developers>

    <distributionManagement>
        <snapshotRepository>
            <id>sonatype-nexus-snapshots</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
        <repository>
            <id>sonatype-nexus-staging</id>
            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
        </repository>
    </distributionManagement>

    <properties>
        <cmake.binary.dir>cmake-build-debug</cmake.binary.dir>
        <download.cmake>false</download.cmake>
    </properties>

    <!-- use mvn enforcer:display-info to find platform name/family values -->
    <!-- CentOS 7:
         [INFO] Maven Version: 3.6.0
         [INFO] JDK Version: 1.8.0_201 normalized as: 1.8.0-201
         [INFO] OS Info: Arch: amd64 Family: unix Name: linux Version: 3.10.0-957.5.1.el7.x86_64
         Raspbian:
         [INFO] Maven Version: 3.6.0
         [INFO] JDK Version: 1.8.0_65 normalized as: 1.8.0-65
         [INFO] OS Info: Arch: arm Family: unix Name: linux Version: 4.9.35+
         Mac OS High Sierra:
         [INFO] Maven Version: 3.6.0
         [INFO] JDK Version: 1.8.0_25 normalized as: 1.8.0-25
         [INFO] OS Info: Arch: x86_64 Family: mac Name: mac os x Version: 10.11.6
    -->
    <profiles>
        <!-- There are two main profiles, build and deploy.

             build is used on each Jenkins node to compile, link and assemble the OS-specific archive. Jenkins runs
             this profile across all OS-varying nodes, then archives the artifact.

             deploy is used on the Jenkins master. The master Jenkins job runs the build profile across all nodes as
             above, and then copies all artifacts from all nodes (using the Copy Artifact Plugin) to the target folder.
             Then the build helper plugin attaches these externally generated archive artifacts to the project,
             they are then signed, and uploaded to nexus.

             This funk is since the behaviour of the nexus staging plugin differs in snapshot and release mode: all
             snapshots are deployed to the same repo, but each release is deployed to its own - and I haven't managed
             to work out how to get the snapshot behaviour on release.


             There are also OS-specific profiles that activate on each OS-specific node.
        -->
        <profile>
            <id>build</id>
            <build>
                <resources>
                    <resource>
                        <directory>src/main/resources</directory>
                        <filtering>true</filtering>
                    </resource>
                </resources>

                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-clean-plugin</artifactId>
                        <version>3.1.0</version>
                        <configuration>
                            <filesets>
                                <fileset>
                                    <directory>${cmake.binary.dir}</directory>
                                    <followSymlinks>false</followSymlinks>
                                </fileset>
                            </filesets>
                        </configuration>
                    </plugin>

                    <!-- Generate the target/classes/version.cpp file that CMakeLists.txt picks up -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-resources-plugin</artifactId>
                        <version>3.0.1</version>
                        <executions>
                            <execution>
                                <id>default-resources</id>
                                <phase>generate-resources</phase>
                                <goals>
                                    <goal>resources</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>com.googlecode.cmake-maven-project</groupId>
                        <artifactId>cmake-maven-plugin</artifactId>
                        <version>3.7.2-b1</version>
                        <executions>
                            <!-- Generate the CMake cache/binary build dir -->
                            <execution>
                                <id>cmake-generate</id>
                                <phase>process-resources</phase>
                                <goals>
                                    <goal>generate</goal>
                                </goals>
                                <configuration>
                                    <sourcePath>${project.basedir}</sourcePath>
                                    <targetPath>${project.basedir}/${cmake.binary.dir}</targetPath>
                                    <generator>${cmake.generator}</generator>
                                    <classifier>${cmake.classifier}</classifier>
                                </configuration>
                            </execution>

                            <execution>
                                <id>cmake-compile</id>
                                <goals>
                                    <goal>compile</goal>
                                </goals>
                                <configuration>
                                    <target>all</target>
                                    <!-- "targetPath" from the "generate" goal: -->
                                    <projectDirectory>${project.basedir}/${cmake.binary.dir}</projectDirectory>
                                    <classifier>${cmake.classifier}</classifier>
                                </configuration>
                            </execution>

                            <execution>
                                <id>cmake-test</id>
                                <goals>
                                    <goal>test</goal>
                                </goals>
                                <configuration>
                                    <!-- "buildDirectory" is "targetPath" from the "generate" goal -->
                                    <buildDirectory>${project.basedir}/${cmake.binary.dir}</buildDirectory>
                                    <options>
                                        <option>--verbose</option>
                                    </options>
                                    <!-- Optional way to not fail the build on test failures -->
                                    <!-- <testFailureIgnore>true</testFailureIgnore> -->
                                    <!-- Optional way to skip just the ctest tests -->
                                    <!-- <ctest.skip.tests>true</ctest.skip.tests> -->
                                    <!-- Optional/standard way to skip all Maven tests -->
                                    <!-- <maven.test.skip>true</maven.test.skip> -->
                                    <!-- Optional way to configure number of threads tests should use -->
                                    <!-- <threadCount>2</threadCount> -->
                                    <!-- Optional dashboard configuration; used with CTestConfig.cmake -->
                                    <!-- <dashboard>Experimental</dashboard> -->
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <version>3.1.1</version>
                        <configuration>
                            <descriptors>
                                <descriptor>src/main/assembly/${assembly.name}.xml</descriptor>
                            </descriptors>
                        </configuration>
                        <executions>
                            <execution>
                                <id>make-assembly</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>linux-amd64</id>
            <activation>
                <os>
                    <name>linux</name>
                    <arch>amd64</arch>
                </os>
            </activation>
            <properties>
                <!-- The CMake maven plugin understands cmake.root.dir -->
                <cmake.root.dir>/opt/cmake</cmake.root.dir>

                <!-- One of the generators defined at https://cmake.org/cmake/help/v3.7/manual/cmake-generators.7.html -->
                <cmake.generator>Unix Makefiles</cmake.generator>
                <!-- The classifier of the current platform. One of [windows-x86_32, windows-x86_64, linux-x86_32, linux-x86_64, linux-arm_32, mac-x86_64]. -->
                <cmake.classifier>linux-x86_64</cmake.classifier>

                <install.dir>/opt/parachute</install.dir>
                <binary.suffix></binary.suffix>
                <assembly.name>linux-distribution</assembly.name>
            </properties>
            <build>
            </build>
        </profile>
        <profile>
            <id>linux-arm</id>
            <activation>
                <os>
                    <name>linux</name>
                    <arch>arm</arch>
                </os>
            </activation>
            <properties>
                <!-- The CMake maven plugin understands cmake.root.dir -->
                <cmake.root.dir>/opt/cmake</cmake.root.dir>

                <!-- One of the generators defined at https://cmake.org/cmake/help/v3.7/manual/cmake-generators.7.html -->
                <cmake.generator>Unix Makefiles</cmake.generator>
                <!-- The classifier of the current platform. One of [windows-x86_32, windows-x86_64, linux-x86_32, linux-x86_64, linux-arm_32, mac-x86_64]. -->
                <cmake.classifier>linux-arm_32</cmake.classifier>

                <install.dir>/opt/parachute</install.dir>
                <binary.suffix></binary.suffix>
                <assembly.name>linux-distribution</assembly.name>
            </properties>
            <build>
            </build>
        </profile>
        <profile>
            <id>macosx</id>
            <activation>
                <os>
                    <name>mac os x</name>
                </os>
            </activation>
            <properties>
                <!-- The CMake maven plugin understands cmake.root.dir -->
                <cmake.root.dir>/opt/local</cmake.root.dir>

                <!-- These are two of my properties I pass in to the CMake plugin, they're not known by the plugin innately -->
                <!-- One of the generators defined at https://cmake.org/cmake/help/v3.7/manual/cmake-generators.7.html -->
                <cmake.generator>Unix Makefiles</cmake.generator>
                <!-- The classifier of the current platform. One of [windows-x86_32, windows-x86_64, linux-x86_32, linux-x86_64, linux-arm_32, mac-x86_64]. -->
                <cmake.classifier>mac-x86_64</cmake.classifier>

                <install.dir>/opt/parachute</install.dir>
                <binary.suffix></binary.suffix>
                <assembly.name>macosx-distribution</assembly.name>
            </properties>
            <build>
            </build>
        </profile>
        <profile>
            <id>windows</id>
            <activation>
                <os>
                    <family>windows</family>
                </os>
            </activation>
            <properties>
                <!-- The CMake maven plugin understands cmake.root.dir -->
                <cmake.root.dir>C:/Program Files/CMake</cmake.root.dir>

                <!-- These are two of my properties I pass in to the CMake plugin, they're not known by the plugin innately -->
                <!-- One of the generators defined at https://cmake.org/cmake/help/v3.7/manual/cmake-generators.7.html -->
                <cmake.generator>NMake Makefiles</cmake.generator>
                <!-- The classifier of the current platform. One of [windows-x86_32, windows-x86_64, linux-x86_32, linux-x86_64, linux-arm_32, mac-x86_64]. -->
                <cmake.classifier>windows-x86_64</cmake.classifier>

                <install.dir>C:/parachute</install.dir>
                <binary.suffix>.exe</binary.suffix>
                <assembly.name>windows-distribution</assembly.name>
            </properties>
            <build>
            </build>
        </profile>

        <profile>
            <id>local-install</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.8</version>
                        <executions>
                            <execution>
                                <id>copy-scripts-and-config</id>
                                <phase>prepare-package</phase>
                                <configuration>
                                    <target>
                                        <mkdir dir="${install.dir}"/>
                                        <mkdir dir="${install.dir}/bin"/>

                                        <copy file="${cmake.binary.dir}/Emulator/temulate${binary.suffix}"
                                              todir="${install.dir}/bin"/>
                                        <chmod file="${install.dir}/bin/temulate${binary.suffix}" perm="755" />

                                        <copy file="${cmake.binary.dir}/NodeServer/server/nodeserver${binary.suffix}"
                                              todir="${install.dir}/bin"/>
                                        <chmod file="${install.dir}/bin/nodeserver${binary.suffix}" perm="755" />
                                    </target>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>deploy</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                        <version>3.0.0</version>
                        <executions>
                            <execution>
                                <id>attach-artifacts</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>attach-artifact</goal>
                                </goals>
                                <configuration>
                                    <artifacts>
                                        <artifact>
                                            <file>${project.build.directory}/${project.artifactId}-${project.version}-centos-7-linux-x86_64.tar.gz</file>
                                            <type>tar.gz</type>
                                            <classifier>centos-7-linux-x86_64</classifier>
                                        </artifact>
                                        <artifact>
                                            <file>${project.build.directory}/${project.artifactId}-${project.version}-mac-x86_64.tar.gz</file>
                                            <type>tar.gz</type>
                                            <classifier>mac-x86_64</classifier>
                                        </artifact>
                                        <artifact>
                                            <file>${project.build.directory}/${project.artifactId}-${project.version}-raspbian-9-linux-arm_32.tar.gz</file>
                                            <type>tar.gz</type>
                                            <classifier>raspbian-9-linux-arm_32</classifier>
                                        </artifact>
                                        <artifact>
                                            <file>${project.build.directory}/${project.artifactId}-${project.version}-ubuntu-16.04-linux-x86_64.tar.gz</file>
                                            <type>tar.gz</type>
                                            <classifier>ubuntu-16.04-linux-x86_64</classifier>
                                        </artifact>
                                        <artifact>
                                            <file>${project.build.directory}/${project.artifactId}-${project.version}-ubuntu-18.04-linux-x86_64.tar.gz</file>
                                            <type>tar.gz</type>
                                            <classifier>ubuntu-18.04-linux-x86_64</classifier>
                                        </artifact>
                                        <artifact>
                                            <file>${project.build.directory}/${project.artifactId}-${project.version}-windows-x86_64.zip</file>
                                            <type>zip</type>
                                            <classifier>windows-x86_64</classifier>
                                        </artifact>
                                    </artifacts>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>1.6</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                                <configuration>
                                    <executable>gpg2</executable>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.sonatype.plugins</groupId>
                        <artifactId>nexus-staging-maven-plugin</artifactId>
                        <version>1.6.8</version>
                        <extensions>true</extensions>
                        <configuration>
                            <serverId>sonatype-nexus-staging</serverId>
                            <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <build>
        <extensions>
            <extension>
                <groupId>kr.motd.maven</groupId>
                <artifactId>os-maven-plugin</artifactId>
                <version>1.6.1</version>
            </extension>
        </extensions>
    </build>
</project>
