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

    Copyright Kroxylicious Authors.

    Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0

-->
<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>io.kroxylicious</groupId>
        <artifactId>kroxylicious-parent</artifactId>
        <version>0.18.0</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <artifactId>kroxylicious-app</artifactId>
    <packaging>jar</packaging>

    <name>Proxy application</name>
    <description>A runnable proxy application. Provides the main() method.</description>

    <dependencies>
        <!-- project dependencies - runtime and compile -->
        <dependency>
            <groupId>io.kroxylicious</groupId>
            <artifactId>kroxylicious-runtime</artifactId>
        </dependency>
        <dependency>
            <groupId>io.kroxylicious</groupId>
            <artifactId>kroxylicious-api</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>io.kroxylicious</groupId>
            <artifactId>kroxylicious-annotations</artifactId>
        </dependency>

        <!-- project dependencies - test -->
        <dependency>
            <groupId>io.kroxylicious</groupId>
            <artifactId>kroxylicious-integration-test-support</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.kroxylicious.testing</groupId>
            <artifactId>testing-api</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.kroxylicious.testing</groupId>
            <artifactId>testing-junit5-extension</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- third party dependencies - runtime and compile -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
        <dependency>
            <groupId>info.picocli</groupId>
            <artifactId>picocli</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-jdk-platform-logging</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j2-impl</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.lmax</groupId>
            <artifactId>disruptor</artifactId>
            <scope>runtime</scope>
        </dependency>
        <!--support yaml logging configuration-->
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-yaml</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka-clients</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.github.spotbugs</groupId>
            <artifactId>spotbugs-annotations</artifactId>
        </dependency>

        <!-- third party dependencies - test -->
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka_2.13</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <configuration>
                    <environmentVariables>
                        <!-- https://github.com/containers/podman/issues/7927#issuecomment-731525556 - required for testcontainers/podman support -->
                        <TESTCONTAINERS_RYUK_DISABLED>true</TESTCONTAINERS_RYUK_DISABLED>
                    </environmentVariables>
                    <systemPropertyVariables>
                        <io.netty.leakDetection.level>paranoid</io.netty.leakDetection.level>
                        <container.logs.dir>${project.build.directory}/container-logs/</container.logs.dir>
                    </systemPropertyVariables>
                    <runOrder>random</runOrder>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
            <resource>
                <directory>src/main/templates</directory>
                <filtering>true</filtering>
                <targetPath>META-INF</targetPath>
            </resource>
        </resources>
    </build>
    <profiles>
        <profile>
            <id>dist</id>
            <properties>
                <io.kroxylicious.proxy.image.name>quay.io/kroxylicious/proxy:${project.version}</io.kroxylicious.proxy.image.name>
                <io.kroxylicious.proxy.image.archive>target/kroxylicious-proxy.img.tar.gz</io.kroxylicious.proxy.image.archive>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>unpack-netty-native-libs</id>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>unpack-dependencies</goal>
                                </goals>
                                <configuration>
                                    <includeArtifactIds>netty-transport-native-epoll,netty-transport-native-unix-common,netty-transport-native-io_uring,netty-transport-native-kqueue</includeArtifactIds>
                                    <outputDirectory>${project.build.directory}/libs/native/netty</outputDirectory>
                                    <!-- derived form snappy's resource-config.json -->
                                    <includes>**/*.dylib,**/*.jnilib,**/*.so,**/*.a</includes>
                                    <fileMappers>
                                        <org.codehaus.plexus.components.io.filemappers.FlattenFileMapper/>
                                    </fileMappers>
                                </configuration>
                            </execution>
                            <execution>
                                <id>unpack-snappy-native-libs</id>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>unpack-dependencies</goal>
                                </goals>
                                <configuration>
                                    <includeArtifactIds>snappy-java</includeArtifactIds>
                                    <outputDirectory>${project.build.directory}/libs/native/snappy</outputDirectory>
                                    <!-- derived form snappy's resource-config.json -->
                                    <includes>**/*.dylib,**/*.jnilib,**/*.so,**/*.a</includes>
                                    <!-- when built into the container paths are cases sensitive and the container build variables for arch and platform  are lower case-->
                                    <fileMappers>
                                        <org.codehaus.plexus.components.io.filemappers.RegExpFileMapper>
                                            <pattern>AIX</pattern>
                                            <replacement>aix</replacement>
                                        </org.codehaus.plexus.components.io.filemappers.RegExpFileMapper>
                                        <org.codehaus.plexus.components.io.filemappers.RegExpFileMapper>
                                            <pattern>FreeBSD</pattern>
                                            <replacement>freebsd</replacement>
                                        </org.codehaus.plexus.components.io.filemappers.RegExpFileMapper>
                                        <org.codehaus.plexus.components.io.filemappers.RegExpFileMapper>
                                            <pattern>Linux</pattern>
                                            <replacement>linux</replacement>
                                        </org.codehaus.plexus.components.io.filemappers.RegExpFileMapper>
                                        <org.codehaus.plexus.components.io.filemappers.RegExpFileMapper>
                                            <pattern>Mac</pattern>
                                            <replacement>darwin</replacement>
                                        </org.codehaus.plexus.components.io.filemappers.RegExpFileMapper>
                                        <org.codehaus.plexus.components.io.filemappers.RegExpFileMapper>
                                            <pattern>SunOS</pattern>
                                            <replacement>sunos</replacement>
                                        </org.codehaus.plexus.components.io.filemappers.RegExpFileMapper>
                                        <org.codehaus.plexus.components.io.filemappers.RegExpFileMapper>
                                            <pattern>Windows</pattern>
                                            <replacement>windows</replacement>
                                        </org.codehaus.plexus.components.io.filemappers.RegExpFileMapper>
                                    </fileMappers>
                                </configuration>
                            </execution>
                            <execution>
                                <id>unpack-zstd-native-libs</id>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>unpack-dependencies</goal>
                                </goals>
                                <configuration>
                                    <includeArtifactIds>zstd-jni</includeArtifactIds>
                                    <outputDirectory>${project.build.directory}/libs/native/zstd-jni</outputDirectory>
                                    <!-- derived form snappy's resource-config.json -->
                                    <includes>**/*.dylib,**/*.jnilib,**/*.so,**/*.a</includes>
                                </configuration>
                            </execution>
                            <execution>
                                <id>unpack-lz4-native-libs</id>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>unpack-dependencies</goal>
                                </goals>
                                <configuration>
                                    <includeArtifactIds>lz4-java</includeArtifactIds>
                                    <outputDirectory>${project.build.directory}/libs/native/lz4-java</outputDirectory>
                                    <!-- derived form snappy's resource-config.json -->
                                    <includes>**/*.dylib,**/*.jnilib,**/*.so,**/*.a</includes>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <configuration>
                            <descriptors>
                                <descriptor>src/assembly/binary-distribution.xml</descriptor>
                            </descriptors>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                        </configuration>
                        <executions>
                            <execution>
                                <id>make-assembly</id> <!-- this is used for inheritance merges -->
                                <phase>package</phase> <!-- bind to the packaging phase -->
                                <goals>
                                    <goal>single</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                    <groupId>io.fabric8</groupId>
                    <artifactId>docker-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <goals>
                                <goal>build</goal>
                                <goal>save</goal>
                            </goals>
                            <phase>package</phase>
                            <configuration>
                                <skip>${skipContainerImageBuild}</skip>
                                <images>
                                    <image>
                                        <name>${io.kroxylicious.proxy.image.name}</name>
                                        <alias>pxy</alias>
                                        <build>
                                            <dockerFile>src/main/docker/proxy.dockerfile</dockerFile>
                                            <contextDir>${project.basedir}</contextDir>
                                            <args>
                                                <KROXYLICIOUS_VERSION>${project.version}</KROXYLICIOUS_VERSION>
                                            </args>
                                        </build>
                                    </image>
                                </images>
                                <saveFile>${io.kroxylicious.proxy.image.archive}</saveFile>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>withAdditionalFilters</id>
            <activation>
                <property>
                    <name>withAdditionalFilters</name>
                    <value>!false</value>
                </property>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>io.kroxylicious</groupId>
                    <artifactId>kroxylicious-multitenant</artifactId>
                    <scope>runtime</scope>
                </dependency>
                <dependency>
                    <groupId>io.kroxylicious</groupId>
                    <artifactId>kroxylicious-record-validation</artifactId>
                    <scope>runtime</scope>
                </dependency>
                <dependency>
                    <groupId>io.kroxylicious</groupId>
                    <artifactId>kroxylicious-simple-transform</artifactId>
                    <scope>runtime</scope>
                </dependency>
                <dependency>
                    <groupId>io.kroxylicious</groupId>
                    <artifactId>kroxylicious-record-encryption</artifactId>
                    <scope>runtime</scope>
                </dependency>
                <dependency>
                    <groupId>io.kroxylicious</groupId>
                    <artifactId>kroxylicious-kms-provider-hashicorp-vault</artifactId>
                    <scope>runtime</scope>
                </dependency>
                <dependency>
                    <groupId>io.kroxylicious</groupId>
                    <artifactId>kroxylicious-kms-provider-aws-kms</artifactId>
                    <scope>runtime</scope>
                </dependency>
                <dependency>
                    <groupId>io.kroxylicious</groupId>
                    <artifactId>kroxylicious-kms-provider-azure-key-vault-kms</artifactId>
                    <scope>runtime</scope>
                </dependency>
                <dependency>
                    <groupId>io.kroxylicious</groupId>
                    <artifactId>kroxylicious-kms-provider-fortanix-dsm</artifactId>
                    <scope>runtime</scope>
                </dependency>
                <dependency>
                    <groupId>io.kroxylicious</groupId>
                    <artifactId>kroxylicious-oauthbearer-validation</artifactId>
                    <scope>runtime</scope>
                </dependency>
                <dependency>
                    <groupId>io.kroxylicious</groupId>
                    <artifactId>kroxylicious-sasl-inspection</artifactId>
                    <scope>runtime</scope>
                </dependency>
                <dependency>
                    <groupId>io.kroxylicious</groupId>
                    <artifactId>kroxylicious-authorization</artifactId>
                    <scope>runtime</scope>
                </dependency>
                <dependency>
                    <groupId>io.kroxylicious</groupId>
                    <artifactId>kroxylicious-authorizer-acl</artifactId>
                    <scope>runtime</scope>
                </dependency>
            </dependencies>
        </profile>
    </profiles>
</project>