<!--
 Copyright 2020 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">
  <properties>
    <java.version>1.8</java.version>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <skipTests>false</skipTests>
    <skipUnits>${skipTests}</skipUnits>
    <skipITs>true</skipITs>
    <it.forkCount>16</it.forkCount>
    <clirr.skip>true</clirr.skip>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

    <excludedTests>
      com.google.cloud.spanner.pgadapter.IntegrationTest,
      com.google.cloud.spanner.pgadapter.golang.GolangTest,
      com.google.cloud.spanner.pgadapter.csharp.DotnetTest,
      com.google.cloud.spanner.pgadapter.python.PythonTest,
      com.google.cloud.spanner.pgadapter.php.PhpTest,
      com.google.cloud.spanner.pgadapter.nodejs.NodeJSTest,
      com.google.cloud.spanner.pgadapter.ruby.RubyTest,
    </excludedTests>
    <excludedIntegrationTests/>

    <junixsocket.version>2.10.1</junixsocket.version>
    <opentelemetry.exporter.version>0.36.0</opentelemetry.exporter.version>
  </properties>

  <modelVersion>4.0.0</modelVersion>
  <artifactId>google-cloud-spanner-pgadapter</artifactId>
  <version>0.53.2</version><!-- {x-version-update:google-cloud-spanner-pgadapter:current} -->
  <name>Google Cloud Spanner PostgreSQL Adapter</name>
  <packaging>jar</packaging>
  <description>
    The PGAdapter server implements the PostgreSQL wire-protocol, but sends all received statements
    to a Cloud Spanner database instead of a PostgreSQL database. The Cloud Spanner database must
    have been created to use the PostgreSQL dialect. See https://cloud.google.com/spanner/docs/quickstart-console#postgresql
    for more information on how to create PostgreSQL dialect databases on Cloud Spanner.
  </description>
  <parent>
    <groupId>com.google.cloud</groupId>
    <artifactId>google-cloud-shared-config</artifactId>
    <version>1.17.0</version>
  </parent>
  <scm>
    <connection>scm:git:git@github.com:GoogleCloudPlatform/pgadapter.git</connection>
    <developerConnection>scm:git:git@github.com:GoogleCloudPlatform/pgadapter.git</developerConnection>
    <url>https://github.com/GoogleCloudPlatform/pgadapter</url>
    <tag>HEAD</tag>
  </scm>
  <issueManagement>
    <url>https://github.com/GoogleCloudPlatform/pgadapter/issues</url>
    <system>GitHub Issues</system>
  </issueManagement>
  <licenses>
    <license>
      <name>Apache-2.0</name>
      <url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
    </license>
  </licenses>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>io.opentelemetry</groupId>
        <artifactId>opentelemetry-bom</artifactId>
        <version>1.59.0</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupId>com.google.cloud</groupId>
        <artifactId>libraries-bom</artifactId>
        <version>26.77.0</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-spanner</artifactId>
      <exclusions>
        <exclusion>
          <groupId>io.opentelemetry</groupId>
          <artifactId>opentelemetry-api-incubator</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>com.google.re2j</groupId>
      <artifactId>re2j</artifactId>
      <version>1.8</version>
    </dependency>
    <dependency>
      <groupId>com.google.auto.value</groupId>
      <artifactId>auto-value-annotations</artifactId>
    </dependency>
    <dependency>
      <groupId>org.checkerframework</groupId>
      <artifactId>checker-qual</artifactId>
      <version>3.54.0</version>
    </dependency>
    <dependency>
      <groupId>io.opentelemetry</groupId>
      <artifactId>opentelemetry-api</artifactId>
    </dependency>
    <dependency>
      <groupId>io.opentelemetry</groupId>
      <artifactId>opentelemetry-sdk</artifactId>
    </dependency>
    <dependency>
      <groupId>io.opentelemetry</groupId>
      <artifactId>opentelemetry-sdk-metrics</artifactId>
    </dependency>
    <dependency>
      <groupId>io.opentelemetry</groupId>
      <artifactId>opentelemetry-exporter-otlp</artifactId>
    </dependency>
    <dependency>
      <groupId>io.opentelemetry</groupId>
      <artifactId>opentelemetry-exporter-logging</artifactId>
    </dependency>
    <dependency>
      <groupId>io.opentelemetry</groupId>
      <artifactId>opentelemetry-sdk-extension-autoconfigure</artifactId>
    </dependency>
    <dependency>
      <groupId>io.opentelemetry</groupId>
      <artifactId>opentelemetry-sdk-extension-autoconfigure-spi</artifactId>
    </dependency>
    <dependency>
      <groupId>com.google.cloud.opentelemetry</groupId>
      <artifactId>exporter-trace</artifactId>
      <version>${opentelemetry.exporter.version}</version>
    </dependency>
    <dependency>
      <groupId>com.google.cloud.opentelemetry</groupId>
      <artifactId>exporter-metrics</artifactId>
      <version>${opentelemetry.exporter.version}</version>
    </dependency>
    <dependency>
      <groupId>org.jetbrains.kotlin</groupId>
      <artifactId>kotlin-stdlib-jdk8</artifactId>
      <version>2.3.10</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>org.postgresql</groupId>
      <artifactId>postgresql</artifactId>
      <version>42.7.10</version>
    </dependency>
    <dependency>
      <groupId>com.kohlschutter.junixsocket</groupId>
      <artifactId>junixsocket-core</artifactId>
      <version>${junixsocket.version}</version>
      <type>pom</type>
    </dependency>
    <dependency>
      <groupId>com.kohlschutter.junixsocket</groupId>
      <artifactId>junixsocket-common</artifactId>
      <version>${junixsocket.version}</version>
    </dependency>
    <dependency>
      <groupId>com.googlecode.json-simple</groupId>
      <artifactId>json-simple</artifactId>
      <version>1.1.1</version>
      <exclusions>
        <exclusion>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>commons-cli</groupId>
      <artifactId>commons-cli</artifactId>
      <version>1.11.0</version>
    </dependency>
    <dependency>
      <groupId>commons-codec</groupId>
      <artifactId>commons-codec</artifactId>
      <version>1.21.0</version>
    </dependency>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-csv</artifactId>
      <version>1.14.1</version>
    </dependency>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-text</artifactId>
      <version>1.15.0</version>
    </dependency>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-model</artifactId>
      <version>3.9.12</version>
    </dependency>
    <dependency>
      <groupId>org.bouncycastle</groupId>
      <artifactId>bcpkix-jdk18on</artifactId>
      <version>1.83</version>
    </dependency>
    <dependency>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>animal-sniffer-annotations</artifactId>
      <version>1.27</version>
      <optional>true</optional>
    </dependency>

    <!-- Test dependencies -->
    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-spanner</artifactId>
      <type>test-jar</type>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.google.api</groupId>
      <artifactId>gax-grpc</artifactId>
      <classifier>testlib</classifier>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>net.java.dev.jna</groupId>
      <artifactId>jna</artifactId>
      <version>5.18.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.13.2</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-core</artifactId>
      <version>4.11.0</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <profiles>
    <profile>
      <id>shade</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <executions>
              <execution>
                <goals>
                  <goal>shade</goal>
                </goals>
                <configuration>
                  <finalName>pgadapter</finalName>
                  <filters>
                    <filter>
                      <artifact>*:*</artifact>
                      <!-- We need to exclude the signatures for any signed jars otherwise
                      we get an exception. -->
                      <excludes>
                        <exclude>META-INF/*.SF</exclude>
                        <exclude>META-INF/*.DSA</exclude>
                        <exclude>META-INF/*.RSA</exclude>
                      </excludes>
                    </filter>
                  </filters>
                  <createSourcesJar>true</createSourcesJar>
                  <shadeSourcesContent>true</shadeSourcesContent>
                  <shadedArtifactAttached>false</shadedArtifactAttached>
                  <createDependencyReducedPom>false</createDependencyReducedPom>
                  <artifactSet>
                    <includes>
                      <include>*:*</include>
                    </includes>
                    <excludes>
                      <exclude>java:*</exclude>
                      <exclude>junit:*</exclude>
                    </excludes>
                  </artifactSet>
                  <transformers>
                    <transformer
                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                      <mainClass>com.google.cloud.spanner.pgadapter.Server
                      </mainClass>
                    </transformer>
                    <transformer
                        implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
                      <resource>META-INF/services</resource>
                      <file>io.grpc.LoadBalancerProvider</file>
                    </transformer>
                  </transformers>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>test-all</id>
      <properties>
        <excludedTests>
          com.google.cloud.spanner.pgadapter.IntegrationTest
        </excludedTests>
      </properties>
    </profile>

    <profile>
      <id>assembly</id>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
              <execution>
                <id>copy-resources</id>
                <phase>validate</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${project.build.directory}/pgadapter</outputDirectory>
                  <resources>
                    <resource>
                      <directory>resources</directory>
                      <filtering>false</filtering>
                    </resource>
                  </resources>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                <id>copy-dependencies</id>
                <phase>prepare-package</phase>
                <goals>
                  <goal>copy-dependencies</goal>
                </goals>
                <configuration>
                  <outputDirectory>${project.build.directory}/pgadapter/lib</outputDirectory>
                  <overWriteReleases>false</overWriteReleases>
                  <overWriteSnapshots>false</overWriteSnapshots>
                  <overWriteIfNewer>true</overWriteIfNewer>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
              <finalName>pgadapter/pgadapter</finalName>
              <archive>
                <index>false</index>
                <manifest>
                  <mainClass>com.google.cloud.spanner.pgadapter.Server</mainClass>
                  <addClasspath>true</addClasspath>
                  <classpathPrefix>lib/</classpathPrefix>
                </manifest>
              </archive>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>format</id>
      <activation>
        <jdk>[17,)</jdk>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>com.spotify.fmt</groupId>
            <artifactId>fmt-maven-plugin</artifactId>
            <executions>
              <execution>
                <goals>
                  <goal>format</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

  <build>
    <testResources>
      <testResource>
        <directory>${project.basedir}/src/test/resources</directory>
      </testResource>
      <testResource>
        <directory>${project.basedir}/src/main/resources</directory>
      </testResource>
    </testResources>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>clirr-maven-plugin</artifactId>
        <executions>
          <execution>
            <!-- Disable this plugin for now as it regularly times out when being downloaded -->
            <phase>none</phase>
          </execution>
        </executions>
        <configuration>
          <skip>${clirr.skip}</skip>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <forkedProcessExitTimeoutInSeconds>3</forkedProcessExitTimeoutInSeconds>
          <forkedProcessTimeoutInSeconds>3600</forkedProcessTimeoutInSeconds>
          <!--suppress UnresolvedMavenProperty -->
          <argLine>${surefire.jacoco.args}</argLine>
          <excludedGroups>${excludedTests}</excludedGroups>
          <reportNameSuffix>sponge_log</reportNameSuffix>
          <skipTests>${skipUnits}</skipTests>
          <systemProperties>
            <property>
              <name>java.util.logging.config.file</name>
              <value>src/test/resources/logging.properties</value>
            </property>
          </systemProperties>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>prepare-agent</goal>
            </goals>
            <configuration>
              <destFile>${project.build.directory}/jacoco-output/jacoco-unit-tests.exec</destFile>
              <propertyName>surefire.jacoco.args</propertyName>
            </configuration>
          </execution>
          <execution>
            <id>after-unit-test-execution</id>
            <phase>test</phase>
            <goals>
              <goal>report</goal>
            </goals>
            <configuration>
              <dataFile>${project.build.directory}/jacoco-output/jacoco-unit-tests.exec</dataFile>
              <outputDirectory>${project.reporting.outputDirectory}/jacoco-unit-test-coverage-report</outputDirectory>
            </configuration>
          </execution>

          <execution>
            <id>before-integration-test-execution</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>prepare-agent</goal>
            </goals>
            <configuration>
              <destFile>${project.build.directory}/jacoco-output/jacoco-integration-tests.exec</destFile>
              <propertyName>failsafe.jacoco.args</propertyName>
            </configuration>
          </execution>
          <execution>
            <id>after-integration-test-execution</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>report</goal>
            </goals>
            <configuration>
              <dataFile>${project.build.directory}/jacoco-output/jacoco-integration-tests.exec</dataFile>
              <outputDirectory>${project.reporting.outputDirectory}/jacoco-integration-test-coverage-report</outputDirectory>
            </configuration>
          </execution>
          <execution>
            <id>merge-unit-and-integration</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>merge</goal>
            </goals>
            <configuration>
              <fileSets>
                <fileSet>
                  <directory>${project.build.directory}/jacoco-output/</directory>
                  <includes>
                    <include>*.exec</include>
                  </includes>
                </fileSet>
              </fileSets>
              <destFile>${project.build.directory}/jacoco-output/merged.exec</destFile>
            </configuration>
          </execution>
          <execution>
            <id>create-merged-report</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>report</goal>
            </goals>
            <configuration>
              <dataFile>${project.build.directory}/jacoco-output/merged.exec</dataFile>
              <outputDirectory>${project.reporting.outputDirectory}/jacoco-merged-test-coverage-report</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <excludedGroups>${excludedIntegrationTests}</excludedGroups>
          <forkedProcessTimeoutInSeconds>3600</forkedProcessTimeoutInSeconds>
          <forkCount>${it.forkCount}</forkCount>
          <reuseForks>true</reuseForks>
          <!--suppress UnresolvedMavenProperty -->
          <argLine>${failsafe.jacoco.args}</argLine>
          <skipITs>${skipITs}</skipITs>
          <systemProperties>
            <property>
              <name>java.util.logging.config.file</name>
              <value>src/test/resources/integration-test-logging.properties</value>
            </property>
          </systemProperties>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
          <archive>
            <manifest>
              <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
              <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
            </manifest>
          </archive>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
