<?xml version="1.0" encoding="UTF-8"?>
<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>com.adobexp.loki</groupId>
        <artifactId>aem-loki-integrator</artifactId>
        <version>1.0.7</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <artifactId>aem-loki-integrator.loki4j</artifactId>
    <packaging>jar</packaging>
    <name>AEM Loki Integrator - loki4j Fragment Bundle</name>
    <description>
        Repackages the loki-logback-appender (loki4j) as an OSGi fragment of
        org.apache.sling.commons.log. Attaching it to the Sling log host
        bundle makes the loki4j classes (and their Logback SPI references)
        visible to the Logback context without the loki4j classes ever being
        loaded by our own customer bundles.
    </description>

    <dependencies>
        <dependency>
            <groupId>com.github.loki4j</groupId>
            <artifactId>loki-logback-appender</artifactId>
        </dependency>

        <!-- Optional runtime dependencies of loki-logback-appender. Declared
             here so bnd can see them while building the fragment's
             Import-Package, but they are all imported with
             resolution:=optional. -->
        <dependency>
            <groupId>org.xerial.snappy</groupId>
            <artifactId>snappy-java</artifactId>
            <version>1.1.10.5</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-core</artifactId>
            <version>1.11.0</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.google.protobuf</groupId>
            <artifactId>protobuf-java</artifactId>
            <version>3.21.12</version>
            <optional>true</optional>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>biz.aQute.bnd</groupId>
                <artifactId>bnd-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>bnd-process</id>
                        <goals>
                            <goal>bnd-process</goal>
                        </goals>
                        <configuration>
                            <bnd><![CDATA[
Bundle-SymbolicName: ${project.artifactId}
Bundle-Name: ${project.name}
Bundle-Version: ${project.version}
Fragment-Host: org.apache.sling.commons.log

# As a fragment of org.apache.sling.commons.log we share the host bundle's
# class loader. The host privately embeds Logback, so the loki4j classes
# we repackage here can reach ch.qos.logback.* directly through the host -
# we must NOT advertise those packages in Import-Package, both to keep the
# bundle wiring consistent and because AEMaaCS Code Quality (rule S1874)
# treats any ch.qos.logback.* Import-Package header as a vulnerability.
Export-Package: com.github.loki4j.logback,\
 com.github.loki4j.pkg.*,\
 com.github.loki4j.util.*
Import-Package: !ch.qos.logback.*,\
 org.xerial.snappy;resolution:=optional,\
 io.micrometer.core.instrument.*;resolution:=optional,\
 com.google.protobuf;resolution:=optional,\
 com.github.loki4j.pkg.google.protobuf;resolution:=optional,\
 com.github.loki4j.pkg.loki.protobuf;resolution:=optional,\
 *

# Keep the manifest free of 'uses:="ch.qos.logback..."' clauses that bnd
# would otherwise generate on Export-Package entries. No downstream bundle
# imports these exports from us (they go through the host), so a uses
# constraint is not needed and the ch.qos.logback.* tokens trip S1874.
-nouses: true

Embed-Dependency: loki-logback-appender;scope=compile|runtime
-includeresource: @loki-logback-appender-${loki4j.version}.jar
]]></bnd>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
