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

    <artifactId>catboost-spark_3.3_2.13</artifactId>
    <packaging>jar</packaging>
    <name>CatBoost for Apache Spark</name>
    <description>JVM module to use CatBoost on Apache Spark</description>

    <parent>
        <groupId>ai.catboost</groupId>
        <artifactId>catboost-spark-aggregate_2.13</artifactId>
        <version>1.2</version>
        <relativePath>..</relativePath>
    </parent>

    <properties>
        <spark.compat.version>3.3</spark.compat.version>
        <spark.version>3.3.0</spark.version>
        <hadoop.version>3.3.2</hadoop.version>
        <global_project_root>${project.basedir}/../../..</global_project_root>
        <catboost_root>${global_project_root}/../..</catboost_root>
        <core_project_root>${global_project_root}/core</core_project_root>
        <src.root>${core_project_root}/src</src.root>
        <buildNative.extraArgs></buildNative.extraArgs>
    </properties>

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

    <build>
        <sourceDirectory>${src.root}/main/scala</sourceDirectory>
        <testSourceDirectory>${src.root}/test/scala</testSourceDirectory>
        <plugins>
            <plugin>
              <groupId>org.codehaus.mojo</groupId>
              <artifactId>build-helper-maven-plugin</artifactId>
              <version>1.5</version>
              <executions>
                <execution>
                  <id>add-source</id>
                  <phase>generate-sources</phase>
                  <goals>
                    <goal>add-source</goal>
                  </goals>
                  <configuration>
                    <sources>
                      <source>${src.root}/spark_3_x/scala</source>
                    </sources>
                  </configuration>
                </execution>
              </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.6.0</version>
                <executions>
                    <execution>
                        <id>Prepare sources for docs</id>
                        <phase>process-sources</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>python</executable>
                            <arguments>
                                <argument>${core_project_root}/prepare_sources_for_docs.py</argument>
                                <argument>--dst-dir=${project.build.directory}/src_for_doc</argument>
                                <argument>--src-jar=${core_project_root}/target/catboost4j-spark-impl-sources.jar</argument>
                            </arguments>
                            <workingDirectory>${user.dir}</workingDirectory>
                        </configuration>
                    </execution>
                    <execution>
                        <id>Generate PySpark wrapper code</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>java</executable>
                            <classpathScope>compile</classpathScope>
                            <arguments>
                                <argument>-classpath</argument>
                                <!-- automatically creates the classpath using all project dependencies,
                                     also adding the project build directory -->
                                <classpath/>
                                <argument>ai.catboost.spark.impl.pyspark_wrapper_generator.Generator</argument>
                                <argument>${project.version}</argument>
                                <argument>${project.build.directory}/classes/catboost_spark</argument>
                                <argument>${spark.compat.version}</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>4.4.0</version>
                <executions>
                    <execution>
                        <id>scala-compile-first</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>scala-test-compile</id>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>attach-javadocs</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>doc-jar</goal>
                        </goals>
                        <configuration>
                            <sourceDir>${project.build.directory}/src_for_doc</sourceDir>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                   
<args>
    <arg>-Ymacro-annotations</arg>
</args>

                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>utf-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.7.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
                <configuration>
                    <redirectTestOutputToFile>true</redirectTestOutputToFile>
                    <trimStackTrace>false</trimStackTrace>
                    <forkCount>1C</forkCount>
                    <reuseForks>false</reuseForks>
                    <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
                    <systemPropertyVariables>
                        <catboost.test.data.path>${catboost_root}/pytest/data</catboost.test.data.path>
                        <canonical.data.path>${src.root}/test/resources/canondata</canonical.data.path>
                    </systemPropertyVariables>
                    <workingDirectory>FORK_DIRECTORY_${surefire.forkNumber}</workingDirectory>
                </configuration>
            </plugin>
        </plugins>

        <resources>
           <resource>
               <directory>${src.root}/main/resources</directory>
           </resource>
        </resources>
        <testResources>
           <testResource>
               <directory>${src.root}/main/resources</directory>
           </testResource>
        </testResources>
    </build>

    <reporting>
      <plugins>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
        <plugin>
          <groupId>net.alchim31.maven</groupId>
          <artifactId>scala-maven-plugin</artifactId>
          <version>4.4.0</version>
          <configuration>
            <jvmArgs>
              <jvmArg>-Xms64m</jvmArg>
              <jvmArg>-Xmx1024m</jvmArg>
            </jvmArgs>
          </configuration>
        </plugin>
      </plugins>
    </reporting>

    <dependencies>
        <dependency>
            <groupId>org.scala-lang.modules</groupId>
            <artifactId>scala-collection-compat_${scala.compat.version}</artifactId>
            <version>2.6.0</version>
        </dependency>

        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>29.0-jre</version>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.7</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.11</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-text</artifactId>
            <version>1.10.0</version>
        </dependency>

        <dependency>
            <groupId>org.json4s</groupId>
            <artifactId>json4s-jackson_${scala.compat.version}</artifactId>
            <version>3.7.0-M11</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        <version>2.13.1</version>
        </dependency>
            <dependency>
            <groupId>com.fasterxml.jackson.module</groupId>
            <artifactId>jackson-module-scala_${scala.compat.version}</artifactId>
            <version>2.13.1</version>
        </dependency>

        <dependency>
            <groupId>io.github.classgraph</groupId>
            <artifactId>classgraph</artifactId>
            <version>4.8.98</version>
        </dependency>

        <!--
          Default Spark 3.2's 4.1.68.Final dependency is broken because of https://github.com/netty/netty/issues/11657
          so upgrade to 4.1.72.Final as in Spark itself: https://github.com/apache/spark/pull/34881
        -->
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-all</artifactId>
            <version>4.1.74.Final</version>
            <scope>provided</scope>
            <exclusions>
                <exclusion>
                  <groupId>io.netty</groupId>
                  <artifactId>netty-codec-dns</artifactId>
                </exclusion>
                <exclusion>
                  <groupId>io.netty</groupId>
                  <artifactId>netty-codec-haproxy</artifactId>
                </exclusion>
                <exclusion>
                  <groupId>io.netty</groupId>
                  <artifactId>netty-codec-http</artifactId>
                </exclusion>
                <exclusion>
                  <groupId>io.netty</groupId>
                  <artifactId>netty-codec-http2</artifactId>
                </exclusion>
                <exclusion>
                  <groupId>io.netty</groupId>
                  <artifactId>netty-codec-memcache</artifactId>
                </exclusion>
                <exclusion>
                  <groupId>io.netty</groupId>
                  <artifactId>netty-codec-mqtt</artifactId>
                </exclusion>
                <exclusion>
                  <groupId>io.netty</groupId>
                  <artifactId>netty-codec-redis</artifactId>
                </exclusion>
                <exclusion>
                  <groupId>io.netty</groupId>
                  <artifactId>netty-codec-smtp</artifactId>
                </exclusion>
                <exclusion>
                  <groupId>io.netty</groupId>
                  <artifactId>netty-codec-socks</artifactId>
                </exclusion>
                <exclusion>
                  <groupId>io.netty</groupId>
                  <artifactId>netty-codec-stomp</artifactId>
                </exclusion>
                <exclusion>
                  <groupId>io.netty</groupId>
                  <artifactId>netty-codec-xml</artifactId>
                </exclusion>
                <exclusion>
                  <groupId>io.netty</groupId>
                  <artifactId>netty-handler-proxy</artifactId>
                </exclusion>
                <exclusion>
                  <groupId>io.netty</groupId>
                  <artifactId>netty-resolver-dns</artifactId>
                </exclusion>
                <exclusion>
                  <groupId>io.netty</groupId>
                  <artifactId>netty-resolver-dns-classes-macos</artifactId>
                </exclusion>
                <exclusion>
                  <groupId>io.netty</groupId>
                  <artifactId>netty-resolver-dns-native-macos</artifactId>
                </exclusion>
                <exclusion>
                  <groupId>io.netty</groupId>
                  <artifactId>netty-transport-rxtx</artifactId>
                </exclusion>
                <exclusion>
                  <groupId>io.netty</groupId>
                  <artifactId>netty-transport-sctp</artifactId>
                </exclusion>
                <exclusion>
                  <groupId>io.netty</groupId>
                  <artifactId>netty-transport-udt</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- newer version than in dependencies to support Apple Darwin arm64 architecture -->
        <dependency>
            <groupId>org.xerial.snappy</groupId>
            <artifactId>snappy-java</artifactId>
            <version>1.1.8.4</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-mapreduce-client-core</artifactId>
            <version>${hadoop.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-common</artifactId>
            <version>${hadoop.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_${scala.compat.version}</artifactId>
            <version>${spark.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-sql_${scala.compat.version}</artifactId>
            <version>${spark.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-mllib_${scala.compat.version}</artifactId>
            <version>${spark.version}</version>
            <scope>provided</scope>
        </dependency>


        <dependency>
            <groupId>ai.catboost</groupId>
            <artifactId>catboost-common</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>ai.catboost</groupId>
            <artifactId>catboost-spark-macros_${scala.compat.version}</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.scalatest</groupId>
            <artifactId>scalatest_${scala.compat.version}</artifactId>
            <version>3.2.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-math3</artifactId>
            <version>3.6.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <profiles>
      <profile>
         <id>build-native</id>
         <activation>
           <property>
             <name>!prebuilt.native.resources.dir</name>
           </property>
         </activation>
         <build>
           <plugins>
              <plugin>
                  <groupId>org.codehaus.mojo</groupId>
                  <artifactId>exec-maven-plugin</artifactId>
                  <version>1.6.0</version>
                  <executions>
                      <execution>
                          <id>Build dynamic library with JNI</id>
                          <phase>generate-sources</phase>
                          <goals>
                              <goal>exec</goal>
                          </goals>
                          <configuration>
                              <executable>python</executable>
                              <commandlineArgs>
                                ${catboost_root}/jvm-packages/tools/build_native_for_maven.py
                                --build-output-root-dir=${project.build.directory}/native
                                --base-dir=${core_project_root}
                                --lib-name=catboost4j-spark-impl
                                ${buildNative.extraArgs}
                              </commandlineArgs>
                              <workingDirectory>${user.dir}</workingDirectory>
                          </configuration>
                      </execution>
                  </executions>
              </plugin>
            </plugins>
          </build>
      </profile>
      <profile>
         <id>prebuilt-native</id>
         <activation>
           <property>
             <name>prebuilt.native.resources.dir</name>
           </property>
         </activation>
         <build>
           <plugins>
              <plugin>
                  <groupId>org.codehaus.mojo</groupId>
                  <artifactId>exec-maven-plugin</artifactId>
                  <version>1.6.0</version>
                  <executions>
                      <execution>
                          <id>Copy prebuilt native files</id>
                          <phase>generate-sources</phase>
                          <goals>
                              <goal>exec</goal>
                          </goals>
                          <configuration>
                              <executable>python</executable>
                              <arguments>
                                  <argument>${catboost_root}/jvm-packages/tools/copy_prebuilt_native_files.py</argument>
                                  <argument>--src-resources-dir=${prebuilt.native.resources.dir}</argument>
                                  <argument>--src-sources-jar=${prebuilt.native.sources.jar}</argument>
                                  <argument>--dst-basedir=${core_project_root}</argument>
                              </arguments>
                              <workingDirectory>${user.dir}</workingDirectory>
                          </configuration>
                      </execution>
                  </executions>
              </plugin>
            </plugins>
          </build>
      </profile>
      <profile>
        <id>javadoc</id>
        <build>
          <plugins>
            <plugin>
              <groupId>net.alchim31.maven</groupId>
              <artifactId>scala-maven-plugin</artifactId>
              <version>4.4.0</version>
              <executions>
                <execution>
                  <id>doc</id>
                  <phase>generate-sources</phase>
                  <goals>
                    <goal>compile</goal>
                  </goals>
                </execution>
              </executions>
              <configuration>
                <args>
                  <arg>-P:genjavadoc:out=${project.build.directory}/genjavadoc</arg>
                </args>
                <compilerPlugins>
                  <compilerPlugin>
                    <groupId>com.typesafe.genjavadoc</groupId>
                    <artifactId>genjavadoc-plugin_2.13.5</artifactId>
                    <version>0.18</version>
                  </compilerPlugin>
                  <compilerPlugin>
                    <groupId>org.scalamacros</groupId>
                    <artifactId>paradise_${scala.version}</artifactId>
                    <version>2.1.1</version>
                  </compilerPlugin>
                </compilerPlugins>
                <sourceDir>${project.build.directory}/src_for_doc</sourceDir>
              </configuration>
            </plugin>
            <plugin>
              <groupId>org.codehaus.mojo</groupId>
              <artifactId>build-helper-maven-plugin</artifactId>
              <executions>
                <execution>
                  <phase>generate-sources</phase>
                  <goals>
                    <goal>add-source</goal>
                  </goals>
                  <configuration>
                    <sources>
                      <source>${project.build.directory}/genjavadoc</source>
                      <source>${project.build.directory}/src_for_doc</source>
                    </sources>
                  </configuration>
                </execution>
              </executions>
            </plugin>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-javadoc-plugin</artifactId>
              <version>2.9</version>
              <configuration>
                <minmemory>64m</minmemory>
                <maxmemory>2g</maxmemory>
                <outputDirectory>${project.build.directory}</outputDirectory>
                <detectLinks>true</detectLinks>
              </configuration>
            </plugin>
          </plugins>
        </build>
      </profile>
      <profile>
        <id>pythondoc</id>
        <build>
          <plugins>
            <plugin>
              <groupId>org.codehaus.mojo</groupId>
              <artifactId>exec-maven-plugin</artifactId>
              <version>1.6.0</version>
              <executions>
                  <execution>
                      <id>Generate Python documentation</id>
                      <phase>process-classes</phase>
                      <goals>
                          <goal>exec</goal>
                      </goals>
                      <configuration>
                          <environmentVariables>
                            <CATBOOST_SPARK_MODULE_PATH>${project.build.directory}/classes</CATBOOST_SPARK_MODULE_PATH>
                          </environmentVariables>
                          <executable>python3</executable>
                          <arguments>
                              <argument>-m</argument>
                              <argument>sphinx</argument>
                              <argument>${core_project_root}/docs/python/source</argument>
                              <argument>${project.build.directory}/site/pythondocs</argument>
                          </arguments>
                          <workingDirectory>${user.dir}</workingDirectory>
                      </configuration>
                  </execution>
              </executions>
            </plugin>
          </plugins>
        </build>
      </profile>
    </profiles>
</project>
