<?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.sling</groupId>
        <artifactId>sling-bundle-parent</artifactId>
        <version>65</version>
        <relativePath />
    </parent>

    <artifactId>org.apache.sling.mcp-server</artifactId>
    <version>0.1.2</version>

    <name>Apache Sling MCP Server</name>

    <scm>
        <connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mcp-server.git</connection>
        <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mcp-server.git</developerConnection>
        <tag>org.apache.sling.mcp-server-0.1.2</tag>
        <url>https://github.com/apache/sling-org-apache-sling-mcp-server.git</url>
    </scm>

    <properties>
        <sling.java.version>17</sling.java.version>
        <sling.starter.version>14</sling.starter.version>
        <!-- Run with -Dslingfeature.app.vmOption=-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=30303 for debug mode-->
        <slingfeature.app.vmOption />
        <!-- Directory for legacy variant classes -->
        <legacy.classes.directory>${project.build.directory}/classes-legacy</legacy.classes.directory>
        <!-- Integration test start timeout -->
        <it.startTimeoutSeconds>120</it.startTimeoutSeconds>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.framework</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.resource</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.annotation.bundle</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.annotation.versioning</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.service.component.annotations</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.service.component</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.service.metatype.annotations</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.sling</groupId>
            <artifactId>org.apache.sling.servlets.annotations</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.jetbrains</groupId>
            <artifactId>annotations</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.sling</groupId>
            <artifactId>org.apache.sling.api</artifactId>
            <version>2.27.6</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.sling</groupId>
            <artifactId>org.apache.sling.serviceusermapper</artifactId>
            <version>1.5.8</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.sling</groupId>
            <artifactId>org.apache.sling.engine</artifactId>
            <version>2.14.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.servlet</groupId>
            <artifactId>jakarta.servlet-api</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.jackrabbit</groupId>
            <artifactId>oak-jackrabbit-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.felix</groupId>
            <artifactId>org.apache.felix.http.wrappers</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>io.modelcontextprotocol.sdk</groupId>
            <artifactId>mcp-core</artifactId>
            <version>1.0.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.service.log</artifactId>
            <version>1.3.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.commonmark</groupId>
            <artifactId>commonmark</artifactId>
            <version>0.27.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.commonmark</groupId>
            <artifactId>commonmark-ext-yaml-front-matter</artifactId>
            <version>0.27.0</version>
            <scope>provided</scope>
        </dependency>

        <!-- test dependencies -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>5.20.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <version>3.27.7</version>
            <scope>test</scope>
        </dependency>

        <!-- integration test dependencies -->
        <dependency>
            <groupId>org.apache.sling</groupId>
            <artifactId>org.apache.sling.testing.clients</artifactId>
            <version>3.1.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.ops4j.pax.tinybundles</groupId>
            <artifactId>tinybundles</artifactId>
            <version>4.0.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>biz.aQute.bnd</groupId>
            <artifactId>biz.aQute.bndlib</artifactId>
            <version>${bnd.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.awaitility</groupId>
            <artifactId>awaitility</artifactId>
            <version>4.2.2</version>
            <scope>test</scope>
        </dependency>
        <!-- slf4j simple for IT logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- McpJsonMapperSupplier SPI implementation (Jackson2) needed by MCP client at test runtime -->
        <dependency>
            <groupId>io.modelcontextprotocol.sdk</groupId>
            <artifactId>mcp-json-jackson2</artifactId>
            <version>1.0.0</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.sling</groupId>
                <artifactId>slingfeature-maven-plugin</artifactId>
                <version>1.9.2</version>
                <extensions>true</extensions>
                <configuration>
                    <skipAddFeatureDependencies>true</skipAddFeatureDependencies>
                    <framework>
                        <groupId>org.apache.felix</groupId>
                        <artifactId>org.apache.felix.framework</artifactId>
                        <version>7.0.5</version>
                    </framework>

                    <!--
                        Prepares a feature model aggregate that takes the following features from
                        the Sling Starter:
                        - nosample_base - the base Sling Starter
                        - oak_persistence_sns - SegmentNodeStore persistence for Oak
                        - composum - The Composum Nodes administration tool
                        Notably missing are the slingshot and starter samples
                     -->
                    <aggregates>
                        <aggregate>
                            <classifier>app</classifier>
                            <filesInclude>main.json</filesInclude>
                            <attach>false</attach>
                            <includeArtifact>
                                <groupId>org.apache.sling</groupId>
                                <artifactId>org.apache.sling.starter</artifactId>
                                <classifier>nosample_base</classifier>
                                <version>${sling.starter.version}</version>
                                <type>slingosgifeature</type>
                            </includeArtifact>
                            <includeArtifact>
                                <groupId>org.apache.sling</groupId>
                                <artifactId>org.apache.sling.starter</artifactId>
                                <classifier>oak_persistence_sns</classifier>
                                <version>${sling.starter.version}</version>
                                <type>slingosgifeature</type>
                            </includeArtifact>
                            <includeArtifact>
                                <groupId>org.apache.sling</groupId>
                                <artifactId>org.apache.sling.starter</artifactId>
                                <classifier>starter</classifier>
                                <version>${sling.starter.version}</version>
                                <type>slingosgifeature</type>
                            </includeArtifact>
                            <includeArtifact>
                                <groupId>org.apache.sling</groupId>
                                <artifactId>org.apache.sling.starter</artifactId>
                                <classifier>composum</classifier>
                                <version>${sling.starter.version}</version>
                                <type>slingosgifeature</type>
                            </includeArtifact>
                        </aggregate>
                    </aggregates>
                    <repositories>
                        <repository>
                            <includeClassifier>app</includeClassifier>
                        </repository>
                    </repositories>
                    <scans>
                        <scan>
                            <includeClassifier>app</includeClassifier>
                        </scan>
                    </scans>
                </configuration>
                <executions>
                    <execution>
                        <id>prepare-features</id>
                        <goals>
                            <goal>aggregate-features</goal>
                            <goal>analyse-features</goal>
                        </goals>
                        <phase>prepare-package</phase>
                    </execution>
                    <execution>
                        <id>create-app-repository</id>
                        <goals>
                            <goal>repository</goal>
                        </goals>
                        <phase>package</phase>
                    </execution>
                </executions>
            </plugin>
            <!-- Configure bnd-baseline to skip when no previous version exists. Remove after first release -->
            <plugin>
                <groupId>biz.aQute.bnd</groupId>
                <artifactId>bnd-baseline-maven-plugin</artifactId>
                <configuration>
                    <failOnMissing>false</failOnMissing>
                </configuration>
            </plugin>
            <!-- Reserve a random port for integration tests -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>reserve-network-port</id>
                        <goals>
                            <goal>reserve-network-port</goal>
                        </goals>
                        <phase>pre-integration-test</phase>
                        <configuration>
                            <portNames>
                                <portName>http.port</portName>
                            </portNames>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- Feature Launcher plugin: manual start via 'mvn feature-launcher:start', and lifecycle-bound IT start/stop -->
            <plugin>
                <groupId>org.apache.sling</groupId>
                <artifactId>feature-launcher-maven-plugin</artifactId>
                <version>1.0.4</version>
                <configuration>
                    <launches>
                        <launch>
                            <id>sling-starter-oak-tar</id>
                            <skip>${skipITs}</skip>
                            <featureFile>${project.slingfeature.outputDirectory}/feature-app.json</featureFile>
                            <repositoryUrls>
                                <repositoryUrl>file://${project.build.directory}/artifacts</repositoryUrl>
                            </repositoryUrls>
                            <launcherArguments>
                                <frameworkProperties>
                                    <org.osgi.service.http.port>${http.port}</org.osgi.service.http.port>
                                </frameworkProperties>
                            </launcherArguments>
                            <startTimeoutSeconds>${it.startTimeoutSeconds}</startTimeoutSeconds>
                        </launch>
                    </launches>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>start</goal>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <configuration>
                    <systemPropertyVariables>
                        <sling.http.port>${http.port}</sling.http.port>
                    </systemPropertyVariables>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.rat</groupId>
                <artifactId>apache-rat-plugin</artifactId>
                <configuration>
                    <excludes combine.children="append">
                        <exclude>bnd-legacy.bnd</exclude>
                        <exclude>src/main/appended-resources/META-INF/*</exclude>
                        <exclude>src/main/appended-resources-legacy/META-INF/*</exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <!-- legacy compatibility (slf4j 1.x, javax.servlet) -->
        <profile>
            <id>legacy-compat</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <!-- Append legacy-specific license content to bnd-generated LICENSE/NOTICE -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>append-legacy-license</id>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <phase>prepare-package</phase>
                                <configuration>
                                    <target>
                                        <concat append="true" destfile="${legacy.classes.directory}/META-INF/LICENSE">
                                            <filelist dir="src/main/appended-resources-legacy/META-INF" files="LICENSE" />
                                        </concat>
                                        <concat append="true" destfile="${legacy.classes.directory}/META-INF/NOTICE">
                                            <filelist dir="src/main/appended-resources-legacy/META-INF" files="NOTICE" />
                                        </concat>
                                    </target>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- Configure bnd-maven-plugin to generate an additional jar based on a different bnd file -->
                    <plugin>
                        <groupId>biz.aQute.bnd</groupId>
                        <artifactId>bnd-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>bnd-process-legacy</id>
                                <goals>
                                    <goal>bnd-process</goal>
                                </goals>
                                <configuration>
                                    <bndfile>bnd-legacy.bnd</bndfile>
                                    <manifestPath>${legacy.classes.directory}/META-INF/MANIFEST.MF</manifestPath>
                                    <outputDir>${legacy.classes.directory}</outputDir>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- Configure jar plugin to create legacy variant from classes-legacy -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jar-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>legacy-jar</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                                <configuration>
                                    <classifier>legacy</classifier>
                                    <classesDirectory>${legacy.classes.directory}</classesDirectory>
                                    <archive>
                                        <manifestFile>${legacy.classes.directory}/META-INF/MANIFEST.MF</manifestFile>
                                    </archive>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>
