<?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.14.2</version> <!-- {x-version-update:bigtable-client-parent:current} -->
  </parent>
  <modelVersion>4.0.0</modelVersion>

  <artifactId>bigtable-beam-import</artifactId>

  <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>
    </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.14.2</version> <!-- {x-version-update:bigtable-client-parent:current} -->
      <exclusions>
        <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>


    <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>
      </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>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</groupId>
      <artifactId>google-cloud-bigtable-emulator-core</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.google.cloud.bigtable</groupId>
      <artifactId>bigtable-internal-test-helper</artifactId>
      <version>2.14.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-core</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>
        <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>
          <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>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/MANIFEST.MF</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>
    </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>
