<?xml version="1.0" encoding="UTF-8"?>
<!--
  Copyright (c) 2020-2023, NVIDIA CORPORATION.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<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>

    <parent>
        <groupId>com.nvidia</groupId>
        <artifactId>rapids-4-spark-parent</artifactId>
        <version>23.02.0</version>
    </parent>
    <artifactId>rapids-4-spark_2.12</artifactId>
    <name>RAPIDS Accelerator for Apache Spark Distribution</name>
    <description>Creates the distribution package of the RAPIDS plugin for Apache Spark</description>
    <version>23.02.0</version>
    <dependencies>
        
    </dependencies>

    <properties>
        <target.classifier/>
        <dist.jar.name>${project.build.directory}/${project.build.finalName}-${cuda.version}.jar</dist.jar.name>
    </properties>
    <profiles>
        <profile>
            <id>noSnapshotsWithDatabricks</id>
            <properties>
                <included_buildvers>
                    ${noSnapshot.buildvers},
                    ${databricks.buildvers}
                </included_buildvers>
            </properties>
        </profile>
        <profile>
            <id>noSnapshots</id>
            <properties>
                <included_buildvers>
                    ${noSnapshot.buildvers}
                </included_buildvers>
            </properties>
        </profile>
        <profile>
            <id>premergeUT1</id>
            <properties>
                <included_buildvers>
                    ${premergeUT1.buildvers}
                </included_buildvers>
            </properties>
        </profile>
        <profile>
            <id>premergeUT2</id>
            <properties>
                <included_buildvers>
                    ${premergeUT2.buildvers}
                </included_buildvers>
            </properties>
        </profile>
        <profile>
            <id>premergeUTF8</id>
            <properties>
                <included_buildvers>
                    ${premergeUTF8.buildvers}
                </included_buildvers>
            </properties>
        </profile>
        <profile>
            <id>jdk11</id>
            <properties>
                <included_buildvers>
                    ${jdk11.buildvers}
                </included_buildvers>
            </properties>
        </profile>
        <profile>
            <id>databricks</id>
            <properties>
                <included_buildvers>
                    ${databricks.buildvers}
                </included_buildvers>
            </properties>
        </profile>
        <profile>
            <!--
            https://spark.apache.org/versioning-policy.html
            Spark's semantic versioning [MAJOR].[FEATURE].[MAINTENANCE]

            The plugin support begins with MAJOR=3

            Most problems with the shim support occur when we cross into the next
            FEATURE version and when we deal with distributions

            Maintain a representative sample one of each:
                - 3.x upstream versions
                - a downstream distro
                - a snapshot
            for testing while minimizing the build time
            -->
            <id>minimumFeatureVersionMix</id>
            <properties>
                <included_buildvers>
                    312,
                    320,
                    321cdh,
                    330,
                    330cdh
                </included_buildvers>
            </properties>
        </profile>
        <profile>
            <id>snapshots</id>
            <properties>
                <included_buildvers>
                    ${noSnapshot.buildvers},
                    ${snapshot.buildvers}
                </included_buildvers>
            </properties>
        </profile>
        <profile>
            <id>snapshotOnly</id>
            <properties>
                <included_buildvers>
                    ${snapshot.buildvers}
                </included_buildvers>
            </properties>
        </profile>
        <profile>
            <id>snapshotsWithDatabricks</id>
            <properties>
                <included_buildvers>
                    ${noSnapshot.buildvers},
                    ${snapshot.buildvers},
                    ${databricks.buildvers}
                </included_buildvers>
            </properties>
        </profile>
        <profile>
            <id>release321cdh</id>
            <activation>
                <property>
                    <name>buildver</name>
                    <value>321cdh</value>
                </property>
            </activation>
            <properties>
                <included_buildvers>${buildver}</included_buildvers>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.apache.spark</groupId>
                    <artifactId>spark-sql_${scala.binary.version}</artifactId>
                    <version>${spark321cdh.version}</version>
                    <exclusions>
                        <exclusion>
                            <groupId>org.apache.arrow</groupId>
                            <artifactId>arrow-vector</artifactId>
                        </exclusion>
                    </exclusions>
                    <scope>provided</scope>
                </dependency>
                <dependency>
                    <groupId>org.apache.spark</groupId>
                    <artifactId>spark-hive_${scala.binary.version}</artifactId>
                    <version>${spark321cdh.version}</version>
                    <exclusions>
                        <!-- spark-core tries to pull a curator-recipes version we don't want -->
                        <exclusion>
                            <groupId>org.apache.spark</groupId>
                            <artifactId>spark-core_${scala.binary.version}</artifactId>
                        </exclusion>
                        <exclusion>
                            <groupId>org.apache.arrow</groupId>
                            <artifactId>arrow-vector</artifactId>
                        </exclusion>
                    </exclusions>
                    <scope>provided</scope>
                </dependency>
                <dependency>
                    <groupId>org.apache.arrow</groupId>
                    <artifactId>arrow-vector</artifactId>
                    <version>${arrow.cdh.version}</version>
                    <scope>provided</scope>
                    <exclusions>
                        <exclusion>
                            <groupId>com.fasterxml.jackson.core</groupId>
                            <artifactId>jackson-core</artifactId>
                        </exclusion>
                        <exclusion>
                            <groupId>com.fasterxml.jackson.core</groupId>
                            <artifactId>jackson-annotations</artifactId>
                        </exclusion>
                        <exclusion>
                            <groupId>io.netty</groupId>
                            <artifactId>netty-common</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
            </dependencies>
             <pluginRepositories>
                <pluginRepository>
                    <id>cloudera-repo</id>
                    <url>https://repository.cloudera.com/artifactory/cloudera-repos/</url>
                </pluginRepository>
             </pluginRepositories>
        </profile>
        <profile>
            <id>release330cdh</id>
            <activation>
                <property>
                    <name>buildver</name>
                    <value>330cdh</value>
                </property>
            </activation>
            <properties>
                 <included_buildvers>${buildver}</included_buildvers>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.apache.spark</groupId>
                    <artifactId>spark-sql_${scala.binary.version}</artifactId>
                    <version>${spark330cdh.version}</version>
                    <exclusions>
                        <exclusion>
                            <groupId>org.apache.arrow</groupId>
                            <artifactId>arrow-vector</artifactId>
                        </exclusion>
                    </exclusions>
                    <scope>provided</scope>
                </dependency>
                <dependency>
                    <groupId>org.apache.spark</groupId>
                    <artifactId>spark-hive_${scala.binary.version}</artifactId>
                    <version>${spark330cdh.version}</version>
                    <exclusions>
                        <!-- spark-core tries to pull a curator-recipes version we don't want -->
                        <exclusion>
                            <groupId>org.apache.spark</groupId>
                            <artifactId>spark-core_${scala.binary.version}</artifactId>
                        </exclusion>
                        <exclusion>
                            <groupId>org.apache.arrow</groupId>
                            <artifactId>arrow-vector</artifactId>
                        </exclusion>
                    </exclusions>
                    <scope>provided</scope>
                </dependency>
                <dependency>
                    <groupId>org.apache.arrow</groupId>
                    <artifactId>arrow-vector</artifactId>
                    <version>${arrow.cdh.version}</version>
                    <scope>provided</scope>
                    <exclusions>
                        <exclusion>
                            <groupId>com.fasterxml.jackson.core</groupId>
                            <artifactId>jackson-core</artifactId>
                        </exclusion>
                        <exclusion>
                            <groupId>com.fasterxml.jackson.core</groupId>
                            <artifactId>jackson-annotations</artifactId>
                        </exclusion>
                        <exclusion>
                            <groupId>io.netty</groupId>
                            <artifactId>netty-common</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
            </dependencies>
            <pluginRepositories>
                <pluginRepository>
                    <id>cloudera-repo</id>
                    <url>https://repository.cloudera.com/artifactory/cloudera-repos/</url>
                </pluginRepository>
            </pluginRepositories>
        </profile>
        <profile>
            <id>individual</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <included_buildvers>${buildver}</included_buildvers>
            </properties>
        </profile>
        <profile>
            <id>pre-merge</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>if_modified_files</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>bash</executable>
                                     <commandlineArgs>-c 'export MODIFIED=$(git status --porcelain | grep "^ M"); [[ -z $MODIFIED ]] &amp;&amp; exit 0 || { echo -e "found modified files during mvn verify:\n$MODIFIED"; exit 1;}'</commandlineArgs>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    <build>
        <resources>
          <resource>
            <directory>${project.build.directory}/extra-resources</directory>
          </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <id>default-resources</id>
                        <phase>process-resources</phase>
                        <configuration>
                            <outputDirectory>${project.build.directory}/parallel-world</outputDirectory>>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <classifier>${cuda.version}</classifier>
                </configuration>
                <executions>
                    <execution>
                        <id>default-jar</id>
                        <phase>none</phase>
                    </execution>
                    <execution>
                        <id>create-parallel-worlds-jar</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <configuration>
                            <archive><compress>${dist.jar.compress}</compress></archive>
                            <classesDirectory>${project.build.directory}/parallel-world</classesDirectory>
                            <classifier>${cuda.version}</classifier>
                            <excludes>
                                <!-- get rid of all maven poms from shim builds -->
                                <exclude>META-INF/maven/**</exclude>
                            </excludes>
                        </configuration>
                    </execution>
                    <execution>
                        <id>default-test-jar</id>
                        <phase>none</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <!-- ensure a phase preceding create-parallel-world and copy-current -->
                        <phase>initialize</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <id>clean-any-prior-output</id>
                        <configuration>
                            <target>
                                <delete dir="${project.build.directory}/parallel-world"
                                        includeemptydirs="true"/>
                                <delete>
                                    <fileset dir="${project.build.directory}" includes="*.jar"/>
                                </delete>
                                <delete dir="${project.build.directory}/deps" includeemptydirs="true"/>
                                <mkdir dir="${project.build.directory}/deps"/>
                            </target>
                        </configuration>
                    </execution>
                    <execution>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <id>create-parallel-world</id>
                        <configuration>
                            <target>
                                <property name="project.basedir" value="${project.basedir}"/>
                                <property name="project.build.directory" value="${project.build.directory}"/>
                                <property name="project.version" value="${project.version}"/>
                                <property name="scala.binary.version" value="${scala.binary.version}"/>
                                <property name="included_buildvers" value="${included_buildvers}"/>
                                <ant
                                    antfile="${project.basedir}/maven-antrun/build-parallel-worlds.xml"
                                    target="build-parallel-worlds"
                                />
                            </target>
                        </configuration>
                    </execution>
                    <execution>
                        <phase>verify</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <id>reduce-pom-deps-in-the-jar</id>
                        <configuration>
                            <target>
                                <zip update="true" basedir="${project.build.directory}/extra-resources"
                                    compress="${dist.jar.compress}"
                                    destfile="${dist.jar.name}"/>
                            </target>
                        </configuration>
                    </execution>
                    <execution>
                        <id>update_config_docs</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
                                <ac:if xmlns:ac="antlib:net.sf.antcontrib">
                                    <equals arg1="spark311" arg2="${spark.version.classifier}"/>
                                    <ac:then>
                                        <java classname="com.nvidia.spark.rapids.RapidsConf" failonerror="true">
                                            <arg value="${project.basedir}/../docs/configs.md"/>
                                        </java>
                                        <java classname="com.nvidia.spark.rapids.SupportedOpsDocs" failonerror="true">
                                            <arg value="${project.basedir}/../docs/supported_ops.md"/>
                                        </java>
                                        <java classname="com.nvidia.spark.rapids.SupportedOpsForTools" failonerror="true">
                                            <arg value="${project.basedir}/../tools/generated_files/supportedDataSource.csv"/>
                                        </java>
                                        <java classname="com.nvidia.spark.rapids.SupportedOpsForTools" failonerror="true">
                                            <arg value="${project.basedir}/../tools/generated_files/operatorsScore.csv"/>
                                            <arg value="operatorScore"/>
                                        </java>
                                        <java classname="com.nvidia.spark.rapids.SupportedOpsForTools" failonerror="true">
                                            <arg value="${project.basedir}/../tools/generated_files/supportedExecs.csv"/>
                                            <arg value="execs"/>
                                        </java>
                                        <java classname="com.nvidia.spark.rapids.SupportedOpsForTools" failonerror="true">
                                            <arg value="${project.basedir}/../tools/generated_files/supportedExprs.csv"/>
                                            <arg value="exprs"/>
                                        </java>
                                    </ac:then>
                                </ac:if>
                            </target>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>com.nvidia</groupId>
                        <artifactId>rapids-4-spark-aggregator_${scala.binary.version}</artifactId>
                        <version>${project.version}</version>
                        <classifier>${spark.version.classifier}</classifier>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.spark</groupId>
                        <artifactId>spark-hive_${scala.binary.version}</artifactId>
                        <version>${spark.version}</version>
                        <exclusions>
                            <exclusion>
                                <groupId>org.apache.curator</groupId>
                                <artifactId>curator-recipes</artifactId>
                            </exclusion>
                        </exclusions>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.spark</groupId>
                        <artifactId>spark-avro_${scala.binary.version}</artifactId>
                        <version>${spark.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>org.apache.rat</groupId>
                <artifactId>apache-rat-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>com.nvidia.spark.rapids.SparkShimServiceProvider.*</exclude>
                        <exclude>dependency-reduced-pom*.xml</exclude>
                        <exclude>*.txt</exclude>
                        <exclude>*.md</exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <!-- The dependency scopes of spark-rapids-jni and jucx are `provided` in aggregator submodule,
                 this will skip the dedupe processing in `create-parallel-world`.
                 Unpack spark-rapids-jni and jucx jars to `parallel-world` directory after `create-parallel-world`,
                 then `parallel-world` will be packaged.
                 Note all Shims use the same version of spark-rapids-jni and jucx -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-spark-rapids-jni-and-ucx</id>
                        <!-- run after `create-parallel-world`, the phase equals to the phase of the `create-parallel-world` -->
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <!-- if add new artifacts, should set `overWrite` as true -->
                                <artifactItem>
                                    <groupId>com.nvidia</groupId>
                                    <artifactId>spark-rapids-jni</artifactId>
                                    <classifier>${cuda.version}</classifier>
                                    <excludes>META-INF</excludes>
                                    <outputDirectory>${project.build.directory}/parallel-world</outputDirectory>
                                    <overWrite>true</overWrite>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.openucx</groupId>
                                    <artifactId>jucx</artifactId>
                                    <excludes>META-INF</excludes>
                                    <outputDirectory>${project.build.directory}/parallel-world</outputDirectory>
                                    <overWrite>true</overWrite>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <version>3.0.1</version>
                <executions>
                    <execution>
                        <id>default-install</id>
                        <phase>none</phase>
                    </execution>
                    <execution>
                        <id>install-parallel-worlds-jar</id>
                        <phase>install</phase>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <configuration>
                            <file>${dist.jar.name}</file>
                            <artifactId>${project.artifactId}</artifactId>
                            <classifier>${cuda.version}</classifier>
                            <groupId>${project.groupId}</groupId>
                            <version>${project.version}</version>
                            <packaging>jar</packaging>
                            <!-- pomFile will be taken from META-INF in jar
                            https://github.com/apache/maven-install-plugin/blob/9f77fb95ab2a95b1d8d0c34c39c6f088f9f690ab/src/main/java/org/apache/maven/plugins/install/InstallFileMojo.java#L309
                            -->
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <id>default-deploy</id>
                        <phase>none</phase>
                    </execution>
                    <execution>
                        <id>deploy-parallel-worlds-jar</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>deploy-file</goal>
                        </goals>
                        <configuration>
                            <file>${dist.jar.name}</file>
                            <url>file://${java.io.tmpdir}/m2-repo</url>
                            <artifactId>${project.artifactId}</artifactId>
                            <classifier>${cuda.version}</classifier>
                            <groupId>${project.groupId}</groupId>
                            <packaging>jar</packaging>
                            <!-- pomFile will be taken from META-INF in jar
                            https://github.com/apache/maven-deploy-plugin/blob/4a72d8e9778c1878058435bdb919d40d65c879dd/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java#L186
                            -->
                            <version>${project.version}</version>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
