<?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.6.3</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>
  </properties>

  <!-- Adding this to resolve version conflict within beam sdk-->
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.apache.beam</groupId>
        <artifactId>beam-sdks-java-bom</artifactId>
        <version>${beam.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <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>com.google.cloud.bigdataoss</groupId>
      <artifactId>gcs-connector</artifactId>
      <version>hadoop2-2.2.2</version>
      <classifier>shaded</classifier>
    </dependency>
    <dependency>
      <groupId>org.apache.beam</groupId>
      <artifactId>
        beam-sdks-java-extensions-google-cloud-platform-core
      </artifactId>
      <exclusions>
        <exclusion>
          <groupId>org.hamcrest</groupId>
          <artifactId>hamcrest</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.apache.beam</groupId>
      <artifactId>beam-runners-google-cloud-dataflow-java</artifactId>
      <exclusions>
        <!-- Exclude BigtableIO deps, we don't need them since we are using CloudBigtableIO -->
        <exclusion>
          <groupId>com.google.cloud.bigtable</groupId>
          <artifactId>bigtable-client-core</artifactId>
        </exclusion>
        <exclusion>
          <groupId>com.google.api.grpc</groupId>
          <artifactId>grpc-google-cloud-bigtable-v2</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.hamcrest</groupId>
          <artifactId>hamcrest</artifactId>
        </exclusion>
          <exclusion>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest</artifactId>
          </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.apache.beam</groupId>
      <artifactId>beam-sdks-java-io-hadoop-common</artifactId>
      <!-- used at runtime via WritableCoderProviderRegistrar service -->
      <scope>runtime</scope>
      <exclusions>
        <exclusion>
          <groupId>org.hamcrest</groupId>
          <artifactId>hamcrest</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.apache.beam</groupId>
      <artifactId>beam-sdks-java-io-hadoop-format</artifactId>
      <exclusions>
        <exclusion>
          <groupId>org.hamcrest</groupId>
          <artifactId>hamcrest</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <!-- Used transitively by beam, and directly in tests -->
    <dependency>
      <groupId>org.apache.beam</groupId>
      <artifactId>beam-runners-core-construction-java</artifactId>
      <scope>runtime</scope>
      <exclusions>
        <exclusion>
          <groupId>org.hamcrest</groupId>
          <artifactId>hamcrest</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.apache.beam</groupId>
      <artifactId>beam-vendor-guava-26_0-jre</artifactId>
      <version>0.1</version>
      <scope>runtime</scope>
    </dependency>

    <!-- Bigtable Group: ordering doesn't matter since everything is shaded -->
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>bigtable-hbase-beam</artifactId>
      <version>2.6.3</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>com.google.cloud.bigtable</groupId>
      <artifactId>bigtable-hbase-1.x-shaded</artifactId>
      <version>2.6.3</version> <!-- {x-version-update:bigtable-client-parent:current} -->
      <exclusions>
        <!-- exclude hbase-shaded-client since we are using hbase-shaded-server -->
        <exclusion>
          <groupId>org.apache.hbase</groupId>
          <artifactId>hbase-shaded-client</artifactId>
        </exclusion>

        <!-- google-cloud-bigtable pulls in a newer version of this, but we want to match beam's version-->
        <exclusion>
          <groupId>org.conscrypt</groupId>
          <artifactId>conscrypt-openjdk-uber</artifactId>
        </exclusion>

        <!-- Workaround MNG-5899 & MSHADE-206. Maven >= 3.3.0 doesn't use the dependency reduced
        pom.xml files when invoking the build from a parent project. So we have to manually exclude
        the dependencies. Note that this works in conjunction with the manually promoted dependencies
        in bigtable-hbase-1.x-shaded/pom.xml -->
        <exclusion>
          <groupId>${project.groupId}</groupId>
          <artifactId>bigtable-hbase-1.x</artifactId>
        </exclusion>
        <exclusion>
          <groupId>com.google.cloud.bigtable</groupId>
          <artifactId>bigtable-metrics-api</artifactId>
        </exclusion>
        <exclusion>
          <groupId>io.opencensus</groupId>
          <artifactId>*</artifactId>
        </exclusion>
        <exclusion>
          <groupId>io.grpc</groupId>
          <artifactId>grpc-census</artifactId>
        </exclusion>
      </exclusions>
    </dependency>


    <!-- HBase Group: contains interfaces bigtable-hbase implement + serializers -->
    <dependency>
      <groupId>org.apache.hbase</groupId>
      <artifactId>hbase-shaded-server</artifactId>
      <version>${hbase1.version}</version>
    </dependency>


    <!-- Misc Group -->
    <dependency>
      <groupId>com.google.apis</groupId>
      <artifactId>google-api-services-storage</artifactId>
      <version>v1-rev20210127-1.31.0</version>
    </dependency>
    <dependency>
      <groupId>com.google.code.findbugs</groupId>
      <artifactId>jsr305</artifactId>
      <version>${jsr305.version}</version>
    </dependency>
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>31.0-jre</version>
    </dependency>
    <dependency>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
      <version>${commons-logging.version}</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>${beam-slf4j.version}</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>${beam-slf4j.version}</version>
      <scope>runtime</scope>
    </dependency>


    <!-- CVE Group: force update transitive deps to exclude CVEs -->
    <dependency>
      <groupId>commons-codec</groupId>
      <artifactId>commons-codec</artifactId>
      <version>1.15</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-compress</artifactId>
      <version>1.21</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>
      <version>0.151.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.google.cloud.bigtable</groupId>
      <artifactId>bigtable-internal-test-helper</artifactId>
      <version>2.6.3</version> <!-- {x-version-update:bigtable-client-parent:current} -->
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.hbase</groupId>
      <artifactId>hbase-shaded-testing-util</artifactId>
      <version>${hbase1.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>${junit.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.google.truth</groupId>
      <artifactId>truth</artifactId>
      <version>1.1.3</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.hamcrest</groupId>
      <artifactId>hamcrest-library</artifactId>
      <version>${hamcrest.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.hamcrest</groupId>
      <artifactId>hamcrest-core</artifactId>
      <version>${hamcrest.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>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <executions>
          <execution>
            <id>enforce</id>
            <configuration>
              <skip>true</skip>
            </configuration>
          </execution>
        </executions>
      </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>
        <version>3.3.0</version>
        <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>

      <plugin>
        <groupId>com.google.cloud.bigtable.test</groupId>
        <artifactId>bigtable-build-helper</artifactId>
        <version>2.6.3</version> <!-- {x-version-update:bigtable-client-parent:current} -->
        <executions>
          <execution>
            <id>verify-mirror-deps</id>
            <phase>verify</phase>
            <goals>
              <goal>verify-mirror-deps</goal>
            </goals>
            <configuration>
              <targetDependencies>
                <targetDependency>org.apache.beam:beam-sdks-java-core:${beam.version}</targetDependency>
              </targetDependencies>
              <ignoredDependencies>
                <!-- beam's dependency tree has an older version closer higher in the tree -->
                <dependency>org.apache.commons:commons-compress</dependency>
              </ignoredDependencies>
            </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>
            <version>3.0.0-M4</version>
            <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>
