<?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">
    <parent>
        <groupId>com.pi4j</groupId>
        <artifactId>pi4j-plugin</artifactId>
        <version>3.0.1</version>
        <relativePath>../pi4j-plugin/pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <!-- MAVEN ARTIFACT INFORMATION -->
    <artifactId>pi4j-plugin-linuxfs</artifactId>
    <name>Pi4J :: PLUGIN :: LinuxFS I/O Providers</name>
    <description>Pi4J Library Plugin for Linux File System I/O Providers</description>
    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>com.jcraft</groupId>
            <artifactId>jsch</artifactId>
            <version>${jsch.version}</version>
        </dependency>
        <dependency>
            <groupId>com.pi4j</groupId>
            <artifactId>pi4j-library-linuxfs</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>${slf4j.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>net.java.dev.jna</groupId>
            <artifactId>jna</artifactId>
            <version>${jna.version}</version>
        </dependency>
    </dependencies>

    <!-- STANDARD BUILD INSTRUCTIONS -->
    <build>
        <plugins>
            <!-- DOWNLOAD RUNTIME DEPENDENCIES -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>process-sources</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <includeScope>runtime</includeScope>
                            <excludeGroupIds>com.pi4j</excludeGroupIds>
                            <outputDirectory>${project.build.directory}/dependencies</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- OPTIONALLY DEPLOY THE FINAL JAR TO THE RASPBERRY PI -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>

                    <!-- copy the compiled JAR file to the Raspberry Pi platform platform -->
                    <execution>
                        <id>transfer-compiled-pi4j-jar</id>
                        <phase>install</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <taskdef resource="net/sf/antcontrib/antcontrib.properties"
                                         classpathref="maven.plugin.classpath"/>
                                <if>
                                    <equals arg1="${pi4j.dev.transfer}" arg2="true"/>
                                    <then>
                                        <!-- ensure the target directory exists on the Raspberry Pi -->
                                        <sshexec host="${pi4j.dev.host}" port="${pi4j.dev.port}"
                                                 username="${pi4j.dev.user}"
                                                 password="${pi4j.dev.password}" trust="true" failonerror="false"
                                                 verbose="false" command="mkdir --parents ${pi4j.dev.directory}"/>

                                        <!-- copy the JAR file(s) to the Raspberry Pi -->
                                        <scp
                                            todir="${pi4j.dev.user}:${pi4j.dev.password}@${pi4j.dev.host}:${pi4j.dev.directory}"
                                            port="${pi4j.dev.port}" trust="true" verbose="false" failonerror="true">
                                            <fileset dir="${project.build.directory}">
                                                <include name="${project.build.finalName}.jar"/>
                                            </fileset>
                                            <fileset dir="${project.build.directory}/dependencies">
                                                <include name="*.jar"/>
                                            </fileset>
                                        </scp>
                                    </then>
                                </if>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>
