<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2017 Google LLC

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">
  <parent>
    <groupId>com.google.cloud.bigtable</groupId>
    <artifactId>bigtable-dataflow-parent</artifactId>
    <version>2.20.2</version> <!-- {x-version-update:bigtable-client-parent:current} -->
  </parent>
  <modelVersion>4.0.0</modelVersion>

  <artifactId>bigtable-beam-import</artifactId>
  <name>${project.groupId}:${project.artifactId}</name>

  <properties>
    <mainClass>com.google.cloud.bigtable.beam.Main</mainClass>
    <hadoop.version>3.3.5</hadoop.version>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.apache.beam</groupId>
        <artifactId>beam-sdks-java-google-cloud-platform-bom</artifactId>
        <version>${beam.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>

      <!-- Version alignment -->
      <!-- Mark all annotations as provided. They don't affect the runtime of the pipeline so
      there is no need to try to version align them -->
      <dependency>
        <groupId>org.checkerframework</groupId>
        <artifactId>checker-qual</artifactId>
        <version>3.31.0</version>
        <scope>provided</scope>
      </dependency>
      <dependency>
        <groupId>com.google.errorprone</groupId>
        <artifactId>error_prone_annotations</artifactId>
        <version>2.18.0</version>
        <scope>provided</scope>
      </dependency>
      <dependency>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>animal-sniffer-annotations</artifactId>
        <version>1.22</version>
        <scope>provided</scope>
      </dependency>
      <dependency>
        <groupId>jakarta.annotation</groupId>
        <artifactId>jakarta.annotation-api</artifactId>
        <version>1.3.5</version>
        <scope>provided</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <!-- Beam Group: should come first since we will be running in the beam ecosystem -->
    <dependency>
      <groupId>org.apache.beam</groupId>
      <artifactId>beam-sdks-java-core</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.beam</groupId>
      <artifactId>beam-sdks-java-io-hadoop-format</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.beam</groupId>
      <artifactId>beam-runners-google-cloud-dataflow-java</artifactId>
      <exclusions>
        <exclusion>
          <!-- Avoid conflicts with commons-logging: beam-sdks-java-io-kafka pulls in spring-core which hijacks commons-logging -->
          <groupId>org.springframework</groupId>
          <artifactId>spring-jcl</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>com.google.cloud.bigdataoss</groupId>
      <artifactId>gcs-connector</artifactId>
      <version>hadoop3-2.2.21</version>
      <classifier>shaded</classifier>
      <exclusions>
        <!-- shaded variant doesn't have deps -->
        <exclusion>
          <groupId>*</groupId>
          <artifactId>*</artifactId>
        </exclusion>
      </exclusions>
    </dependency>


    <!-- Bigtable w/ client patches to HBase -->
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>bigtable-hbase-beam</artifactId>
      <version>2.20.2</version> <!-- {x-version-update:bigtable-client-parent:current} -->
      <exclusions>
        <!-- Exclude hbase-shaded-client to prevent reintroducing the dnsjava SPI / LiteralByteString conflict (NoClassDefFoundError) -->
        <exclusion>
          <groupId>org.apache.hbase</groupId>
          <artifactId>hbase-shaded-client</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>org.apache.hadoop</groupId>
      <artifactId>hadoop-client-api</artifactId>
      <version>${hadoop.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.hadoop</groupId>
      <artifactId>hadoop-client-runtime</artifactId>
      <version>${hadoop.version}</version>
    </dependency>


    <!-- Use hbase-shaded-mapreduce (instead of hbase-shaded-client) to defeat the dnsjava SPI / LiteralByteString conflict (NoClassDefFoundError on JDK 21+) -->
    <dependency>
      <groupId>org.apache.hbase</groupId>
      <artifactId>hbase-shaded-mapreduce</artifactId>
      <version>${hbase2.version}</version>
      <exclusions>
        <exclusion>
          <groupId>log4j</groupId>
          <artifactId>log4j</artifactId>
        </exclusion>
        <exclusion>
          <!-- Dont need access to hdfs & it conflicts with beam deps -->
          <groupId>org.apache.hadoop</groupId>
          <artifactId>hadoop-hdfs-client</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.apache.hbase</groupId>
          <artifactId>hbase-shaded-client</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>ch.qos.reload4j</groupId>
      <artifactId>reload4j</artifactId>
      <version>${reload4j.version}</version>
      <scope>runtime</scope>
    </dependency>


    <!-- Test Group -->
    <dependency>
      <groupId>org.apache.beam</groupId>
      <artifactId>beam-runners-direct-java</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-bigtable-emulator-core</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.hbase</groupId>
      <artifactId>hbase-shaded-testing-util</artifactId>
      <version>${hbase2.version}</version>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <groupId>log4j</groupId>
          <artifactId>log4j</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>com.google.cloud.bigtable</groupId>
      <artifactId>bigtable-internal-test-helper</artifactId>
      <version>2.20.2</version> <!-- {x-version-update:bigtable-client-parent:current} -->
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>${junit.version}</version>
      <scope>test</scope>
      <exclusions>
        <!-- Avoid conflict with beam-sdks-java-core's transitive dep on hamcrest 2.1
          JUnit has a transitive dep on hamcrest-core 1.x, beam has a dep on hamcrest 2.1.
          The artifact were renamed at version 2.0 and hamcrest-core was pulled into hamcrest.
          We only care for this for tests, so its safe to exclude it here....tests will break if beam drops it.
         -->
        <exclusion>
          <groupId>org.hamcrest</groupId>
          <artifactId>hamcrest-core</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>com.google.truth</groupId>
      <artifactId>truth</artifactId>
      <version>${truth.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-inline</artifactId>
      <version>${mockito.version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <testResources>
      <testResource>
        <!-- Prevent maven from trying to filter the binary zip files -->
        <directory>src/test/resources</directory>
        <filtering>false</filtering>
      </testResource>
    </testResources>

    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-enforcer-plugin</artifactId>
          <executions>
            <!-- TODO: figure out how to deal with beam enforcement errors -->
            <execution>
              <id>enforce</id>
              <configuration>
                <skip>true</skip>
              </configuration>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>


    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <fork>true</fork>
        </configuration>
      </plugin>

      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
          <archive>
            <manifest>
              <mainClass>${mainClass}</mainClass>
            </manifest>
          </archive>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>java</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <mainClass>${mainClass}</mainClass>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>../../third_party/third_party_hbase_server/src/main/import/</source>
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <shadedArtifactAttached>true</shadedArtifactAttached>
          <!-- The shaded jar is attached under a classifier, so the main artifact is the thin,
               unshaded jar and it still needs every one of its compile dependencies declared.
               A dependency-reduced pom would strip them and leave consumers with nothing to
               resolve (MSHADE-419 does exactly that in shade >= 3.3.0, which shipped broken
               poms in 2.20.0 and 2.20.1). Set explicitly rather than relying on the plugin
               default, whose behavior here changed between 3.2.4 and 3.6.0.
               Guarded by the verify-published-pom-deps check below. -->
          <createDependencyReducedPom>false</createDependencyReducedPom>
          <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer" />
          </transformers>
	  <filters>
	      <filter>
		  <artifact>*:*</artifact>
		  <excludes>
		      <!-- Exclude InetAddressResolverProvider to prevent the dnsjava SPI / LiteralByteString conflict (NoClassDefFoundError on JDK 21+) -->
		      <exclude>META-INF/services/java.net.spi.InetAddressResolverProvider</exclude>
		      <exclude>META-INF/*.SF</exclude>
		      <exclude>META-INF/*.DSA</exclude>
		      <exclude>META-INF/*.RSA</exclude>
          <exclude>META-INF/**/pom.properties</exclude>
          <exclude>META-INF/**/pom.xml</exclude>
          <exclude>META-INF/LICENSE</exclude>
          <exclude>META-INF/NOTICE.txt</exclude>
          <exclude>META-INF/NOTICE</exclude>
          <exclude>META-INF/DEPENDENCIES</exclude>
          <exclude>META-INF/ASL2.0</exclude>
          <exclude>META-INF/LICENSE.txt</exclude>
          <exclude>**/*.proto</exclude>
      </excludes>
	      </filter>
	  </filters>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <trimStackTrace>false</trimStackTrace>
        </configuration>
        <executions>
          <execution>
            <id>default-test</id>
            <phase>test</phase>
            <goals>
              <goal>test</goal>
            </goals>
            <configuration>
              <excludes>
                <exclude>**/*IT.java</exclude>
              </excludes>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <configuration>
          <!-- disable integration tests by default, opt-in via profile -->
          <skip>true</skip>
        </configuration>
      </plugin>

      <plugin>
        <groupId>com.google.cloud.bigtable.test</groupId>
        <artifactId>bigtable-build-helper</artifactId>
        <version>2.20.2</version> <!-- {x-version-update:bigtable-client-parent:current} -->
        <executions>
          <execution>
            <id>verify-published-pom-deps</id>
            <phase>verify</phase>
            <goals>
              <goal>verify-published-pom-deps</goal>
            </goals>
            <configuration>
              <!-- The main artifact is the thin, unshaded jar, so these have to survive into the
                   published pom. Shade stripped every one of them in 2.20.0 and 2.20.1, which
                   broke downstream consumers (e.g. DataflowTemplates) with a
                   NoClassDefFoundError that no build in this repo could reproduce. -->
              <requiredDependencies>
                <requiredDependency>com.google.cloud.bigtable:bigtable-hbase-beam</requiredDependency>
                <requiredDependency>org.apache.beam:beam-sdks-java-core</requiredDependency>
                <requiredDependency>org.apache.beam:beam-sdks-java-io-hadoop-format</requiredDependency>
                <requiredDependency>org.apache.beam:beam-runners-google-cloud-dataflow-java</requiredDependency>
                <requiredDependency>org.apache.hadoop:hadoop-client-api</requiredDependency>
                <requiredDependency>org.apache.hadoop:hadoop-client-runtime</requiredDependency>
                <requiredDependency>org.apache.hbase:hbase-shaded-mapreduce</requiredDependency>
                <requiredDependency>com.google.cloud.bigdataoss:gcs-connector</requiredDependency>
              </requiredDependencies>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <!-- TODO: remove the sequence file profile after kokoro jobs are migrated -->
    <profile>
      <id>sequencefileIntegrationTest</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <executions>
              <execution>
                <id>import-e2e-test</id>
                <goals>
                  <goal>integration-test</goal>
                  <goal>verify</goal>
                </goals>
                <configuration>
                  <skip>false</skip>
                  <includes>
                    <include>**/sequencefiles/*IT.java</include>
                  </includes>
                  <!-- Use Isolated Classloader so that dataflow can find all files
                                         that must be staged.
                                    -->
                  <forkCount>1</forkCount>
                  <useSystemClassLoader>false</useSystemClassLoader>

                  <!-- prevent multiple executions from clobering each other -->
                  <summaryFile>${project.build.directory}/failsafe-reports/sequencefile-tests/failsafe-summary.xml</summaryFile>
                  <reportsDirectory>${project.build.directory}/failsafe-reports/sequencefile-tests</reportsDirectory>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>beamIntegrationTest</id>
      <!-- Requires system properties to be set, see TestProperties.java -->
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <executions>
              <execution>
                <id>beam-integration-test</id>
                <goals>
                  <goal>integration-test</goal>
                  <goal>verify</goal>
                </goals>

                <configuration>
                  <skip>false</skip>
                  <includes>
                    <include>**/*IT.java</include>
                  </includes>
                  <!-- Use Isolated Classloader so that dataflow can find all files
                       that must be staged.
                  -->
                  <forkCount>1</forkCount>
                  <useSystemClassLoader>false</useSystemClassLoader>

                  <!-- Run tests in parallel -->
                  <parallel>all</parallel>
                  <threadCount>10</threadCount>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
