<?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.bitbucket.server</groupId>
        <artifactId>bitbucket-it-parent</artifactId>
        <version>8.2.0-m1</version>
    </parent>

    <artifactId>bitbucket-it-resources</artifactId>
    <packaging>atlassian-plugin</packaging>

    <name>Bitbucket Server - Integration Test Resources</name>

    <properties>
        <source.data.dir>src/main/resources/amps-home/standalone</source.data.dir>
        <target.data.dir>${basedir}/target/standalone-home</target.data.dir>
        <!-- logging levels -->
        <level.logger.ROOT>WARN</level.logger.ROOT>
        <level.logger.com.atlassian.stash>INFO</level.logger.com.atlassian.stash>
        <level.logger.com.atlassian.stash.internal.project>WARN</level.logger.com.atlassian.stash.internal.project>
        <level.logger.com.atlassian.stash.internal.scm.git.command>WARN</level.logger.com.atlassian.stash.internal.scm.git.command>
        <!-- additional logging lines e.g.
             <logging.logger.additions>logging.logger.com.foo=WARN${line.separator}logging.logger.com.bar=INFO</logging.logger.additions>
         -->
        <logging.logger.additions />
        <!-- Disable skipping the integration tests. This counters the behaviors of the release-perform-no-tests
             or skipIntegrationTests profiles being activated when running Maven. -->
        <product.version>${project.version}</product.version>
        <skipIntegrationTests>false</skipIntegrationTests>
        <skipITs>false</skipITs>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-it-common</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-page-objects</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.atlassian.plugins.rest</groupId>
            <artifactId>atlassian-rest-common</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</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>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-library</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>log4j-over-slf4j</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.openclover</groupId>
                <artifactId>clover-maven-plugin</artifactId>
                <version>${clover.libversion}</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <configuration>
                    <!-- _Never_ skip the integration tests, even if -DskipTests or -DskipITs is set. An integration
                         test is used to prepare plugin test data and the overall build will fail if it's skipped. -->
                    <skipTests>false</skipTests>
                </configuration>
            </plugin>
            <!-- Copy clustered home resources to target/clustered-home and do jdbc prop replacements -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${target.data.dir}</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${source.data.dir}</directory>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- clean home directory so repeated runs with just the goal 'install' succeed -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <executions>
                    <execution>
                        <id>clean-home-directory</id>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                        <phase>pre-integration-test</phase>
                        <configuration>
                            <excludeDefaultDirectories>true</excludeDefaultDirectories>
                            <filesets>
                                <fileset>
                                    <directory>${project.build.directory}/bitbucket</directory>
                                </fileset>
                            </filesets>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>bitbucket-maven-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <products>
                        <product>
                            <id>bitbucket</id>
                            <instanceId>bitbucket</instanceId>
                            <containerId>${tomcat.containerId}</containerId>
                            <version>${product.version}</version>
                            <dataPath>${target.data.dir}</dataPath>
                            <systemPropertyVariables>
                                <file.encoding>UTF-8</file.encoding>
                                <activeobjects.servicefactory.config.timeout>${activeobjects.servicefactory.config.timeout}</activeobjects.servicefactory.config.timeout>
                                <!-- Move the embedded-elasticsearch home directory out of the Bitbucket home
                                     so it does not get included in the generated home ZIP -->
                                <plugin.embedded-elasticsearch.path.home>${project.build.directory}/embedded-elasticsearch</plugin.embedded-elasticsearch.path.home>
                            </systemPropertyVariables>
                            <startupTimeout>${stash.startup.timeout}</startupTimeout>
                            <libArtifacts>
                                <libArtifact>
                                    <groupId>org.openclover</groupId>
                                    <artifactId>clover</artifactId>
                                    <version>${clover.libversion}</version>
                                </libArtifact>
                                <libArtifact>
                                    <groupId>com.microsoft.sqlserver</groupId>
                                    <artifactId>mssql-jdbc</artifactId>
                                    <version>${mssql-jdbc.libversion}</version>
                                </libArtifact>
                                <libArtifact>
                                    <groupId>com.oracle.jdbc</groupId>
                                    <artifactId>ojdbc8</artifactId>
                                    <version>${oraclejdbc.libversion}</version>
                                </libArtifact>
                                <libArtifact>
                                    <groupId>mysql</groupId>
                                    <artifactId>mysql-connector-java</artifactId>
                                    <version>${mysqljdbc.libversion}</version>
                                </libArtifact>
                                <libArtifact>
                                    <groupId>org.postgresql</groupId>
                                    <artifactId>postgresql</artifactId>
                                    <version>${postgresjdbc.libversion}</version>
                                </libArtifact>
                            </libArtifacts>
                        </product>
                    </products>
                    <!-- _Never_ skip the tests; they are used to build the plugin test data and the overall build
                         will fail if they are skipped. -->
                    <skipITs>false</skipITs>
                    <skipTests>false</skipTests>
                    <systemPropertyVariables>
                        <xvfb.enable>${xvfb.enable}</xvfb.enable>
                        <cargo.servlet.uriencoding>UTF-8</cargo.servlet.uriencoding>
                        <stash.spring.profiles>dev</stash.spring.profiles>
                        <atlassian.dev.mode>false</atlassian.dev.mode>
                        <atlassian.org.osgi.framework.bootdelegation>${atlassian.org.osgi.framework.bootdelegation}</atlassian.org.osgi.framework.bootdelegation>
                        <file.encoding>UTF-8</file.encoding>
                    </systemPropertyVariables>
                </configuration>
                <executions>
                    <execution>
                        <id>snapshot-bitbucket</id>
                        <phase>post-integration-test</phase>
                        <goals><goal>create-home-zip</goal></goals>
                        <configuration>
                            <!-- This goal *attaches* the artifact to the Maven build, so that Maven deploys it
                                 when you use mvn install or mvn deploy. -->
                            <homeZip>${project.build.directory}/home-snapshot.zip</homeZip>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <!-- assemble the mirror bitbucket-home and publish it -->
                    <execution>
                        <id>bitbucket-mirror-home</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
                                <descriptor>src/main/resources/assembly/mirror.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>it.clustered</id>
            <activation>
                <property>
                    <name>it.clustered</name>
                </property>
            </activation>
            <properties>
                <source.data.dir>src/main/resources/amps-home/clustered</source.data.dir>
                <target.data.dir>${basedir}/target/clustered-home</target.data.dir>
                <hazelcast.network.tcpip.members>localhost:5701,localhost:5702</hazelcast.network.tcpip.members>
                <product.version>${node1.version}</product.version>
            </properties>
            <build>
                <plugins>
                    <!-- Drop all existing tables in the Stash schema -->
                    <plugin>
                        <groupId>org.liquibase</groupId>
                        <artifactId>liquibase-maven-plugin</artifactId>
                        <version>${liquibase.version}</version>
                        <executions>
                            <execution>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>dropAll</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
                            <driver>${jdbc.driver}</driver>
                            <url>${jdbc.url}</url>
                            <username>${jdbc.user}</username>
                            <password>${jdbc.password}</password>
                        </configuration>
                        <dependencies>
                            <dependency>
                                <groupId>com.atlassian.bitbucket.server</groupId>
                                <artifactId>bitbucket-dao-impl</artifactId>
                                <version>${project.version}</version>
                            </dependency>
                            <dependency>
                                <groupId>com.microsoft.sqlserver</groupId>
                                <artifactId>mssql-jdbc</artifactId>
                                <version>${mssql-jdbc.libversion}</version>
                            </dependency>
                            <dependency>
                                <groupId>com.oracle.jdbc</groupId>
                                <artifactId>ojdbc8</artifactId>
                                <version>${oraclejdbc.libversion}</version>
                            </dependency>
                            <dependency>
                                <groupId>mysql</groupId>
                                <artifactId>mysql-connector-java</artifactId>
                                <version>${mysqljdbc.libversion}</version>
                            </dependency>
                            <dependency>
                                <groupId>org.postgresql</groupId>
                                <artifactId>postgresql</artifactId>
                                <version>${postgresjdbc.libversion}</version>
                            </dependency>
                        </dependencies>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>it.clustered.local</id>
            <activation>
                <property>
                    <name>it.clustered</name>
                    <value>local</value>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <configuration>
                            <imagesMap>
                                <search>
                                    <run>
                                        <skip>true</skip>
                                    </run>
                                </search>
                                <haproxy>
                                    <run>
                                        <skip>true</skip>
                                    </run>
                                </haproxy>
                            </imagesMap>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>postgres-snapshot</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                                <configuration>
                                    <descriptors>
                                        <descriptor>src/main/resources/assembly/postgres.xml</descriptor>
                                    </descriptors>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
