<?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-parent</artifactId>
        <version>7.18.0-m6</version>
    </parent>

    <artifactId>bitbucket-it-parent</artifactId>
    <packaging>pom</packaging>

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

    <modules>
        <module>common</module>
        <module>page-objects</module>
        <module>hosting-test-util</module>
        <module>dcm</module>
        <module>javascript-tests</module>
        <module>licensed-plugin</module>
        <module>mirror</module>
        <module>test-support-plugin</module>
    </modules>

    <properties>
        <license.scope>test</license.scope>
        <atlassian.org.osgi.framework.bootdelegation>
            jdk.*,
            weblogic,weblogic.*,
            META-INF.services,
            com.yourkit,com.yourkit.*,
            com.chronon,com.chronon.*,
            com.jprofiler,com.jprofiler.*,
            org.apache.xerces,org.apache.xerces.*,
            org.apache.xalan,org.apache.xalan.*,
            org.apache.xml.serializer,
            sun.*,
            com.sun.xml.bind.v2,
            com.icl.saxon,
            com_atlassian_clover,
            com.atlassian.clover,com.atlassian.clover.*
        </atlassian.org.osgi.framework.bootdelegation>
        <!-- Give func tests Stash instances more time to get the AO models registered. Slow or memory-constrained
             VMs can cause AO to give up too soon -->
        <activeobjects.servicefactory.config.timeout>60000</activeobjects.servicefactory.config.timeout>
        <!-- These properties are used by Surefire for the CTK tests -->
        <!-- LoginUriProviderTest is disabled because our URI encoding is valid but different from
             the encoding expected in the LoginUriProviderTest -->
        <!-- TransactionalExecutorTest is excluded because Bitbucket doesn't support the TransactionalExecutor -->
        <!-- PlatformVersionTest is temporarily disabled until atlassian-streams is correctly marked as optional -->
        <!-- WebHookOnEventsTest is disabled for now because atlassian-connect breaks it -->
        <!-- DarkFeaturesTest is disabled because it tries to change admin settings as an anonymous user -->
        <platform.ctk.test.exclude>
            com.atlassian.refapp.ctk.prettyurls.PrettyUrlsTest,
            com.atlassian.refapp.ctk.rest.tests.WebSudoRestTest,
            com.atlassian.refapp.ctk.sal.DarkFeaturesTest,
            com.atlassian.refapp.ctk.sal.LicenseHandlerTest,
            com.atlassian.refapp.ctk.sal.TransactionalExecutorTest,
            com.atlassian.refapp.ctk.sal.ThreadLocalContextManagerTest,
            com.atlassian.refapp.ctk.sal.UserManagerTest,
            com.atlassian.refapp.ctk.sal.UserSettingsTest,
            com.atlassian.refapp.ctk.version.PlatformVersionTest,
            com.atlassian.refapp.ctk.ui.tests.UpmUiTest,
            com.atlassian.refapp.ctk.webhooks.WebHookOnEventsTest
        </platform.ctk.test.exclude>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.atlassian.integration.jira</groupId>
                <artifactId>page-objects</artifactId>
                <version>${jira.integration.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>com.atlassian.maven.plugins</groupId>
                    <artifactId>bitbucket-maven-plugin</artifactId>
                    <configuration>
                        <skipITs>${skipITs}</skipITs>
                        <skipTests>${skipITs}</skipTests>
                    </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>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <configuration>
                    <!-- Bind skipping integration tests to skipITs instead of skipTests. This needs to be configured
                         in addition to skipITs on bitbucekt-maven-plugin to keep AMPS and Failsafe in sync on whether
                         integration tests should be run or not. -->
                    <skipTests>${skipITs}</skipTests>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <!-- enables tracking flaky tests in JIRA -->
            <id>track-flaky-tests</id>
            <properties>
                <!--default tracking flaky tests disabled-->
                <flakyTracking.enableFlakyTracking>false</flakyTracking.enableFlakyTracking>
                <flakyTracking.flakyTestRerunCount>0</flakyTracking.flakyTestRerunCount>
                <flakyTracking.moduleFrom>${project.artifactId}</flakyTracking.moduleFrom>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>com.atlassian</groupId>
                    <artifactId>flaky-test-reporter</artifactId>
                    <scope>test</scope>
                </dependency>
            </dependencies>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-resources-plugin</artifactId>
                            <executions>
                                <execution>
                                    <id>copy-flaky-issuecreator-config</id>
                                    <phase>generate-test-sources</phase>
                                    <goals>
                                        <goal>copy-resources</goal>
                                    </goals>
                                    <configuration>
                                        <outputDirectory>${project.build.testOutputDirectory}</outputDirectory>
                                        <resources>
                                            <resource>
                                                <directory>${maven.multiModuleProjectDirectory}/etc</directory>
                                                <includes>
                                                    <include>flaky_issuecreator_config.json</include>
                                                </includes>
                                            </resource>
                                        </resources>
                                    </configuration>
                                </execution>
                            </executions>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-failsafe-plugin</artifactId>
                            <configuration>
                                <properties>
                                    <property>
                                        <name>listener</name>
                                        <value>com.atlassian.test.reporting.JUnitFlakyTestListener</value>
                                    </property>
                                </properties>
                                <rerunFailingTestsCount>${flakyTracking.flakyTestRerunCount}</rerunFailingTestsCount>
                                <systemPropertyVariables>
                                    <module>${flakyTracking.moduleFrom}</module>
                                    <junitflakylistener.runnerId>${env.bamboo_buildResultKey}</junitflakylistener.runnerId>
                                    <junitflakylistener.branchName>${env.bamboo_planRepository_branchName}</junitflakylistener.branchName>
                                    <junitflakylistener.trackFlakyTest>${flakyTracking.enableFlakyTracking}</junitflakylistener.trackFlakyTest>
                                    <junitflakylistener.trackFlakyTestOnBranchesRegExp>master</junitflakylistener.trackFlakyTestOnBranchesRegExp>
                                    <junitflakylistener.failBranchWithNewFlakes>false</junitflakylistener.failBranchWithNewFlakes>
                                    <junitflakylistener.deprecatedVerboseTestLogging>true</junitflakylistener.deprecatedVerboseTestLogging>
                                    <junitflakylistener.jiraUserName>${env.bamboo_dc_bot_username}</junitflakylistener.jiraUserName>
                                    <junitflakylistener.jiraPassword>${env.bamboo_dc_bot_password}</junitflakylistener.jiraPassword>
                                    <junitflakylistener.jiraProjectConfigPath>flaky_issuecreator_config.json</junitflakylistener.jiraProjectConfigPath>
                                </systemPropertyVariables>
                                <skipAfterFailureCount>20</skipAfterFailureCount>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
        <profile>
            <!-- builds all artifacts required for amps. The amps.prepare profile activated by the
                 release plugin (see maven-release-plugin) -->
            <id>amps.prepare</id>
            <modules>
                <module>plugin-test-resources</module>
            </modules>
        </profile>

        <!-- mvn install -Pit runs the integration tests -->
        <profile>
            <id>it</id>
            <modules>
                <!-- plugin-test-resources needs to be before func-tests, because it
                generates the initial home for the tests. -->
                <module>plugin-test-resources</module>
                <module>browser</module>
                <module>mesh</module>
                <module>rest</module>
                <module>hosting</module>
                <module>migration</module>
                <module>setup</module>
                <module>license-setup</module>
            </modules>
        </profile>
        <profile>
            <id>it.smoke</id>
            <modules>
                <module>smoke</module>
            </modules>
        </profile>
        <profile>
            <id>it.dcm</id>
            <modules>
                <!-- plugin-test-resources needs to be before func-tests, because it
                generates the initial home for the tests. -->
                <module>plugin-test-resources</module>
            </modules>
        </profile>
        <!-- During a release, make sure we transform all the poms -->
        <profile>
            <id>release-pom-transform</id>
            <modules>
                <module>installer</module>
                <module>pact</module>
                <module>smoke</module>
                <module>dev-resources</module>
                <module>page-weight</module>
                <module>aurora-failover</module>
                <module>kubernetes</module>
                <module>license-setup</module>
                <module>git-lfs</module>
            </modules>
        </profile>
        <profile>
            <id>it.browser</id>
            <modules>
                <!-- plugin-test-resources needs to be before func-tests, because it
                     generates the initial home for the tests. -->
                <module>plugin-test-resources</module>
                <module>browser</module>
            </modules>
        </profile>
        <profile>
            <id>it.dev-resources</id>
            <modules>
                <module>dev-resources</module>
            </modules>
        </profile>
        <profile>
            <id>it.pageweight</id>
            <modules>
                <module>plugin-test-resources</module>
                <module>page-weight</module>
            </modules>
        </profile>
        <profile>
            <id>it.rest</id>
            <modules>
                <!-- plugin-test-resources needs to be before func-tests, because it
                     generates the initial home for the tests. -->
                <module>plugin-test-resources</module>
                <module>rest</module>
            </modules>
        </profile>
        <profile>
            <id>it.hosting</id>
            <modules>
                <!-- plugin-test-resources needs to be before func-tests, because it
                     generates the initial home for the tests. -->
                <module>plugin-test-resources</module>
                <module>hosting</module>
            </modules>
        </profile>
        <profile>
            <id>it.setup</id>
            <modules>
                <module>setup</module>
            </modules>
        </profile>
        <profile>
            <id>it.migration</id>
            <modules>
                <!-- plugin-test-resources needs to be before func-tests, because it
                     generates the initial home for the tests. -->
                <module>plugin-test-resources</module>
                <module>migration</module>
            </modules>
        </profile>
        <profile>
            <id>it.mirror</id>
            <modules>
                <module>plugin-test-resources</module>
            </modules>
        </profile>
        <profile>
            <id>it.mirror.browser</id>
            <modules>
                <module>plugin-test-resources</module>
            </modules>
        </profile>
        <profile>
            <id>it.mirror.setup</id>
            <modules>
                <module>plugin-test-resources</module>
            </modules>
        </profile>
        <profile>
            <id>it.clover</id>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>com.atlassian.maven.plugins</groupId>
                            <artifactId>clover-maven-plugin</artifactId>
                            <version>${clover.libversion}</version>
                            <configuration>
                                <distributedCoverage />
                            </configuration>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-failsafe-plugin</artifactId>
                            <configuration>
                                <systemProperties>
                                    <clover.server>true</clover.server>
                                    <clover.distributed.coverage>ON</clover.distributed.coverage>
                                </systemProperties>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
        <profile>
            <id>it.clustered</id>
            <properties>
                <elasticsearch.port>9200</elasticsearch.port>
                <node2.version>${project.version}</node2.version>
                <plugin.search.elasticsearch.baseurl>http://localhost:${elasticsearch.port}</plugin.search.elasticsearch.baseurl>
                <plugin.search.elasticsearch.username>bitbucket</plugin.search.elasticsearch.username>
                <plugin.search.elasticsearch.password>bitbucket</plugin.search.elasticsearch.password>
                <standalone.es.disabled>false</standalone.es.disabled>
                <zdu.enable.upgrade.mode>true</zdu.enable.upgrade.mode>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>validate</phase>
                                <id>parse-version</id>
                                <goals>
                                    <goal>parse-version</goal>
                                </goals>
                                <configuration>
                                    <propertyPrefix>parsedVersion</propertyPrefix>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>validate</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <exportAntProperties>true</exportAntProperties>
                                    <target name="Set node1.version property">
                                        <condition property="baseVersion" value="${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.0" else="${project.version}">
                                            <not>
                                                <equals arg1="${parsedVersion.incrementalVersion}" arg2="0" />
                                            </not>
                                        </condition>
                                        <condition property="node1.version" value="${baseVersion}">
                                            <not>
                                                <isset property="node1.version" />
                                            </not>
                                        </condition>
                                        <echo>node1.version: ${node1.version}</echo>
                                    </target>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>io.fabric8</groupId>
                            <artifactId>docker-maven-plugin</artifactId>
                            <configuration>
                                <removeVolumes>true</removeVolumes>
                                <showLogs>true</showLogs>
                                <images>
                                    <image>
                                        <alias>es</alias>
                                        <name>dchevell/bitbucket-elasticsearch:latest</name>
                                        <run>
                                            <skip>${standalone.es.disabled}</skip>
                                            <ports>
                                                <port>${elasticsearch.port}:9200</port>
                                            </ports>
                                            <env>
                                                <discovery.type>single-node</discovery.type>
                                                <AUTH_BASIC_USERNAME>${plugin.search.elasticsearch.username}</AUTH_BASIC_USERNAME>
                                                <AUTH_BASIC_PASSWORD>${plugin.search.elasticsearch.password}</AUTH_BASIC_PASSWORD>
                                            </env>
                                        </run>
                                    </image>
                                </images>
                            </configuration>
                            <executions>
                                <execution>
                                    <id>start</id>
                                    <phase>pre-integration-test</phase>
                                    <goals>
                                        <goal>build</goal>
                                        <goal>start</goal>
                                    </goals>
                                </execution>
                                <execution>
                                    <id>stop</id>
                                    <phase>post-integration-test</phase>
                                    <goals>
                                        <goal>stop</goal>
                                    </goals>
                                </execution>
                                <execution>
                                    <id>stop-clean</id>
                                    <phase>pre-clean</phase>
                                    <goals>
                                        <goal>stop</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>
                        <plugin>
                            <groupId>com.atlassian.maven.plugins</groupId>
                            <artifactId>load-balancer-maven-plugin</artifactId>
                            <executions>
                                <execution>
                                    <id>start-load-balancer</id>
                                    <phase>pre-integration-test</phase>
                                    <goals>
                                        <goal>start</goal>
                                    </goals>
                                </execution>
                                <execution>
                                    <id>stop-load-balancer</id>
                                    <phase>post-integration-test</phase>
                                    <goals>
                                        <goal>stop</goal>
                                    </goals>
                                </execution>
                            </executions>
                            <configuration>
                                <balancers>
                                    <!-- HTTP -->
                                    <balancer>
                                        <port>7990</port>
                                        <targets>
                                            <target>
                                                <port>7991</port>
                                            </target>
                                            <target>
                                                <port>7992</port>
                                            </target>
                                        </targets>
                                    </balancer>
                                    <!-- SSH -->
                                    <balancer>
                                        <port>7999</port>
                                        <targets>
                                            <target>
                                                <port>7998</port>
                                            </target>
                                            <target>
                                                <port>7997</port>
                                            </target>
                                        </targets>
                                    </balancer>
                                </balancers>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
        <profile>
            <id>it.clustered.local</id>
            <properties>
                <jdbc.driver>org.postgresql.Driver</jdbc.driver>
                <jdbc.url>jdbc:postgresql:bitbucket</jdbc.url>
                <jdbc.user>bitbucket</jdbc.user>
                <jdbc.password>bitbucket</jdbc.password>
            </properties>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-dependency-plugin</artifactId>
                            <executions>
                                <execution>
                                    <id>copy-postgres-zip</id>
                                    <phase>package</phase>
                                    <goals>
                                        <goal>unpack</goal>
                                    </goals>
                                    <configuration>
                                        <artifactItems>
                                            <artifactItem>
                                                <groupId>com.atlassian.bitbucket.server</groupId>
                                                <artifactId>bitbucket-it-resources</artifactId>
                                                <classifier>postgres</classifier>
                                                <version>${project.version}</version>
                                                <type>zip</type>
                                                <includes>**/*</includes>
                                            </artifactItem>
                                        </artifactItems>
                                        <outputDirectory>${project.build.directory}</outputDirectory>
                                    </configuration>
                                </execution>
                            </executions>
                        </plugin>
                        <plugin>
                            <groupId>io.fabric8</groupId>
                            <artifactId>docker-maven-plugin</artifactId>
                            <configuration>
                                <images combine.children="append">
                                    <image>
                                        <alias>postgres</alias>
                                        <name>postgres:10</name>
                                        <run>
                                            <ports>
                                                <port>5432:5432</port>
                                            </ports>
                                            <env>
                                                <POSTGRES_USER>${jdbc.user}</POSTGRES_USER>
                                                <POSTGRES_PASSWORD>${jdbc.password}</POSTGRES_PASSWORD>
                                            </env>
                                            <volumes>
                                                <bind>
                                                    <volume>
                                                        ${project.build.directory}/postgres_data:/var/lib/postgresql/data
                                                    </volume>
                                                </bind>
                                            </volumes>
                                            <wait>
                                                <time>90000</time>
                                                <log>
                                                    (?s)(PostgreSQL init process complete|PostgreSQL Database directory appears to contain a database).*database system is ready to accept connections
                                                </log>
                                            </wait>
                                        </run>
                                    </image>
                                </images>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
        <profile>
            <id>it.installer</id>
            <activation>
                <property>
                    <!-- This should have the same activation as the installer -->
                    <name>install4j.home</name>
                </property>
            </activation>
            <modules>
                <module>installer</module>
            </modules>
        </profile>
        <profile>
            <id>it.pact</id>
            <modules>
                <!-- plugin-test-resources needs to be before func-tests, because it
                     generates the initial home for the tests. -->
                <module>plugin-test-resources</module>
                <module>pact</module>
            </modules>
        </profile>
        <profile>
            <id>it.aurora-failover</id>
            <modules>
                <module>aurora-failover</module>
            </modules>
        </profile>
        <profile>
            <id>it.git-lfs</id>
            <modules>
                <module>plugin-test-resources</module>
                <module>git-lfs</module>
            </modules>
        </profile>
        <profile>
            <id>it.kubernetes</id>
            <modules>
                <module>kubernetes</module>
            </modules>
        </profile>
        <profile>
            <id>build-test-jar</id>
            <modules>
                <!-- plugin-test-resources needs to be before func-tests, because it
                generates the initial home for the tests. -->
                <module>browser</module>
                <module>rest</module>
                <module>hosting</module>
            </modules>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jar-plugin</artifactId>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>test-jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>it.license.setup</id>
            <modules>
                <module>license-setup</module>
            </modules>
        </profile>
    </profiles>
</project>
