<?xml version="1.0"?>
<!--

    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you 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>org.apache.drill.contrib.storage-hive</groupId>
    <artifactId>drill-contrib-storage-hive-parent</artifactId>
    <version>1.17.0</version>
  </parent>

  <artifactId>drill-hive-exec-shaded</artifactId>
  <packaging>jar</packaging>
  <name>contrib/hive-storage-plugin/hive-exec-shaded</name>

  <properties>
    <hive.parquet.version>1.8.3</hive.parquet.version>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.apache.parquet</groupId>
        <artifactId>parquet-hadoop-bundle</artifactId>
        <version>${hive.parquet.version}</version>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>org.apache.hive</groupId>
      <artifactId>hive-exec</artifactId>
      <scope>compile</scope>
      <exclusions>
        <!--Hive Calcite libraries are not required. When user submits query in Drill via Hive plugin, the query
        is validated and planned via Drill Calcite. Hive Calcite can be used only to setup Hive store for Drill unit
        testing, where a lot of Hive specific queries are performed. But Drill Calcite and Avatica versions have
        conflicts with Hive old Calcite and Avatica versions. That's why Calcite cost based optimizator
        (ConfVars.HIVE_CBO_ENABLED) is disabled for Drill Hive JUnit test cases. It can be enabled again once Hive
        will leverage the newest Calcite version. To do that check whether Drill Calcite and Avatica versions are
        suitable for hive-exec. If no, use Hive Calcite and Avatica versions.
        Note: Versions of Calcite libraries are controlled by "DependencyManagement" block in Drill's
        root POM file now-->
        <exclusion>
          <groupId>org.apache.calcite</groupId>
          <artifactId>calcite-core</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.apache.calcite.avatica</groupId>
          <artifactId>avatica</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.apache.calcite</groupId>
          <artifactId>calcite-linq4j</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.apache.calcite</groupId>
          <artifactId>calcite-druid</artifactId>
        </exclusion>
        <exclusion>
          <groupId>com.github.joshelser</groupId>
          <artifactId>dropwizard-metrics-hadoop-metrics2-reporter</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-shade-plugin</artifactId>
        <configuration>
          <artifactSet>
            <includes>
              <include>org.apache.hive:hive-exec</include>
              <!-- Provides custom version of parquet-hadoop-bundle instead of the shaded one
                to be able to use version with some critical fixes like PARQUET-363 -->
              <include>org.apache.parquet:parquet-hadoop-bundle</include>
              <include>commons-codec:commons-codec</include>
              <include>com.fasterxml.jackson.core:jackson-databind</include>
              <include>com.fasterxml.jackson.core:jackson-annotations</include>
              <include>com.fasterxml.jackson.core:jackson-core</include>
            </includes>
          </artifactSet>
          <createDependencyReducedPom>false</createDependencyReducedPom>
          <promoteTransitiveDependencies>true</promoteTransitiveDependencies>
          <createSourcesJar>true</createSourcesJar>
          <shadeSourcesContent>true</shadeSourcesContent>
          <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer" />
            <transformer implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer">
              <addHeader>false</addHeader>
            </transformer>
          </transformers>
          <relocations>
            <relocation>
              <pattern>com.google.</pattern>
              <shadedPattern>hive.com.google.</shadedPattern>
            </relocation>
            <relocation>
              <pattern>org.apache.commons.codec.</pattern>
              <shadedPattern>hive.org.apache.commons.codec.</shadedPattern>
            </relocation>
            <relocation>
              <pattern>net.hydromatic.</pattern>
              <shadedPattern>hive.net.hydromatic.</shadedPattern>
            </relocation>
            <relocation>
              <pattern>org.eigenbase.</pattern>
              <shadedPattern>hive.org.eigenbase.</shadedPattern>
            </relocation>
            <relocation>
              <pattern>com.fasterxml.jackson.</pattern>
              <shadedPattern>hive.com.fasterxml.jackson.</shadedPattern>
            </relocation>
            <relocation>
              <pattern>org.apache.parquet.</pattern>
              <shadedPattern>hive.org.apache.parquet.</shadedPattern>
            </relocation>
            <relocation>
              <pattern>shaded.parquet.</pattern>
              <shadedPattern>hive.shaded.parquet.</shadedPattern>
            </relocation>
            <relocation>
              <pattern>org.apache.avro.</pattern>
              <shadedPattern>hive.org.apache.avro.</shadedPattern>
            </relocation>
            <relocation>
              <pattern>com.google.protobuf.</pattern>
              <shadedPattern>hive.com.google.protobuf.</shadedPattern>
            </relocation>
          </relocations>
          <filters>
            <filter>
              <artifact>org.apache.hive:hive-exec</artifact>
              <excludes>
                <!-- This exclusion can be removed once hive-exec uses parquet-hadoop-bundle 1.8.2 or higher.
                 It can be so, for example, after upgrading Hive to 3.0. To check if it's safe to remove the exclusion
                 you can use TestHiveStorage.readFromAlteredPartitionedTableWithEmptyGroupType() test case. -->
                <exclude>org/apache/parquet/**</exclude>
                <exclude>shaded/parquet/org/**</exclude>
              </excludes>
            </filter>
          </filters>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>unpack</id>
            <phase>package</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.apache.drill.contrib.storage-hive</groupId>
                  <artifactId>drill-hive-exec-shaded</artifactId>
                  <version>${project.version}</version>
                  <type>jar</type>
                  <overWrite>true</overWrite>
                  <outputDirectory>${project.build.directory}/classes</outputDirectory>
                  <includes>**/**</includes>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>attach-hive-shaded</id>
            <phase>package</phase>
            <goals>
              <goal>attach-artifact</goal>
            </goals>
            <configuration>
              <artifacts>
                <artifact>
                  <file>${project.build.directory}/${project.artifactId}-${project.version}.jar</file>
                  <type>jar</type>
                  <classifier>jar</classifier>
                </artifact>
                <artifact>
                  <file>${project.build.directory}/${project.artifactId}-${project.version}-sources.jar</file>
                  <type>jar</type>
                  <classifier>sources</classifier>
                </artifact>
              </artifacts>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>findbugs-maven-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
