<?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.atlassian.pom</groupId>
        <artifactId>closedsource-private-pom</artifactId>
        <version>6.3.7</version>
    </parent>

    <!-- NOTE: This groupId and artifactID is fixed because AMPS contains "embedded-elasticsearch-plugin" as a hard-coded string-->
    <!-- See https://bitbucket.org/atlassian/amps/src/f38e44eceeb03ed65a1497c061077631826c05eb/maven-amps-plugin/src/main/java/com/atlassian/maven/plugins/amps/product/BitbucketProductHandler.java?at=master&fileviewer=file-view-default#BitbucketProductHandler.java-74 -->
    <groupId>com.atlassian.bitbucket.search</groupId>
    <artifactId>embedded-elasticsearch-plugin</artifactId>
    <version>9.0.2</version>
    <packaging>atlassian-plugin</packaging>

    <name>Bitbucket Search - Embedded search plugin</name>
    <description>Plugin that starts an embedded OpenSearch node to be used for development purposes only (e.g. in AMPS)</description>

    <scm>
        <connection>scm:git:ssh://git@stash.dev.internal.atlassian.com:7999/STASH/embedded-search-plugin.git</connection>
        <developerConnection>scm:git:ssh://git@stash.dev.internal.atlassian.com:7999/STASH/embedded-search-plugin.git</developerConnection>
        <url>scm:git:http://stash.dev.internal.atlassian.com/git/STASH/embedded-search-plugin.git</url>
        <tag>embedded-elasticsearch-plugin-9.0.2</tag>
    </scm>

    <properties>
        <bitbucket.version>9.3.0</bitbucket.version>
        <amps.version>9.0.6</amps.version>
        <!-- This plugin relies on there being a minimal distribution of OpenSearch existing in packages.atlassian.com
             for Maven to bundle when compiling. It should have been built from the "Verify base distributions" stage in
             https://stash.dev.internal.atlassian.com/projects/STASH/repos/bitbucket-bundled-search's bamboo build.
         -->
        <opensearch-min.version>2.19.1</opensearch-min.version>
        <opensearch-min.atlassian.hosted.version>${opensearch-min.version}-atlassian-hosted</opensearch-min.atlassian.hosted.version>
        <!-- Java 17 is required for Bitbucket 9.0+ -->
        <java.version>17</java.version>
        <skipIntegrationTests>true</skipIntegrationTests>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.atlassian.bitbucket.server</groupId>
                <artifactId>bitbucket-parent</artifactId>
                <version>${bitbucket.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>io.rest-assured</groupId>
                <artifactId>rest-assured</artifactId>
                <version>5.4.0</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.opensearch.distribution.tar</groupId>
                <artifactId>opensearch-min</artifactId>
                <version>${opensearch-min.atlassian.hosted.version}</version>
                <type>tar.gz</type>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <!-- This dependency has to be manually uploaded. See comment above the opensearch-min.version property
             definition for details. -->
        <dependency>
            <groupId>org.opensearch.distribution.tar</groupId>
            <artifactId>opensearch-min</artifactId>
            <type>tar.gz</type>
        </dependency>

        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.sal</groupId>
            <artifactId>sal-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>io.atlassian.util.concurrent</groupId>
            <artifactId>atlassian-util-concurrent</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-compress</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-it-common</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-bundled-opensearch</id>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <phase>generate-resources</phase>
                        <configuration>
                            <excludeTransitive>true</excludeTransitive>
                            <includeGroupIds>org.opensearch.distribution.tar</includeGroupIds>
                            <stripVersion>true</stripVersion>
                            <outputDirectory>${project.build.outputDirectory}/bundle</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <!-- There are no unit tests below this module, only integration tests. Surefire is used to run
                         the unit tests, and Failsafe is used to run the integration tests. So we can fully disable
                         the Surefire plugin below here; it's not necessary. -->
                    <excludes>
                        <exclude>it/**/*.java</exclude>
                    </excludes>
                    <!--
                        The EnvironmentRule currently relies on reflection to get the `m` field of an unmodifiable map
                        so that the tests can modify the environment variables during runtime. However, JDK 17 no
                        longer allows reflective access to private class properties which the `m` field is. Configuring
                        add-opens here is a workaround that allows the tests to continue working in JDK 17 without too
                        much refactoring.
                    -->
                    <argLine>--add-opens java.base/java.util=ALL-UNNAMED</argLine>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <configuration>
                    <skipITs>${skipIntegrationTests}</skipITs>
                    <skipTests>${skipIntegrationTests}</skipTests>
                    <environmentVariables>
                        <JAVA_TOOL_OPTIONS>-Xmx1280m</JAVA_TOOL_OPTIONS>
                    </environmentVariables>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>bitbucket-maven-plugin</artifactId>
                <version>${amps.version}</version>
                <extensions>true</extensions>
                <configuration>
                    <skipITs>${skipIntegrationTests}</skipITs>
                    <skipTests>${skipIntegrationTests}</skipTests>
                    <extractDependencies>false</extractDependencies>
                    <products>
                        <product>
                            <id>bitbucket</id>
                            <instanceId>bitbucket</instanceId>
                            <version>${bitbucket.version}</version>
                            <dataVersion>${bitbucket.version}</dataVersion>
                        </product>
                    </products>
                    <instructions>
                        <Atlassian-Plugin-Key>${project.groupId}.${project.artifactId}</Atlassian-Plugin-Key>
                        <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
                        <Private-Package>
                            com.atlassian.bitbucket.search.internal*
                        </Private-Package>
                        <Export-Package>
                            com.atlassian.bitbucket.search.embedded
                        </Export-Package>
                        <Spring-Context>*</Spring-Context>
                        <Import-Package>
                            *
                        </Import-Package>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>it</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <properties>
                <skipIntegrationTests>false</skipIntegrationTests>
            </properties>
        </profile>
    </profiles>
</project>
