<?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>lakesoul-parent</artifactId>
        <groupId>com.dmetasoul</groupId>
        <version>2.2.0</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>lakesoul-io-java</artifactId>
    <version>2.2.0</version>
    <packaging>jar</packaging>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <arrow.version>11.0.0</arrow.version>
        <scala.version>2.12.10</scala.version>
        <scala.binary.version>2.12</scala.binary.version>
        <scalatest.version>3.1.0</scalatest.version>
    </properties>


    <dependencies>
        <dependency>
            <groupId>org.apache.arrow</groupId>
            <artifactId>arrow-vector</artifactId>
            <version>${arrow.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.arrow</groupId>
            <artifactId>arrow-memory-netty</artifactId>
            <version>${arrow.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.arrow</groupId>
            <artifactId>arrow-memory-core</artifactId>
            <version>${arrow.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.arrow</groupId>
            <artifactId>arrow-c-data</artifactId>
            <version>${arrow.version}</version>
        </dependency>

        <!-- scala deps -->
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${scala.version}</version>
            <scope>${local.scope}</scope>
        </dependency>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-compiler</artifactId>
            <version>${scala.version}</version>
            <scope>${local.scope}</scope>
        </dependency>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-reflect</artifactId>
            <version>${scala.version}</version>
            <scope>${local.scope}</scope>
        </dependency>

        <!--      test deps        -->
        <dependency>
            <groupId>org.scalatest</groupId>
            <artifactId>scalatest_${scala.binary.version}</artifactId>
            <version>${scalatest.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
            <scope>test</scope>
        </dependency>

        <!--        jnr-ffi deps-->
        <dependency>
            <groupId>com.github.jnr</groupId>
            <artifactId>jnr-ffi</artifactId>
            <version>2.2.13</version>
            <exclusions>
                <exclusion>
                    <groupId>com.github.jnr</groupId>
                    <artifactId>jffi</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- https://github.com/jnr/jffi/issues/138 -->
        <!-- upgrade jffi version to make it work on CentOS 7 -->
        <dependency>
            <groupId>com.github.jnr</groupId>
            <artifactId>jffi</artifactId>
            <version>1.3.11</version>
        </dependency>
        <dependency>
            <groupId>com.github.jnr</groupId>
            <artifactId>jffi</artifactId>
            <version>1.3.11</version>
            <scope>runtime</scope>
            <classifier>native</classifier>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <id>native-dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <resources>
                    <resource>
                        <directory>${basedir}/../target/release/</directory>
                        <includes>
                            <include>*.dylib</include>
                            <include>*.so</include>
                            <include>*.dll</include>
                        </includes>
                        <excludes>
                            <exclude>deps</exclude>
                            <exclude>.fingerprint</exclude>
                            <exclude>build</exclude>
                            <exclude>examples</exclude>
                            <exclude>*.d</exclude>
                        </excludes>
                    </resource>
                </resources>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>3.1.0</version>
                        <executions>
                            <execution>
                                <id>compile-native</id>
                                <phase>generate-resources</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>cargo</executable>
                                    <commandlineArgs>+nightly build --release --all-features --package lakesoul-io-c</commandlineArgs>
                                    <workingDirectory>${basedir}/../</workingDirectory>
                                </configuration>
                            </execution>
                            <execution>
                                <id>clean-native</id>
                                <phase>clean</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>cargo</executable>
                                    <commandlineArgs>
                                        clean
                                    </commandlineArgs>
                                    <workingDirectory>${basedir}/../</workingDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>release-linux-x86-64</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <build>
                <resources>
                    <resource>
                        <directory>${basedir}/../target/x86_64-unknown-linux-gnu/release/</directory>
                        <includes>
                            <include>*.so</include>
                        </includes>
                        <excludes>
                            <exclude>deps</exclude>
                            <exclude>.fingerprint</exclude>
                            <exclude>build</exclude>
                            <exclude>examples</exclude>
                            <exclude>*.d</exclude>
                        </excludes>
                    </resource>
                </resources>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>3.1.0</version>
                        <executions>
                            <execution>
                                <id>compile-native</id>
                                <phase>generate-resources</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>cross</executable>
                                    <commandlineArgs>+nightly build --target x86_64-unknown-linux-gnu --release --features lakesoul-io/hdfs --package lakesoul-io-c</commandlineArgs>
                                    <workingDirectory>${basedir}/../</workingDirectory>
                                </configuration>
                            </execution>
                            <execution>
                                <id>clean-native</id>
                                <phase>clean</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>cargo</executable>
                                    <commandlineArgs>
                                        clean
                                    </commandlineArgs>
                                    <workingDirectory>${basedir}/../</workingDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <build>
        <extensions>
            <extension>
                <groupId>kr.motd.maven</groupId>
                <artifactId>os-maven-plugin</artifactId>
                <version>1.7.0</version>
            </extension>
        </extensions>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.10.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M6</version>
                <configuration>
                    <argLine>--add-opens=java.base/java.nio=ALL-UNNAMED</argLine>
                </configuration>
            </plugin>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>4.6.3</version>
                <executions>
                    <execution>
                        <id>scala-compile-first</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>scala-test-compile</id>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <compileOrder>Mixed</compileOrder>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>