<?xml version="1.0" encoding="UTF-8"?>
<!--


    Copyright 2021-2025 gematik GmbH

    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.

    *******

    For additional notes and disclaimer from gematik and in case of changes by gematik find details in the "Readme" file.

-->
<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>de.gematik.test</groupId>
    <artifactId>tiger</artifactId>
    <version>4.2.7</version>
    <relativePath>../pom.xml</relativePath>
  </parent>

  <artifactId>tiger-proxy</artifactId>
  <packaging>jar</packaging>
  <name>${project.artifactId}</name>
  <description>tiger-proxy modul of the tiger test platform.</description>
  <properties>
    <build.date>${maven.build.timestamp}</build.date>
    <maven.build.timestamp.format>dd-MM-yyyy HH:mm:ss</maven.build.timestamp.format>
    <!-- Docker image build (see the `docker` profile at the bottom of this pom). Properties
             can be overridden on the command line, e.g. `-Ddocker.image.tag=dev`. The README
             has the full set of recipes. -->
    <docker.image.name>gematik1/tiger-proxy</docker.image.name>
    <docker.image.tag>${project.version}</docker.image.tag>
    <docker.commit.hash>unknown</docker.commit.hash>
    <version.docker-maven-plugin>0.46.0</version.docker-maven-plugin>
  </properties>

  <dependencies>
    <!-- needed to set proxy config of unirest instances -->
    <dependency>
      <groupId>com.konghq</groupId>
      <artifactId>unirest-java-core</artifactId>
    </dependency>
    <dependency>
      <groupId>com.konghq</groupId>
      <artifactId>unirest-modules-jackson</artifactId>
    </dependency>
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
    </dependency>
    <dependency>
      <groupId>de.gematik.test</groupId>
      <artifactId>tiger-java-agent</artifactId>
    </dependency>
    <dependency>
      <groupId>de.gematik.test</groupId>
      <artifactId>tiger-proxy-scrollable-webui</artifactId>
    </dependency>
    <!-- tiger -->
    <dependency>
      <groupId>de.gematik.test</groupId>
      <artifactId>tiger-rbel</artifactId>
    </dependency>
    <!-- Netty -->
    <dependency>
      <groupId>io.netty</groupId>
      <artifactId>netty-buffer</artifactId>
    </dependency>
    <dependency>
      <groupId>io.netty</groupId>
      <artifactId>netty-codec</artifactId>
    </dependency>
    <dependency>
      <groupId>io.netty</groupId>
      <artifactId>netty-codec-http</artifactId>
    </dependency>
    <dependency>
      <groupId>io.netty</groupId>
      <artifactId>netty-codec-http2</artifactId>
    </dependency>
    <dependency>
      <groupId>io.netty</groupId>
      <artifactId>netty-handler</artifactId>
    </dependency>
    <dependency>
      <groupId>io.netty</groupId>
      <artifactId>netty-handler-proxy</artifactId>
    </dependency>
    <dependency>
      <groupId>io.netty</groupId>
      <artifactId>netty-tcnative-boringssl-static</artifactId>
    </dependency>
    <dependency>
      <groupId>io.netty</groupId>
      <artifactId>netty-transport</artifactId>
    </dependency>
    <dependency>
      <groupId>io.rest-assured</groupId>
      <artifactId>rest-assured</artifactId>
    </dependency>
    <dependency>
      <groupId>net.jcip</groupId>
      <artifactId>jcip-annotations</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-jexl3</artifactId>
    </dependency>
    <!-- commons -->
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId>
    </dependency>
    <dependency>
      <groupId>org.bitbucket.b_c</groupId>
      <artifactId>jose4j</artifactId>
    </dependency>
    <dependency>
      <groupId>org.bouncycastle</groupId>
      <artifactId>bcpkix-jdk18on</artifactId>
    </dependency>
    <dependency>
      <groupId>org.bouncycastle</groupId>
      <artifactId>bcprov-jdk18on</artifactId>
    </dependency>
    <dependency>
      <groupId>org.bouncycastle</groupId>
      <artifactId>bctls-jdk18on</artifactId>
    </dependency>
    <dependency>
      <groupId>org.java-websocket</groupId>
      <artifactId>Java-WebSocket</artifactId>
      <version>1.5.6</version>
    </dependency>
    <dependency>
      <groupId>org.pcap4j</groupId>
      <artifactId>pcap4j-core</artifactId>
      <version>1.8.2</version>
    </dependency>
    <dependency>
      <groupId>org.pcap4j</groupId>
      <artifactId>pcap4j-packetfactory-static</artifactId>
      <version>1.8.2</version>
    </dependency>
    <!-- spring -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-websocket</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springdoc</groupId>
      <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
    </dependency>

    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.squareup.okhttp3</groupId>
      <artifactId>okhttp-jvm</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>de.gematik.test</groupId>
      <artifactId>tiger-httpbin</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>de.gematik.test</groupId>
      <artifactId>tiger-test-utils</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.httpcomponents.client5</groupId>
      <artifactId>httpclient5</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.awaitility</groupId>
      <artifactId>awaitility</artifactId>
      <scope>test</scope>
    </dependency>

    <!-- test -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.testcontainers</groupId>
      <artifactId>testcontainers</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.wiremock</groupId>
      <artifactId>wiremock-standalone</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>uk.org.webcompere</groupId>
      <artifactId>system-stubs-core</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>net.bytebuddy</groupId>
      <artifactId>byte-buddy-agent</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>${version.maven-resources-plugin}</version>
        <executions>
          <execution>
            <id>Copy Vue frontend into Spring Boot target static folder</id>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <phase>process-resources</phase>
            <configuration>
              <outputDirectory>${project.build.directory}/classes/static/webui</outputDirectory>
              <resources>
                <resource>
                  <directory>${project.parent.basedir}/tiger-proxy-scrollable-webui/src/frontend/dist</directory>
                  <filtering>false</filtering>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok-maven-plugin</artifactId>
        <version>1.18.20.0</version>
        <executions>
          <execution>
            <goals>
              <goal>delombok</goal>
            </goals>
            <phase>generate-sources</phase>
            <configuration>
              <addOutputDirectory>false</addOutputDirectory>
              <sourceDirectory>src/main/java</sourceDirectory>
              <outputDirectory>${project.build.directory}/delombok</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <!-- stage tiger-java-agent jar into target/ so the Dockerfile (build context = tiger-proxy/)
                     can COPY it into the image as /app/agent.jar -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-tiger-java-agent</id>
            <goals>
              <goal>copy</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>de.gematik.test</groupId>
                  <artifactId>tiger-java-agent</artifactId>
                  <version>${project.version}</version>
                  <type>jar</type>
                  <overWrite>true</overWrite>
                  <outputDirectory>${project.build.directory}</outputDirectory>
                  <destFileName>tiger-java-agent.jar</destFileName>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <!-- create repackaged jar with docker classifier to be executed in docker container -->
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>${version.spring-boot}</version>
        <executions>
          <execution>
            <goals>
              <goal>repackage</goal>
            </goals>
            <configuration>
              <classifier>docker</classifier>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <!-- very pessimistic value for slow environment. Default is 30. Rare errors observed. -->
          <forkedProcessExitTimeoutInSeconds>1000</forkedProcessExitTimeoutInSeconds>
          <forkCount>10</forkCount>
          <threadCount>1</threadCount>
          <reuseForks>true</reuseForks>
          <parallel>classes</parallel>
          <rerunFailingTestsCount>2</rerunFailingTestsCount>
          <argLine>-Djdk.httpclient.allowRestrictedHeaders=host
                        -javaagent:${project.parent.basedir}/tiger-java-agent/target/tiger-java-agent-${project.version}.jar
                        ${surefireJacocoAgent}</argLine>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <!--
      Builds the tiger-proxy Docker image from the existing Dockerfile in this module.
      Activate explicitly so developer machines without a Docker daemon are not affected
      by the default `mvn package` build:

          mvn -Pdocker -pl tiger-proxy -am package
          mvn -Pdocker -pl tiger-proxy docker:build         # only the image (jars must exist)
          mvn -Pdocker -pl tiger-proxy docker:push          # push to the configured registry

      The plugin uses the local Docker daemon (DOCKER_HOST env var honored). The image
      is also picked up by Jenkins' shared-library build (which still calls `docker build`
      directly) - both paths produce the same image because both consume the same
      Dockerfile.
    -->
    <profile>
      <id>docker</id>
      <build>
        <plugins>
          <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>${version.docker-maven-plugin}</version>
            <configuration>
              <images>
                <image>
                  <name>${docker.image.name}:${docker.image.tag}</name>
                  <build>
                    <contextDir>${project.basedir}</contextDir>
                    <dockerFile>Dockerfile</dockerFile>
                    <args>
                      <APP>tiger-proxy</APP>
                      <VERSION>${project.version}</VERSION>
                      <COMMIT_HASH>${docker.commit.hash}</COMMIT_HASH>
                    </args>
                  </build>
                </image>
              </images>
            </configuration>
            <executions>
              <execution>
                <id>build-docker-image</id>
                <goals>
                  <goal>build</goal>
                </goals>
                <phase>package</phase>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
