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

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

    <properties>
        <libs.dir>libs</libs.dir>
        <ApiCompatability.ReferenceVersion>0.24.0</ApiCompatability.ReferenceVersion>
        <ApiCompatability.EnforceForMajorVersionZero>true</ApiCompatability.EnforceForMajorVersionZero>
    </properties>

    <name>Kroxylicious API</name>
    <description>API for filters, and some dependant APIs</description>

    <dependencies>
        <!-- third party dependencies - runtime and compile -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.spotbugs</groupId>
            <artifactId>spotbugs-annotations</artifactId>
        </dependency>
        <!-- Compile-scope dependencies of the vendored io.kroxylicious.kafka.common.* support
             classes. jackson-databind backs the generated *JsonConverter classes; jackson-core is
             also referenced directly (e.g. MessageUtil implements a jackson-core TreeNode-based
             interface) rather than only transitively through jackson-databind, so it needs its own
             explicit declaration — an explicit scope on a transitive dependency overrides Maven's
             mediation, so declaring it test-scoped (it's also used by the forked MessageUtilTest)
             would have hidden it from the main compile classpath. slf4j-api and the native codecs
             back the vendored compress/record code. kafka-clients brings the codecs transitively at
             runtime only, so they are declared here to lift them onto the compile classpath. See
             tools/kafka-vendoring/README.md. -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.luben</groupId>
            <artifactId>zstd-jni</artifactId>
        </dependency>
        <dependency>
            <groupId>at.yawk.lz4</groupId>
            <artifactId>lz4-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.xerial.snappy</groupId>
            <artifactId>snappy-java</artifactId>
        </dependency>

        <!-- third party dependencies - test -->
        <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j2-impl</artifactId>
            <scope>test</scope>
        </dependency>
        <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.junit.jupiter</groupId>
            <artifactId>junit-jupiter-params</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.kroxylicious</groupId>
            <artifactId>kroxylicious-annotations</artifactId>
        </dependency>
        <dependency>
            <groupId>io.kroxylicious</groupId>
            <artifactId>kroxylicious-identity-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-message-specs</id>
                        <phase>generate-sources</phase>
                    </execution>
                    <execution>
                        <id>unpack-data-class-message-specs</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.apache.kafka</groupId>
                                    <artifactId>kafka-clients</artifactId>
                                    <version>${kafka.message-spec.version}</version>
                                    <overWrite>false</overWrite>
                                    <includes>common/message/**/*.json</includes>
                                    <outputDirectory>${project.build.directory}/data-class-message-specs
                                    </outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- Generate io.kroxylicious.kafka.common.message.*Data classes from the Kafka
                 protocol JSON specs on every build. The forked generator is a plugin-scoped
                 dependency so it stays off this module's own dependency graph. Declared after
                 unpack-data-class-message-specs so it runs after the specs are unpacked within the
                 generate-sources phase. -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>generate-data-classes</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <mainClass>io.kroxylicious.kafka.message.MessageGenerator</mainClass>
                            <includePluginDependencies>true</includePluginDependencies>
                            <arguments>
                                <argument>-p</argument>
                                <argument>io.kroxylicious.kafka.common.message</argument>
                                <argument>-i</argument>
                                <argument>${project.build.directory}/data-class-message-specs/common/message</argument>
                                <!-- Write into the package directory so the generated tree has a
                                     normal Java layout. This keeps the added source root at
                                     .../kafka-messages while the files live under their declared
                                     io.kroxylicious.kafka.common.message package, which lets Javadoc
                                     exclude them by package name (see maven-javadoc-plugin config). -->
                                <argument>-o</argument>
                                <argument>
                                    ${project.build.directory}/generated-sources/kafka-messages/io/kroxylicious/kafka/common/message
                                </argument>
                                <argument>-t</argument>
                                <argument>ApiMessageTypeGenerator</argument>
                                <argument>-m</argument>
                                <argument>MessageDataGenerator</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <!-- Generate the owned io.kroxylicious.kafka.common.protocol.ApiKeys enum as a
                         veneer over the generated ApiMessageType. ApiKeys lives in the protocol
                         package (mirroring Kafka), which differs from ApiMessageType's message
                         package, so it needs its own MessageGenerator run with a distinct -p/-o. -->
                    <execution>
                        <id>generate-api-keys</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <mainClass>io.kroxylicious.kafka.message.MessageGenerator</mainClass>
                            <includePluginDependencies>true</includePluginDependencies>
                            <arguments>
                                <argument>-p</argument>
                                <argument>io.kroxylicious.kafka.common.protocol</argument>
                                <argument>-i</argument>
                                <argument>${project.build.directory}/data-class-message-specs/common/message</argument>
                                <argument>-o</argument>
                                <argument>
                                    ${project.build.directory}/generated-sources/kafka-messages/io/kroxylicious/kafka/common/protocol
                                </argument>
                                <argument>-t</argument>
                                <argument>ApiKeysGenerator</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>io.kroxylicious</groupId>
                        <artifactId>kroxylicious-kafka-message-generator</artifactId>
                        <version>${project.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
            <!-- This actually shouldn't be needed, as the plug-in itself adds that directory as a source directory;
                 Unfortunately, Eclipse/M2E doesn't reliably pick it up without this helper plug-in -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${project.build.directory}/generated-sources/krpc</source>
                                <source>${project.build.directory}/generated-sources/kafka-messages</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- The vendored/forked io.kroxylicious.kafka.* classes (see tools/kafka-vendoring —
                 io.kroxylicious.kafka.common.* support classes under src/main, plus their forked
                 Apache Kafka unit tests and test-support helper under src/test) are copied verbatim
                 from Apache Kafka and carry ASF copyright headers; give them their own licenseSet
                 with the ASF header instead of the parent's Kroxylicious header. combine.self="override"
                 prevents the parent's licenseSet from merging in at module scope, so the Kroxylicious
                 set below has to be restated. Mirrors kroxylicious-kafka-message-generator/pom.xml,
                 which is fully forked and so needs no second (Kroxylicious) licenseSet. -->
            <plugin>
                <groupId>com.mycila</groupId>
                <artifactId>license-maven-plugin</artifactId>
                <configuration combine.self="override">
                    <strictCheck>true</strictCheck>
                    <licenseSets>
                        <licenseSet>
                            <header>${rootdir}/etc/license.txt</header>
                            <excludes>
                                <exclude>src/main/java/io/kroxylicious/kafka/**</exclude>
                                <exclude>src/test/java/io/kroxylicious/kafka/**</exclude>
                                <!-- The raw ASF header document itself; a header file is never
                                     checked against itself, but that's per-licenseSet, so with two
                                     sets it still needs excluding from this one explicitly. -->
                                <exclude>etc/asf-license.txt</exclude>
                            </excludes>
                        </licenseSet>
                        <licenseSet>
                            <header>${project.basedir}/etc/asf-license.txt</header>
                            <includes>
                                <include>src/main/java/io/kroxylicious/kafka/**</include>
                                <include>src/test/java/io/kroxylicious/kafka/**</include>
                            </includes>
                        </licenseSet>
                    </licenseSets>
                </configuration>
            </plugin>
            <!-- The vendored (io.kroxylicious.kafka.common.*) and generated (…​.common.message.*)
                 Kafka protocol classes carry Kafka's own Javadoc, which does not satisfy this
                 project's doclint/failOnWarnings gate and is not something we publish API docs for.
                 Exclude the whole io.kroxylicious.kafka.* tree; the public Filter API
                 (io.kroxylicious.proxy.filter) is unaffected. (The maven-javadoc-plugin only
                 processes src/main by default, so this doesn't need a src/test equivalent.) -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <configuration>
                    <excludePackageNames>io.kroxylicious.kafka:io.kroxylicious.kafka.*</excludePackageNames>
                </configuration>
            </plugin>
            <plugin>
                <groupId>io.kroxylicious</groupId>
                <artifactId>kroxylicious-krpc-plugin</artifactId>
                <executions>
                    <execution>
                        <id>generate-filters</id>
                        <goals>
                            <goal>generate-single</goal>
                        </goals>
                        <phase>generate-sources</phase>
                        <configuration>
                            <messageSpecDirectory>${project.build.directory}/message-specs/common/message
                            </messageSpecDirectory>
                            <messageSpecFilter>*{Request,Response}.json</messageSpecFilter>
                            <templateDirectory>${project.basedir}/src/main/templates</templateDirectory>
                            <templateNames>Kproxy/Filter.ftl</templateNames>
                            <!--suppress UnresolvedMavenProperty -->
                            <outputFilePattern>${messageSpecName}Filter.java</outputFilePattern>
                            <outputPackage>io.kroxylicious.proxy.filter</outputPackage>
                            <outputDirectory>${project.build.directory}/generated-sources/krpc</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>qa</id>
            <activation>
                <property>
                    <name>!quick</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.github.siom79.japicmp</groupId>
                        <artifactId>japicmp-maven-plugin</artifactId>
                        <version>0.26.2</version>
                        <configuration>
                            <oldVersion>
                                <!-- specify the old version directly so its deterministic -->
                                <dependency>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>${project.artifactId}</artifactId>
                                    <version>${ApiCompatability.ReferenceVersion}</version>
                                    <type>jar</type>
                                </dependency>
                            </oldVersion>
                            <parameter>
                                <excludes>
                                    <!-- Type migration from org.apache.kafka.* to io.kroxylicious.kafka.*:
                                         all filter/router interfaces have method signature changes that are
                                         intentional and expected as part of this migration. -->
                                    <exclude>io.kroxylicious.proxy.filter</exclude>
                                    <exclude>io.kroxylicious.proxy.filter.metadata</exclude>
                                    <exclude>io.kroxylicious.proxy.router</exclude>
                                    <exclude>io.kroxylicious.proxy.authentication.Subject#allPrincipalsOfType(java.lang.Class)</exclude>
                                    <exclude>io.kroxylicious.proxy.authentication.Subject#isAnonymous()</exclude>
                                    <exclude>io.kroxylicious.proxy.authentication.Subject#uniquePrincipalOfType(java.lang.Class)</exclude>
                                </excludes>
                                <accessModifier>public</accessModifier>
                                <breakBuildBasedOnSemanticVersioning>true</breakBuildBasedOnSemanticVersioning>
                                <breakBuildOnBinaryIncompatibleModifications>false
                                </breakBuildOnBinaryIncompatibleModifications>
                                <breakBuildBasedOnSemanticVersioningForMajorVersionZero>
                                    ${ApiCompatability.EnforceForMajorVersionZero}
                                </breakBuildBasedOnSemanticVersioningForMajorVersionZero>
                            </parameter>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>verify</phase>
                                <goals>
                                    <goal>cmp</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
