<?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-pom</artifactId>
        <version>5.0.9</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>7.0.0</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-elasticsearch-plugin.git</connection>
        <developerConnection>scm:git:ssh://git@stash.dev.internal.atlassian.com:7999/STASH/embedded-elasticsearch-plugin.git</developerConnection>
        <url>scm:git:http://stash.dev.internal.atlassian.com/git/STASH/embedded-elasticsearch-plugin.git</url>
        <tag>embedded-elasticsearch-plugin-7.0.0</tag>
    </scm>

    <properties>
        <bitbucket.version>7.18.0</bitbucket.version>
        <amps.version>8.0.0</amps.version>
        <!-- This plugin relies on there being a minimal distribution of OpenSearch existing in packages.atlassian.com
             for Maven to bundle when compiling. A script exists in the Bitbucket Server repository at
             /etc/misc/deploy-new-opensearch.sh which deploys a new version of OpenSearch to packages.atlassian.com.
             Before bumping the version here, run the script and pass the desired version _along with the min flag_.
         -->
        <opensearch-min.version>1.2.0</opensearch-min.version>
        <opensearch-min.atlassian.hosted.version>${opensearch-min.version}-atlassian-hosted</opensearch-min.atlassian.hosted.version>
        <java.version>1.8</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>3.2.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>com.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>
                </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>
                            com.atlassian.bitbucket.server,
                            org.slf4j.*,
                            org.springframework.beans.factory,
                            org.springframework.core.io,
                            com.atlassian.*,
                            com.google.common.base,
                            com.google.common.collect,
                            javax.*,
                            org.apache.commons.compress.*,
                            org.apache.commons.lang3.*
                        </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>
