<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Licensed to the Apache Software Foundation (ASF) under one or more
  ~ contributor license agreements.  See the NOTICE file distributed with
  ~ this work for additional information regarding copyright ownership.
  ~ The ASF licenses this file to you 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/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>${revision}</version>
    <relativePath>../log4j-parent</relativePath>
  </parent>

  <artifactId>log4j-osgi-test</artifactId>

  <name>Apache Log4j OSGi tests</name>
  <description>The Apache Log4j OSGi tests</description>

  <properties>

    <bnd.baseline.skip>true</bnd.baseline.skip>
    <log4j.docgen.skip>true</log4j.docgen.skip>
    <maven.deploy.skip>true</maven.deploy.skip>
    <maven.install.skip>true</maven.install.skip>
    <sign.skip>true</sign.skip>
    <spotbugs.skip>true</spotbugs.skip>

    <!-- dependency versions -->
    <spifly.version>1.3.7</spifly.version>

  </properties>

  <dependencies>
    <dependency>
      <groupId>javax.inject</groupId>
      <artifactId>javax.inject</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.osgi</groupId>
      <artifactId>org.osgi.core</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-1.2-api</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-api</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-api-test</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-core</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-to-jul</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-to-slf4j</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.lmax</groupId>
      <artifactId>disruptor</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.vintage</groupId>
      <artifactId>junit-vintage-engine</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.aries.spifly</groupId>
      <artifactId>org.apache.aries.spifly.dynamic.bundle</artifactId>
      <version>${spifly.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.felix</groupId>
      <artifactId>org.apache.felix.framework</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.eclipse.platform</groupId>
      <artifactId>org.eclipse.osgi</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.ops4j.pax.exam</groupId>
      <artifactId>pax-exam</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.ops4j.pax.exam</groupId>
      <artifactId>pax-exam-container-native</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.ops4j.pax.exam</groupId>
      <artifactId>pax-exam-junit4</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.ops4j.pax.exam</groupId>
      <artifactId>pax-exam-link-assembly</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.ops4j.pax.exam</groupId>
      <artifactId>pax-exam-spi</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>

    <testResources>
      <testResource>
        <!-- Enable variable interpolation in resources -->
        <filtering>true</filtering>
        <directory>src/test/resources</directory>
      </testResource>
    </testResources>

    <plugins>

      <!--
        ~ Unban Logback.
        -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <executions>
          <execution>
            <id>ban-logging-dependencies</id>
            <configuration>
              <rules>
                <bannedDependencies>
                  <includes>
                    <include>ch.qos.logback:*:*:*:test</include>
                  </includes>
                </bannedDependencies>
              </rules>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.ops4j.pax.exam</groupId>
        <artifactId>exam-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>generate-link-files</goal>
            </goals>
            <phase>generate-test-resources</phase>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <configuration>
          <!-- Property files must be encoded in ISO-8859-1 -->
          <propertiesEncoding>ISO-8859-1</propertiesEncoding>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <classpathDependencyExcludes>
            <exclude>org.osgi:org.osgi.core</exclude>
          </classpathDependencyExcludes>
          <systemPropertyVariables>
            <!-- PAX logging has a copy of Log4j2 API-->
            <pax.exam.logging>false</pax.exam.logging>
            <java.protocol.handler.pkgs>org.ops4j.pax.url</java.protocol.handler.pkgs>
            <!-- Used in `osgi.properties -->
            <felix.cache.rootdir>${project.build.directory}</felix.cache.rootdir>
          </systemPropertyVariables>
        </configuration>
        <executions>
          <!-- Split the Felix and Equinox tests to prevent classpath conflicts.
               Both frameworks contain e.g. the `org.apache.felix.resolver` package. -->
          <execution>
            <id>default-test</id>
            <phase>none</phase>
          </execution>
          <execution>
            <id>test-equinox</id>
            <goals>
              <goal>test</goal>
            </goals>
            <configuration>
              <classpathDependencyExcludes combine.children="append">
                <exclude>org.apache.felix:org.apache.felix.framework</exclude>
              </classpathDependencyExcludes>
              <excludes>
                <exclude>org.apache.logging.log4j.osgi.tests.FelixLoadApiBundleTest</exclude>
                <exclude>org.apache.logging.log4j.osgi.tests.DisruptorTest</exclude>
              </excludes>
            </configuration>
          </execution>
          <execution>
            <id>test-equinox-disruptor</id>
            <goals>
              <goal>test</goal>
            </goals>
            <configuration>
              <classpathDependencyExcludes combine.children="append">
                <!-- Ensure that Disruptor is not accidentally loaded from the parent classpath -->
                <exclude>com.lmax.disruptor:disruptor</exclude>
                <exclude>org.apache.felix:org.apache.felix.framework</exclude>
              </classpathDependencyExcludes>
              <includes>
                <include>org.apache.logging.log4j.osgi.tests.DisruptorTest</include>
              </includes>
              <systemPropertyVariables>
                <log4j2.asyncLoggerExceptionHandler>org.apache.logging.log4j.osgi.tests.DisruptorTest$TestExceptionHandler</log4j2.asyncLoggerExceptionHandler>
                <log4j2.contextSelector>org.apache.logging.log4j.core.async.BasicAsyncLoggerContextSelector</log4j2.contextSelector>
              </systemPropertyVariables>
            </configuration>
          </execution>
          <execution>
            <id>test-felix</id>
            <goals>
              <goal>test</goal>
            </goals>
            <configuration>
              <classpathDependencyExcludes combine.children="append">
                <exclude>org.eclipse.platform:org.eclipse.osgi</exclude>
              </classpathDependencyExcludes>
              <excludes>
                <exclude>org.apache.logging.log4j.osgi.tests.EquinoxLoadApiBundleTest</exclude>
                <exclude>org.apache.logging.log4j.osgi.tests.DisruptorTest</exclude>
              </excludes>
            </configuration>
          </execution>
          <execution>
            <id>test-felix-disruptor</id>
            <goals>
              <goal>test</goal>
            </goals>
            <configuration>
              <classpathDependencyExcludes combine.children="append">
                <!-- Ensure that Disruptor is not accidentally loaded from the parent classpath -->
                <exclude>com.lmax.disruptor:disruptor</exclude>
                <exclude>org.eclipse.platform:org.eclipse.osgi</exclude>
              </classpathDependencyExcludes>
              <includes>
                <include>org.apache.logging.log4j.osgi.tests.DisruptorTest</include>
              </includes>
              <systemPropertyVariables>
                <log4j2.asyncLoggerExceptionHandler>org.apache.logging.log4j.osgi.tests.DisruptorTest$TestExceptionHandler</log4j2.asyncLoggerExceptionHandler>
                <log4j2.contextSelector>org.apache.logging.log4j.core.async.BasicAsyncLoggerContextSelector</log4j2.contextSelector>
              </systemPropertyVariables>
            </configuration>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>

  <profiles>

    <!-- Fixes incompatible with Java 8 -->
    <profile>

      <id>java8-incompat-fixes</id>

      <!-- CI uses Java 8 for running tests.
           Hence, we assume CI=Java8 and apply our changes elsewhere.

           One might think why not activate using `<jdk>[16,)` instead?
           This doesn't work, since the match is not against "the JDK running tests", but "the JDK running Maven".
           These two JDKs can differ due to Maven Toolchains.
           See `java8-tests` profile in `/pom.xml` for details. -->
      <activation>
        <property>
          <name>!env.CI</name>
        </property>
      </activation>

      <!-- Illegal access is disabled by default in Java 16 due to JEP-396.
           We are relaxing it for tests. -->
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <argLine>--add-opens java.base/java.net=ALL-UNNAMED</argLine>
            </configuration>
          </plugin>
        </plugins>
      </build>

    </profile>

  </profiles>

</project>
