<?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>
        <artifactId>pi4j-parent</artifactId>
        <groupId>com.pi4j</groupId>
        <version>2.0</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>pi4j-test</artifactId>
    <name>Pi4J :: TESTING  :: Unit/Integration Tests</name>
    <description>Pi4J Unit and Integration Tests</description>

    <dependencies>
        <dependency>
            <groupId>com.pi4j</groupId>
            <artifactId>pi4j-core</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
        </dependency>

        <!-- include Pi4J Plugins (Platforms and I/O Providers) -->
        <dependency>
            <groupId>com.pi4j</groupId>
            <artifactId>pi4j-plugin-mock</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>${project.build.directory}</directory>
                <filtering>false</filtering>
                <includes>
                    <include>LICENSE.txt</include>
                    <include>NOTICE.txt</include>
                    <include>README.md</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/**</include>
                </includes>
            </resource>
        </resources>

        <plugins>
            <!-- JAVA COMPILER -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>

            <!-- MAVEN RUN JUNIT5 TESTS -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <argLine>
                        --illegal-access=permit
                        --add-opens com.pi4j.test/com.pi4j.test=com.pi4j,ALL-UNNAMED
                        --add-opens com.pi4j.test/com.pi4j.test.context=com.pi4j,ALL-UNNAMED
                        --add-opens com.pi4j.test/com.pi4j.test.io.i2c=com.pi4j,ALL-UNNAMED
                        --add-opens com.pi4j.test/com.pi4j.test.io.serial=com.pi4j,ALL-UNNAMED
                        --add-opens com.pi4j.test/com.pi4j.test.platform=com.pi4j,ALL-UNNAMED
                        --add-opens com.pi4j.test/com.pi4j.test.provider=com.pi4j,ALL-UNNAMED
                        --add-opens com.pi4j.test/com.pi4j.test.registry=com.pi4j,ALL-UNNAMED
                    </argLine>
                </configuration>
            </plugin>

            <!-- INCLUDE SOURCE JAR -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
            </plugin>

            <!-- INCLUDE JAVADOC JAR -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
            </plugin>

            <!-- DEFAULT JAR EXECUTABLE CLASS -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>${exec-maven-plugin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>com.pi4j.test.Main</mainClass>
                    <arguments>
                    </arguments>
                </configuration>
            </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 to the Raspberry Pi -->
                                        <scp file="${project.build.directory}/${project.build.finalName}.jar"
                                             todir="${pi4j.dev.user}:${pi4j.dev.password}@${pi4j.dev.host}:${pi4j.dev.directory}"
                                             port="${pi4j.dev.port}" trust="true" verbose="false" failonerror="true">
                                        </scp>
                                    </then>
                                </if>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>


</project>
