<?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.oauth2</groupId>
        <artifactId>oauth2-provider-parent</artifactId>
        <version>6.0.0</version>
    </parent>

    <artifactId>oauth2-provider-rest</artifactId>

    <name>Atlassian OAuth 2 Provider - Rest</name>
    <description>Rest Resources for Atlassian OAuth 2 Provider</description>

    <properties>
        <skip-database-docker>false</skip-database-docker>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.atlassian.oauth2</groupId>
            <artifactId>oauth2-common</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>com.atlassian.oauth2</groupId>
            <artifactId>oauth2-provider-api</artifactId>
            <version>${project.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.oauth2</groupId>
            <artifactId>oauth2-client-api</artifactId>
            <version>${project.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.oauth2</groupId>
            <artifactId>oauth2-scopes-api</artifactId>
            <version>${project.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.secrets</groupId>
            <artifactId>atlassian-secrets-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.oauth2</groupId>
            <artifactId>oauth2-provider-core</artifactId>
            <version>${project.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.servlet</groupId>
            <artifactId>jakarta.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.annotation</groupId>
            <artifactId>jakarta.annotation-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.plugins.rest</groupId>
            <artifactId>atlassian-rest-v2-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.ws.rs</groupId>
            <artifactId>jakarta.ws.rs-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.sal</groupId>
            <artifactId>sal-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.plugins</groupId>
            <artifactId>atlassian-plugins-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.xml.bind</groupId>
            <artifactId>jakarta.xml.bind-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.beehive</groupId>
            <artifactId>beehive-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.annotations</groupId>
            <artifactId>atlassian-annotations</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>io.atlassian.util.concurrent</groupId>
            <artifactId>atlassian-util-concurrent</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Test Dependencies -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.test-framework</groupId>
            <artifactId>jersey-test-framework-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.test-framework.providers</groupId>
            <artifactId>jersey-test-framework-provider-grizzly2</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-client</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>tools.jackson.jakarta.rs</groupId>
            <artifactId>jackson-jakarta-rs-json-provider</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>tools.jackson.module</groupId>
            <artifactId>jackson-module-jakarta-xmlbind-annotations</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>net.java.dev.activeobjects</groupId>
            <artifactId>activeobjects-test</artifactId>
            <version>3.2.4</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.activeobjects</groupId>
            <artifactId>activeobjects-core</artifactId>
            <version>3.2.4</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-test-util</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.oauth2</groupId>
            <artifactId>oauth2-provider-core</artifactId>
            <type>test-jar</type>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.oauth2</groupId>
            <artifactId>oauth2-scopes-plugin</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.beehive</groupId>
            <artifactId>beehive-single-node</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.cache</groupId>
            <artifactId>atlassian-cache-memory</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.nimbusds</groupId>
            <artifactId>nimbus-jose-jwt</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.inject</groupId>
            <artifactId>jakarta.inject-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>tools.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>tools.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.inject</groupId>
            <artifactId>jersey-hk2</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents.core5</groupId>
            <artifactId>httpcore5</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <configuration>
                    <excludePackageNames>com.atlassian.oauth2.provider.rest,com.atlassian.oauth2.provider.rest.*</excludePackageNames>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <!-- required to not start the docker database images twice - especially because Oracle takes forever -->
            <id>skip-database-docker</id>
            <properties>
                <skip-database-docker>true</skip-database-docker>
            </properties>
        </profile>
        <profile>
            <id>postgres</id>
            <properties>
                <no.webapp>true</no.webapp>

                <db.name>ao_test</db.name>
                <db.username>ao_user</db.username>
                <db.password>ao_password</db.password>
                <db.port>5432</db.port>
                <docker.image>postgres:10</docker.image>
                <docker.wait.log>PostgreSQL init process complete</docker.wait.log>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.postgresql</groupId>
                    <artifactId>postgresql</artifactId>
                    <version>${postgres.jdbc.version}</version>
                    <scope>test</scope>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>generate-test-sources</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                                <configuration>
                                    <skip>${skip-database-docker}</skip>
                                    <images>
                                        <image>
                                            <name>${docker.image}</name>
                                            <run>
                                                <ports>
                                                    <port>db.port:5432</port>
                                                </ports>
                                                <env>
                                                    <POSTGRES_DB>${db.name}</POSTGRES_DB>
                                                    <POSTGRES_USER>${db.username}</POSTGRES_USER>
                                                    <POSTGRES_PASSWORD>${db.password}</POSTGRES_PASSWORD>
                                                </env>
                                                <wait>
                                                    <log>${docker.wait.log}</log>
                                                    <time>1200000</time>
                                                </wait>
                                                <log>
                                                    <prefix>postgres</prefix>
                                                </log>
                                            </run>
                                        </image>
                                    </images>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <systemPropertyVariables>
                                <jdbc.url>jdbc:postgresql://localhost:${db.port}/${db.name}?loggerLevel=DEBUG</jdbc.url>
                                <jdbc.schema>public</jdbc.schema>
                                <jdbc.user>${db.username}</jdbc.user>
                                <jdbc.password>${db.password}</jdbc.password>
                            </systemPropertyVariables>
                            <includes>
                                <include>**/*ResourceTest.java</include>
                            </includes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>mysql</id>
            <properties>
                <db.name>ao_test</db.name>
                <db.username>ao_user</db.username>
                <db.password>ao_password</db.password>
                <db.schema>ao_schema</db.schema>
                <db.port>3325</db.port>
                <to.db.port>3306</to.db.port>
                <docker.wait.log>starting as process 1</docker.wait.log>
                <docker.image>mysql:8.4</docker.image>
                <db.system.username>root</db.system.username>
                <db.system.password>root</db.system.password>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>com.mysql</groupId>
                    <artifactId>mysql-connector-j</artifactId>
                    <version>${mysql.jdbc.version}</version>
                    <scope>test</scope>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>generate-test-sources</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <skip>${skip-database-docker}</skip>
                            <images>
                                <image>
                                    <name>${docker.image}</name>
                                    <run>
                                        <ports>
                                            <port>${db.port}:${to.db.port}</port>
                                        </ports>
                                        <env>
                                            <MYSQL_DATABASE>${db.name}</MYSQL_DATABASE>
                                            <MYSQL_USER>${db.username}</MYSQL_USER>
                                            <MYSQL_PASSWORD>${db.password}</MYSQL_PASSWORD>
                                            <MYSQL_ROOT_PASSWORD>${db.system.password}</MYSQL_ROOT_PASSWORD>
                                        </env>
                                        <wait>
                                            <log>${docker.wait.log}</log>
                                            <time>120000</time>
                                        </wait>
                                        <log>
                                            <prefix>mysql</prefix>
                                        </log>
                                    </run>
                                </image>
                            </images>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <systemPropertyVariables>
                                <jdbc.url>jdbc:mysql://localhost:${db.port}/${db.name}?autoReconnect=true&amp;enabledTLSProtocols=TLSv1.2</jdbc.url>
                                <jdbc.schema>${db.schema}</jdbc.schema>
                                <jdbc.user>${db.username}</jdbc.user>
                                <jdbc.password>${db.password}</jdbc.password>
                            </systemPropertyVariables>
                            <includes>
                                <include>**/*ResourceTest.java</include>
                            </includes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>sqlserver</id>
            <properties>
                <docker.tag>2019-latest</docker.tag>
                <docker.image>mcr.microsoft.com/mssql/server:${docker.tag}</docker.image>
                <!-- Ready for connection != ready -->
                <docker.wait.log>.*Recovery is complete. This is an informational message only. No user action is required..*</docker.wait.log>
                <db.port>1433</db.port>
                <db.name>ao_test</db.name>
                <!-- This is used for creating database and schema in maven by sql-maven-plugin -->
                <db.url.no.db>jdbc:sqlserver://localhost:${db.port};trustServerCertificate=true</db.url.no.db>
                <!-- These are used by DynamicJdbcConfiguration.buildJdbcConfiguration to build connection -->
                <db.username>sa</db.username>
                <!-- SQL Server requires complex password -->
                <db.password>AO_password12</db.password>
                <db.url>${db.url.no.db};databaseName=${db.name}</db.url>
                <db.schema>ao_schema</db.schema>
            </properties>

            <!-- From now on sqljdbc is default driver as jtds is outdated -->
            <dependencies>
                <dependency>
                    <groupId>com.microsoft.sqlserver</groupId>
                    <artifactId>mssql-jdbc</artifactId>
                    <version>${sqlserver.jdbc.version}</version>
                    <scope>test</scope>
                </dependency>
            </dependencies>

            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>generate-test-sources</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                                <configuration>
                                    <skip>${skip-database-docker}</skip>
                                    <images>
                                        <image>
                                            <name>${docker.image}</name>
                                            <run>
                                                <ports>
                                                    <port>${db.port}:${db.port}</port>
                                                </ports>
                                                <env>
                                                    <SA_PASSWORD>${db.password}</SA_PASSWORD>
                                                    <ACCEPT_EULA>Y</ACCEPT_EULA>
                                                    <MSSQL_PID>Express</MSSQL_PID>
                                                </env>
                                                <wait>
                                                    <log>${docker.wait.log}</log>
                                                    <time>120000</time>
                                                </wait>
                                                <log>
                                                    <prefix>mssql</prefix>
                                                </log>
                                            </run>
                                        </image>
                                    </images>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>sql-maven-plugin</artifactId>
                        <dependencies>
                            <dependency>
                                <groupId>com.microsoft.sqlserver</groupId>
                                <artifactId>mssql-jdbc</artifactId>
                                <version>${sqlserver.jdbc.version}</version>
                            </dependency>
                        </dependencies>

                        <configuration>
                            <username>${db.username}</username>
                            <password>${db.password}</password>
                            <url>${db.url.no.db}</url>
                            <driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver>
                        </configuration>

                        <executions>
                            <execution>
                                <id>create-db</id>
                                <phase>generate-test-sources</phase>

                                <goals>
                                    <goal>execute</goal>
                                </goals>

                                <configuration>
                                    <skip>${skip-database-docker}</skip>
                                    <autocommit>true</autocommit>
                                    <sqlCommand>
                                        CREATE DATABASE ${db.name};
                                        USE ${db.name};
                                        CREATE SCHEMA ${db.schema};
                                    </sqlCommand>
                                    <onError>abort</onError>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <systemPropertyVariables>
                                <jdbc.url>${db.url.no.db};databaseName=${db.name}</jdbc.url>
                                <jdbc.schema>${db.schema}</jdbc.schema>
                                <jdbc.user>${db.username}</jdbc.user>
                                <jdbc.password>${db.password}</jdbc.password>
                            </systemPropertyVariables>
                            <includes>
                                <include>**/*ResourceTest.java</include>
                            </includes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>oracle</id>
            <properties>
                <oracle.jdbc.timezoneAsRegion>false</oracle.jdbc.timezoneAsRegion>
                <db.port>1521</db.port>
                <db.sid>orcl</db.sid>
                <db.url>jdbc:oracle:thin:@localhost:${db.port}:${db.sid}</db.url>
                <db.username>ao_user</db.username>
                <db.password>ao_password</db.password>
                <!-- https://hello.atlassian.net/wiki/spaces/RELENG/pages/137965245/HOWTO+-+Use+Oracle+Docker+images+provided+by+BuildEng -->
                <docker.image>docker.atl-paas.net/buildeng/oracle11g</docker.image>
                <docker.wait.log>(?s).*DATABASE IS READY TO USE.*</docker.wait.log>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>com.oracle.ojdbc</groupId>
                    <artifactId>ojdbc8</artifactId>
                    <version>${oracle.jdbc.version}</version>
                    <scope>test</scope>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>generate-test-sources</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                                <configuration>
                                    <skip>${skip-database-docker}</skip>
                                    <images>
                                        <image>
                                            <name>${docker.image}</name>
                                            <alias>oracle</alias>
                                            <run>
                                                <ports>
                                                    <port>db.port:1521</port>
                                                </ports>
                                                <wait>
                                                    <log>${docker.wait.log}</log>
                                                    <time>1000000</time>
                                                </wait>
                                                <log>
                                                    <prefix>oracle</prefix>
                                                </log>
                                            </run>
                                        </image>
                                    </images>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>sql-maven-plugin</artifactId>
                        <dependencies>
                            <dependency>
                                <groupId>com.oracle.ojdbc</groupId>
                                <artifactId>ojdbc8</artifactId>
                                <version>${oracle.jdbc.version}</version>
                                <scope>runtime</scope>
                            </dependency>
                        </dependencies>

                        <configuration>
                            <username>SYS AS SYSDBA</username>
                            <password>oracle</password>
                            <url>${db.url}</url>
                            <driver>oracle.jdbc.OracleDriver</driver>
                        </configuration>

                        <executions>
                            <execution>
                                <id>create-db</id>
                                <phase>generate-test-sources</phase>

                                <goals>
                                    <goal>execute</goal>
                                </goals>

                                <configuration>
                                    <skip>${skip-database-docker}</skip>
                                    <autocommit>true</autocommit>
                                    <sqlCommand>
                                        DROP USER ${db.username} CASCADE;
                                        CREATE USER ${db.username} IDENTIFIED BY ${db.password} DEFAULT TABLESPACE USERS QUOTA UNLIMITED ON USERS;
                                        GRANT ALL PRIVILEGES TO  ${db.username} WITH ADMIN OPTION;
                                        GRANT CONNECT TO  ${db.username};
                                    </sqlCommand>
                                    <onError>continue</onError>
                                    <driverProperties>oracle.jdbc.timezoneAsRegion=${oracle.jdbc.timezoneAsRegion}</driverProperties>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <systemPropertyVariables>
                                <jdbc.url>${db.url}</jdbc.url>
                                <jdbc.schema>${db.username}</jdbc.schema>
                                <jdbc.user>${db.username}</jdbc.user>
                                <jdbc.password>${db.password}</jdbc.password>
                                <ao.transaction.isolation.level>TRANSACTION_READ_COMMITTED</ao.transaction.isolation.level>
                                <oracle.jdbc.timezoneAsRegion>${oracle.jdbc.timezoneAsRegion}</oracle.jdbc.timezoneAsRegion>
                            </systemPropertyVariables>
                            <includes>
                                <include>**/*ResourceTest.java</include>
                            </includes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>