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

    Copyright 2024 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.

-->
<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.3.1</version>
    <relativePath>../pom.xml</relativePath>
  </parent>

  <artifactId>tiger-standalone-proxy</artifactId>
  <packaging>jar</packaging>
  <name>${project.artifactId}</name>
  <description>tiger-standalone-proxy modul of the tiger test platform.</description>

  <properties>
    <!-- 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`. -->
    <docker.image.name>gematik1/tiger-proxy-image</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>
    <dependency>
      <groupId>de.gematik.test</groupId>
      <artifactId>tiger-proxy</artifactId>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>com.mycila</groupId>
        <artifactId>license-maven-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>
      <!-- no tests need to run as its just repackaging -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${version.maven.surefire}</version>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>
      <!-- We must generate a -javadoc JAR file to publish on Maven Central -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>${version.maven-jar-plugin}</version>
        <executions>
          <execution>
            <id>empty-javadoc-jar</id>
            <goals>
              <goal>jar</goal>
            </goals>
            <phase>package</phase>
            <configuration>
              <classifier>javadoc</classifier>
              <classesDirectory>${project.basedir}/javadoc</classesDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <!-- stage tiger-java-agent jar into target/ so the Dockerfile can COPY it into the image -->
        <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>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>${version.spring-boot}</version>
        <configuration>
          <mainClass>de.gematik.test.tiger.proxy.TigerProxyApplication</mainClass>
        </configuration>
        <executions>
          <execution>
            <id>repackage</id>
            <goals>
              <goal>repackage</goal>
            </goals>
          </execution>
          <execution>
            <id>repackage-docker</id>
            <goals>
              <goal>repackage</goal>
            </goals>
            <configuration>
              <classifier>docker</classifier>
            </configuration>
          </execution>
          <execution>
            <id>build-info</id>
            <goals>
              <goal>build-info</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <!--
      Builds the tiger-proxy Docker image from the 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-standalone-proxy -am package
          mvn -Pdocker -pl tiger-standalone-proxy docker:build
          mvn -Pdocker -pl tiger-standalone-proxy docker:push
    -->
    <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>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>
