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

    <!-- MAVEN ARTIFACT INFORMATION -->
    <artifactId>pi4j-core</artifactId>
    <name>Pi4J :: LIBRARY  :: Java Library (CORE)</name>
    <description>Pi4J Java API &amp; Runtime Library</description>
    <packaging>jar</packaging>
    <parent>
        <groupId>com.pi4j</groupId>
        <artifactId>pi4j-parent</artifactId>
        <version>2.0</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <!-- PROJECT DEPENDENCIES -->
    <dependencies>
    </dependencies>

    <!-- BUILD INSTRUCTIONS -->
    <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>
                <artifactId>maven-compiler-plugin</artifactId>
            </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>

            <!-- OSGi BUNDLE -->
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                        <Bundle-Version>${project.version}</Bundle-Version>
                        <Export-Package>
                            com.pi4j.*,
                        </Export-Package>
                        <Private-Package>
                        </Private-Package>
                    </instructions>
                </configuration>
                <executions>
                    <execution>
                        <id>bundle-manifest</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>manifest</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!-- INCLUDE OSGi MANIFEST IN JAR -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>test-jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!-- 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>
                            <outputDirectory>${project.build.directory}/dependencies</outputDirectory>
                            <excludeGroupIds>com.pi4j</excludeGroupIds>
                            <includeScope>runtime</includeScope>
                            <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 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>

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