<?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.confluence</groupId>
        <artifactId>confluence-core</artifactId>
        <version>10.2.2</version>
    </parent>

    <artifactId>confluence-opensearch-impl</artifactId>

    <name>Confluence OpenSearch Implementation</name>
    <description>This provides searching and indexing capabilities with OpenSearch</description>

    <properties>
        <opensearch.docker.tag>2.19.0</opensearch.docker.tag>
        <skip.local.aws.tests>true</skip.local.aws.tests>
        <skip.local.docker.tests>${skipTests}</skip.local.docker.tests>
        <skip.testContainers.tests>true</skip.testContainers.tests>
        <spotbugs.excludes>src/etc/findbugs-excludes.xml</spotbugs.excludes>
        <surefire.forkCount>1</surefire.forkCount>
    </properties>

    <dependencies>

        <dependency>
            <groupId>io.github.resilience4j</groupId>
            <artifactId>resilience4j-retry</artifactId>
        </dependency>
        <dependency>
            <groupId>org.opensearch.client</groupId>
            <artifactId>opensearch-java</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.confluence</groupId>
            <artifactId>confluence</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.annotation</groupId>
            <artifactId>jakarta.annotation-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.persistence</groupId>
            <artifactId>jakarta.persistence-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-collections4</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents.core5</groupId>
            <artifactId>httpcore5</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents.core5</groupId>
            <artifactId>httpcore5-h2</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents.client5</groupId>
            <artifactId>httpclient5</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.confluence</groupId>
            <artifactId>confluence-rest-serialization-jackson2</artifactId>
            <version>${project.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.checkerframework</groupId>
            <artifactId>checker-qual</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Dependencies required by IntegrationTestFailedDefaultJournalManager taken in from confluence-core -->
        <dependency>
            <groupId>com.atlassian.confluence</groupId>
            <artifactId>confluence</artifactId>
            <version>${project.version}</version>
            <classifier>tests</classifier>
            <scope>provided</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>apache-client</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>regions</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>auth</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.modzdetector</groupId>
            <artifactId>modz-detector</artifactId>
            <version>${modz.detector.version}</version>
            <scope>test</scope>
        </dependency>
        <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>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.github.stefanbirkner</groupId>
            <artifactId>system-rules</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.opensearch</groupId>
            <artifactId>opensearch-testcontainers</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>localstack</artifactId>
            <version>1.20.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.sal</groupId>
            <artifactId>sal-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.sal</groupId>
            <artifactId>sal-spi</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.sal</groupId>
            <artifactId>sal-spring</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.confluence</groupId>
            <artifactId>confluence-bandana</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.confluence</groupId>
            <artifactId>confluence-not-shippable</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.confluence</groupId>
            <artifactId>confluence-testutils</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-analyzers-common</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-queryparser</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.atlassian.confluence</groupId>
            <artifactId>confluence-core-integration-test-dependencies</artifactId>
            <version>${project.version}</version>
            <type>pom</type>
            <scope>test</scope>
            <!-- would be test-runtime if such a thing existed -->
        </dependency>
        <dependency>
            <groupId>com.atlassian.confluence</groupId>
            <artifactId>confluence-api-impl</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.confluence</groupId>
            <artifactId>confluence-retention</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>opensymphony</groupId>
            <artifactId>propertyset</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <executions>
                    <execution>
                        <!-- This execution runs the ITs against the OpenSearch container started by the docker-maven-plugin -->
                        <id>integration_tests_with_prestarted_container</id>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <phase>integration-test</phase>
                        <configuration>
                            <skip>${skip.local.docker.tests}</skip>
                            <argLine>@{itCoverageAgent}</argLine>
                            <includes>
                                <include>com/atlassian/confluence/plugins/opensearch/**/IntegrationTest*</include>
                            </includes>
                            <systemPropertyVariables combine.children="append">
                                <opensearch.test.url>http://localhost:9200</opensearch.test.url>
                            </systemPropertyVariables>
                        </configuration>
                    </execution>
                    <execution>
                        <!-- This execution runs the ITs against the OpenSearch container started by the TestContainers -->
                        <id>integration_tests_with_testcontainers</id>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <phase>integration-test</phase>
                        <configuration>
                            <skip>${skip.testContainers.tests}</skip>
                            <argLine>@{itCoverageAgent}</argLine>
                            <includes>
                                <include>com/atlassian/confluence/plugins/opensearch/**/IntegrationTest*</include>
                            </includes>
                        </configuration>
                    </execution>
                    <execution>
                        <!-- This execution runs the ITs against OpenSearch+LocalStack containers started by TestContainers -->
                        <id>opensearch_aws_client_integration_tests</id>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <phase>integration-test</phase>
                        <configuration>
                            <systemPropertyVariables combine.children="append">
                                <opensearch.test.use.aws>true</opensearch.test.use.aws>
                            </systemPropertyVariables>
                            <skip>${skip.local.aws.tests}</skip>
                            <argLine>@{itCoverageAgent}</argLine>
                            <includes>
                                <include>com/atlassian/confluence/plugins/opensearch/**/IntegrationTest*</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>test-jar</goal>
                        </goals>
                        <configuration>
                            <skip>false</skip>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <configuration>
                    <skip>${maven.test.skip}</skip>
                    <images>
                        <image>
                            <alias>opensearch</alias>
                            <name>opensearchproject/opensearch:${opensearch.docker.tag}</name>
                            <run>
                                <cmd>
                                    <exec>
                                        <arg>sh</arg>
                                        <arg>-c</arg>
                                        <arg>/usr/share/opensearch/bin/opensearch-plugin install analysis-stempel analysis-kuromoji &amp;&amp; /usr/share/opensearch/opensearch-docker-entrypoint.sh opensearch</arg>
                                    </exec>
                                </cmd>
                                <log>
                                    <enabled>true</enabled>
                                    <file>${project.build.directory}/opensearch.log</file>
                                </log>
                                <ports>
                                    <port>9200:9200</port>
                                    <port>9300:9300</port>
                                </ports>
                                <wait>
                                    <http>
                                        <url>http://localhost:9200</url>
                                    </http>
                                    <time>30000</time>
                                </wait>
                                <env>
                                    <discovery.type>single-node</discovery.type>
                                    <DISABLE_SECURITY_PLUGIN>true</DISABLE_SECURITY_PLUGIN>
                                </env>
                            </run>
                        </image>
                    </images>
                    <skip>${skip.local.docker.tests}</skip>
                </configuration>
                <executions>
                    <execution>
                        <id>start-containers</id>
                        <goals>
                            <goal>start</goal>
                        </goals>
                        <phase>pre-integration-test</phase>
                    </execution>
                    <execution>
                        <id>stop-containers</id>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                        <phase>post-integration-test</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <profiles>
        <profile>
            <id>aws</id>
            <properties>
                <skip.local.docker.tests>true</skip.local.docker.tests>
                <skip.testContainers.tests>true</skip.testContainers.tests>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <systemPropertyVariables combine.children="append">
                                <opensearch.test.aws.host>${opensearch.test.aws.host}</opensearch.test.aws.host>
                            </systemPropertyVariables>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
