<?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.whisper</groupId>
        <artifactId>atlassian-whisper-parent</artifactId>
        <version>6.0.16-67a66662</version>
        <relativePath>..</relativePath>
    </parent>

    <artifactId>whisper-delivery</artifactId>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <!-- Import dependency management from Spring Boot -->
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring.boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

<!--
            spring-boot-dependencies overrides version of groovy used by rest-assured.
            rest-assured is imported transitively through atlassian-whisper-testkit.
            This manual override:
            - needs to be updated once rest-assured version is updated
            - might not be needed when spring-boot is updated
-->
            <dependency>
                <groupId>org.codehaus.groovy</groupId>
                <artifactId>groovy-json</artifactId>
                <version>3.0.2</version>
            </dependency>
            <dependency>
                <groupId>org.codehaus.groovy</groupId>
                <artifactId>groovy-xml</artifactId>
                <version>3.0.2</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>whisper-delivery-api</artifactId>
        </dependency>
        <!--
        Spring Boot dependencies shall be provided:
        - the spring-boot-maven-plugin:repackage will still pick them
        - they will not pollute transitional dependencies when other module in this project will depend on whisper-delivery
        -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jersey</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-actuator</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Persistence -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-core</artifactId>
            <version>7.15.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>provided</scope>
            <version>42.4.2</version>
        </dependency>

        <!-- Security -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.ldap</groupId>
            <artifactId>spring-ldap-core</artifactId>
            <version>2.4.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-ldap</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.zapodot</groupId>
            <artifactId>embedded-ldap-junit</artifactId>
            <version>0.5.2</version>
            <scope>test</scope>
        </dependency>


        <!-- Misc -->
        <dependency>
            <groupId>com.google.code.findbugs</groupId>
            <artifactId>jsr305</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>net.logstash.logback</groupId>
            <artifactId>logstash-logback-encoder</artifactId>
            <version>7.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.13</version>
            <scope>provided</scope>
        </dependency>
        <!-- streamhub related -->
        <dependency>
            <groupId>com.atlassian.spring.boot</groupId>
            <artifactId>stream-hub-client</artifactId>
            <version>5.0.23</version>
        </dependency>
        <dependency>
            <groupId>com.atlassian.spring.boot</groupId>
            <artifactId>stream-hub-event-model</artifactId>
            <version>5.0.23</version>
        </dependency>
        <dependency>
            <groupId>com.atlassian.spring-boot.security</groupId>
            <artifactId>asap-client-feign</artifactId>
            <version>6.0.1</version>
            <exclusions>
                <exclusion>
                    <groupId>org.bouncycastle</groupId>
                    <artifactId>bcprov-jdk15on</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <!-- remove this once asap-client-feign depends on httpclient >= 4.5.13 -->
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.13</version>
        </dependency>
        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcprov-jdk15to18</artifactId>
            <version>1.76</version>
        </dependency>



        <!-- Test dependencies -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>atlassian-whisper-testkit</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- Security overriden dependencies -->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-core</artifactId>
            <scope>provided</scope>
            <version>9.0.75</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${spring.boot.version}</version>
                <executions>
                    <execution>
                        <id>fat-jar</id>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <finalName>${project.artifactId}-${project.version}-${git.commit.id.describe}</finalName>
                        </configuration>
                    </execution>
                    <execution>
                        <goals>
                            <goal>build-info</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>pre-integration-test</id>
                        <goals>
                            <goal>start</goal>
                        </goals>
                        <configuration>
                            <skip>${skipTests}</skip>
                        </configuration>
                    </execution>
                    <execution>
                        <id>post-integration-test</id>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                        <configuration>
                            <skip>${skipTests}</skip>
                        </configuration>
                    </execution>
                </executions>
                <configuration combine.self="override">
                    <arguments>
                        <argument>--server.port=${delivery.port}</argument>
                    </arguments>
                   <profiles>
                        <profile>jdbc</profile>
                        <profile>ac_local</profile>
                        <profile>dummy_streamhub</profile>
                    </profiles>
                </configuration>
            </plugin>

            <plugin>
                <groupId>pl.project13.maven</groupId>
                <artifactId>git-commit-id-plugin</artifactId>
                <executions>
                    <execution>
                        <id>git.properties</id>
                        <goals>
                            <goal>revision</goal>
                        </goals>
                        <configuration>
                            <generateGitPropertiesFile>true</generateGitPropertiesFile>
                            <injectAllReactorProjects>true</injectAllReactorProjects>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <finalName>${project.artifactId}-${project.version}-${git.commit.id.describe}</finalName>
                </configuration>
            </plugin>

            <!--integration tests-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <!--because of https://github.com/spring-projects/spring-boot/issues/6254-->
                <version>2.18.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>docker-release</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.5.0</version>
                        <executions>
                            <execution>
                                <id>build-docker-image</id>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <phase>deploy</phase>
                                <configuration>
                                    <executable>docker</executable>
                                    <arguments>
                                        <argument>build</argument>
                                        <argument>-t</argument>
                                        <argument>docker.atl-paas.net/${project.artifactId}:${project.version}-${git.commit.id.describe}</argument>
                                        <argument>--build-arg</argument>
                                        <argument>DELIVERY_PORT=${delivery.port}</argument>
                                        <argument>.</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                            <execution>
                                <id>push-docker-image</id>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <phase>deploy</phase>
                                <configuration>
                                    <executable>docker</executable>
                                    <arguments>
                                        <argument>push</argument>
                                        <argument>docker.atl-paas.net/${project.artifactId}:${project.version}-${git.commit.id.describe}</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <!--don't deploy jar artifact to Maven repository - we are only interested in Docker image-->
                    <plugin>
                        <groupId>org.sonatype.plugins</groupId>
                        <artifactId>nexus-staging-maven-plugin</artifactId>
                        <version>1.6.5-atlassian-2</version>
                        <configuration>
                            <skipNexusStagingDeployMojo>true</skipNexusStagingDeployMojo>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <properties>
        <project.git.version>${project.version}-${git.commit.id.describe}</project.git.version>
    </properties>
</project>
