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

    Copyright 2021 OPS4J.

    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 https://maven.apache.org/xsd/maven-4.0.0.xsd">

	<modelVersion>4.0.0</modelVersion>

	<parent>
		<groupId>org.ops4j.pax</groupId>
		<artifactId>web</artifactId>
		<version>11.0.1</version>
		<relativePath>../pom.xml</relativePath>
	</parent>

	<groupId>org.ops4j.pax.web</groupId>
	<artifactId>pax-web-api</artifactId>
	<packaging>bundle</packaging>

	<name>OPS4J Pax Web - API</name>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<version>${plugin.maven-surefire-plugin}</version>
				<configuration>
					<argLine>--add-opens=java.base/jdk.internal.loader=ALL-UNNAMED</argLine>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-dependency-plugin</artifactId>
				<executions>
					<execution>
						<id>unpack-tomcat-servlet-api</id>
						<phase>generate-resources</phase>
						<goals>
							<goal>unpack</goal>
						</goals>
						<configuration>
							<artifactItems>
								<artifactItem>
									<groupId>org.apache.tomcat</groupId>
									<artifactId>tomcat-servlet-api</artifactId>
								</artifactItem>
							</artifactItems>
							<outputDirectory>${project.build.directory}/unpack-deps/tomcat-servlet-api</outputDirectory>
						</configuration>
					</execution>
					<execution>
						<id>unpack-tomcat-jsp-api</id>
						<phase>generate-resources</phase>
						<goals>
							<goal>unpack</goal>
						</goals>
						<configuration>
							<artifactItems>
								<artifactItem>
									<groupId>org.apache.tomcat</groupId>
									<artifactId>tomcat-jsp-api</artifactId>
								</artifactItem>
							</artifactItems>
							<outputDirectory>${project.build.directory}/unpack-deps/tomcat-jsp-api</outputDirectory>
						</configuration>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<executions>
					<execution>
						<!--
							copy jakarta/servlet/resources and jakarta/servlet/jsp/resources which will be
							available to slightly modified org.apache.tomcat.util.descriptor.DigesterFactory
							Originally Tomcat load these resources through java.lang.Class.getResource() method
							of jakarta.servlet.ServletContext and jakarta.servlet.jsp.JspContext classes
						-->
						<id>copy-selected-resources</id>
						<phase>process-resources</phase>
						<goals>
							<goal>copy-resources</goal>
						</goals>
						<configuration>
							<outputDirectory>${project.build.outputDirectory}/META-INF/resources</outputDirectory>
							<resources>
								<resource>
									<directory>${project.build.directory}/unpack-deps/tomcat-servlet-api/jakarta/servlet/resources</directory>
									<includes>
										<include>*.xsd</include>
										<include>*.dtd</include>
									</includes>
								</resource>
								<resource>
									<directory>${project.build.directory}/unpack-deps/tomcat-jsp-api/jakarta/servlet/jsp/resources</directory>
									<includes>
										<include>*.xsd</include>
										<include>*.dtd</include>
									</includes>
								</resource>
							</resources>
						</configuration>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>org.apache.felix</groupId>
				<artifactId>maven-bundle-plugin</artifactId>
				<extensions>true</extensions>
				<configuration>
					<instructions>
						<Import-Package>
							<!-- Servlet API 6.0+ (JakartaEE 10+) -->
							jakarta.servlet;version="[6,7)",
							jakarta.servlet.annotation;version="[6,7)",
							jakarta.servlet.descriptor;version="[6,7)",
							jakarta.servlet.http;version="[6,7)",

							<!-- OSGi Core R8+ -->
							org.osgi.dto;version="[1.1,2)",
							org.osgi.framework;version="[1.10,2)",
							org.osgi.framework.dto;version="[1.8,2)",
							org.osgi.framework.wiring;version="[1.2,2)",

							<!-- from pax-logging-api -->
							org.slf4j;version="[1.7,3)"
						</Import-Package>
						<Export-Package>
							<!-- pax-web-api -->
							org.ops4j.pax.web.service;version="${pax-web.osgi.version}",
							org.ops4j.pax.web.service.views;version="${pax-web.osgi.version}",
							org.ops4j.pax.web.service.whiteboard;version="${pax-web.osgi.version}",
							org.ops4j.pax.web.utils;version="${pax-web.osgi.version}",

							<!-- re-export OSGi CMPN R7 102 HTTP Service packages, but moved to Pax Web -->
							org.ops4j.pax.web.service.http;version="${pax-web.osgi.version}",

							<!-- OSGi CMPN R8.1 140 Whiteboard Specification for Jakarta™ Servlet -->
							org.osgi.service.servlet.context;version="2.0.0",
							org.osgi.service.servlet.runtime;version="2.0.0",
							org.osgi.service.servlet.runtime.dto;version="2.0.0",
							org.osgi.service.servlet.whiteboard;version="2.0.0",
							org.osgi.service.servlet.whiteboard.annotations;version="2.0.0",
							org.osgi.service.servlet.whiteboard.propertytypes;version="2.0.0",
						</Export-Package>
						<Include-Resource>
							{maven-resources},
							META-INF/resources/=${project.build.outputDirectory}/META-INF/resources/
						</Include-Resource>
						<_contract>!*</_contract>
					</instructions>
				</configuration>
			</plugin>
		</plugins>
	</build>

	<dependencies>

		<!--
			Good place to remind https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
			If we declare dependency with scope:
			 - "compile"
			    - transitive "compile" dependency becomes "compile" as well
			    - transitive "provided" dependency is not visible
			    - transitive "runtime" dependency becomes "runtime" as well
			    - transitive "test" dependency is not visible
			 - "provided"
			    - transitive "compile" dependency becomes "provided"
			    - transitive "provided" dependency is not visible
			    - transitive "runtime" dependency becomes "provided"
			    - transitive "test" dependency is not visible
			 - "runtime"
			    - transitive "compile" dependency becomes "runtime"
			    - transitive "provided" dependency is not visible
			    - transitive "runtime" dependency becomes "runtime"
			    - transitive "test" dependency is not visible
			 - "test"
			    - transitive "compile" dependency becomes "test"
			    - transitive "provided" dependency is not visible
			    - transitive "runtime" dependency becomes "test"
			    - transitive "test" dependency is not visible

			Summarizing:
			 - "compile": all classpaths, propagation to depending projects
			 - "provided": compilation and test classpaths, but no propagation to depending projects
			 - "runtime": not required for compilation, so runtime and test classpaths, propagation to depending projects
			 - "test": test classpath, no propagation

			Some explanations:
			 - having OSGi Core and CMPN as "provided" means (here) that projects depending on pax-web-api will
			   have to add explicit dependencies on OSGi jars if needed
			 - having slf4j-api as "provided" means that projects depending on pax-web-api may provide different
			   library that will satisfy slf4j-api - e.g., pax-logging-api
		-->

		<!-- OSGi -->

		<dependency>
			<groupId>org.osgi</groupId>
			<artifactId>osgi.core</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.osgi</groupId>
			<artifactId>org.osgi.namespace.extender</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.osgi</groupId>
			<artifactId>org.osgi.service.servlet</artifactId>
			<scope>provided</scope>
		</dependency>

		<!-- JakartaEE -->

		<dependency>
			<groupId>jakarta.servlet</groupId>
			<artifactId>jakarta.servlet-api</artifactId>
			<scope>provided</scope>
		</dependency>

		<!-- Logging -->

		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.apache.logging.log4j</groupId>
			<artifactId>log4j-slf4j2-impl</artifactId>
			<scope>test</scope>
		</dependency>

		<!-- Tomcat -->

		<dependency>
			<!--
				This dependency is used to take jakarta.servlet.resources package with XSDs/DTDs into pax-web-api
				to satisfy the DigesterFactory
			-->
			<groupId>org.apache.tomcat</groupId>
			<artifactId>tomcat-servlet-api</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<!--
				This dependency is used to take jakarta.servlet.jsp.resources package with XSDs/DTDs into pax-web-api
				to satisfy the DigesterFactory
			-->
			<groupId>org.apache.tomcat</groupId>
			<artifactId>tomcat-jsp-api</artifactId>
			<scope>provided</scope>
		</dependency>

		<!-- Testing -->


		<dependency>
			<groupId>org.junit.jupiter</groupId>
			<artifactId>junit-jupiter-api</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.junit.jupiter</groupId>
			<artifactId>junit-jupiter-engine</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.assertj</groupId>
			<artifactId>assertj-core</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>commons-io</groupId>
			<artifactId>commons-io</artifactId>
			<scope>test</scope>
		</dependency>

	</dependencies>

</project>
