<?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/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <parent>
        <artifactId>atlassian-connect-integration-parent</artifactId>
        <groupId>com.atlassian.fusion.plugins</groupId>
        <version>1.1.0-D20170201T045853</version>
    </parent>

    <artifactId>atlassian-connect-integration-plugin</artifactId>

    <name>Atlassian Connect Integration: Plugin</name>
    <description>The Atlassian Connect Integration plugin</description>
    <packaging>atlassian-plugin</packaging>

    <properties>

        <!-- OnDemand compatibility test directives -->
        <od.testing.configuration>
            use-maven,3.2.5
            use-java,8
        </od.testing.configuration>

        <darkfeature.enabled>true</darkfeature.enabled>

        <xsl.directory>${project.build.directory}/xsl</xsl.directory>
        <restdoc.directory>${project.build.directory}/restapi</restdoc.directory>

        <vertigo.flags/>
    </properties>

    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>atlassian-connect-integration-api</artifactId>
        </dependency>
        <dependency>
            <groupId>cloud.atlassian.sal</groupId>
            <artifactId>sal-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.plugin</groupId>
            <artifactId>atlassian-spring-scanner-annotation</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.atlassian.jwt</groupId>
            <artifactId>jwt-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.jwt</groupId>
            <artifactId>jwt-core</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.jwt</groupId>
            <artifactId>jwt-spi</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.nimbusds</groupId>
            <artifactId>nimbus-jose-jwt</artifactId>
        </dependency>

        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>jsr311-api</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
        </dependency>

        <dependency>
            <groupId>cloud.atlassian.plugins.rest</groupId>
            <artifactId>atlassian-rest-common</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>cloud.atlassian.activeobjects</groupId>
            <artifactId>activeobjects-plugin</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
        </dependency>

        <dependency>
            <groupId>com.atlassian.fugue</groupId>
            <artifactId>fugue</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- Fugue three is not in platform yet, but will be peacefully co-exist with fugue 2. To be removed when platform updates -->
        <dependency>
            <groupId>io.atlassian.fugue</groupId>
            <artifactId>fugue</artifactId>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>cloud.atlassian.applinks</groupId>
            <artifactId>applinks-host</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>cloud.atlassian.applinks</groupId>
            <artifactId>applinks-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>cloud.atlassian.applinks</groupId>
            <artifactId>applinks-plugin</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>cloud.atlassian.event</groupId>
            <artifactId>atlassian-event</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>cloud.atlassian.activeobjects</groupId>
            <artifactId>activeobjects-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>java-hamcrest</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-junit</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-connect-integration-test-resources</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.atlassian</groupId>
            <artifactId>atlassian-test-categories</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>atlassian-jira-pageobjects</artifactId>
            <version>${jira.pageobjects.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>atlassian-connect-integration-testkit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.tomakehurst</groupId>
            <artifactId>wiremock</artifactId>
            <version>1.57</version>
            <scope>test</scope>
            <classifier>standalone</classifier>
            <exclusions>
                <exclusion>
                    <groupId>org.mortbay.jetty</groupId>
                    <artifactId>jetty</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.google.guava</groupId>
                    <artifactId>guava</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-annotations</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-databind</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.httpcomponents</groupId>
                    <artifactId>httpclient</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.skyscreamer</groupId>
                    <artifactId>jsonassert</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>xmlunit</groupId>
                    <artifactId>xmlunit</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.jayway.jsonpath</groupId>
                    <artifactId>json-path</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>net.sf.jopt-simple</groupId>
                    <artifactId>jopt-simple</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>maven-jira-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <!-- Integration tests live in a different module -->
                    <instructions>
                        <Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>

                        <Export-Package>
                            com.atlassian.fusion.aci.api.analytics,
                            com.atlassian.fusion.aci.api.analytics.event,
                            com.atlassian.fusion.aci.api.event,
                            com.atlassian.fusion.aci.api.feature,
                            com.atlassian.fusion.aci.api.model,
                            com.atlassian.fusion.aci.api.service,
                            com.atlassian.fusion.aci.api.service.exception,
                            com.atlassian.fusion.aci.obr.install,
                            io.atlassian.fugue;version="${fugue.version}",
                            io.atlassian.fugue.law;version="${fugue.version}"
                        </Export-Package>

                        <Import-Package>
                            com.atlassian.annotations,
                            com.atlassian.jwt,
                            com.atlassian.sal.api,
                            com.atlassian.plugins.rest.common.security,
                            com.atlassian.plugin.osgi.*,
                            org.springframework.aop.support,
                            org.springframework.beans,
                            org.springframework.beans.factory*,
                            org.springframework.context.annotation,
                            org.springframework.osgi.service.*;resolution:="optional",
                            org.springframework.osgi.*;resolution:="optional",
                            org.springframework.stereotype,
                            org.springframework.util,
                            net.java.ao.schema,
                            net.java.ao,
                            com.atlassian.activeobjects.external,
                            org.slf4j,
                            com.google.common.*,
                            org.w3c.dom,
                            org.osgi.util.tracker,
                            org.osgi.framework,
                            javax.annotation,
                            javax.ws.rs.core,
                            javax.ws.rs,
                            javax.inject,
                            org.eclipse.gemini.blueprint.*;resolution:="optional",
                            com.atlassian.analytics.api.annotations;resolution:="optional",
                            io.atlassian.fugue;resolution:="optional",
                            io.atlassian.fugue.law;resolution:="optional",
                            !org.bouncycastle.openssl.*,
                            !sun.security.util,
                            *
                        </Import-Package>

                        <!-- Ensure plugin is spring powered - see https://extranet.atlassian.com/x/xBS9hQ  -->
                        <Spring-Context>*</Spring-Context>
                    </instructions>

                    <skipITs>${skipITs}</skipITs>
                    <log4jProperties>src/test/resources/log4j.properties</log4jProperties>

                    <!-- Speedup startup times -->
                    <enableFastdev>false</enableFastdev>
                    <enableDevToolbox>false</enableDevToolbox>
                    <enablePde>false</enablePde>
                    <allowGoogleTracking>false</allowGoogleTracking>
                    <extractDependencies>false</extractDependencies>
                    <skipManifestValidation>true</skipManifestValidation>
                    <skipRestDocGeneration>true</skipRestDocGeneration>

                    <systemPropertyVariables>
                        <atlassian.darkfeature.atlassian.plugin.aci.enabled>${darkfeature.enabled}</atlassian.darkfeature.atlassian.plugin.aci.enabled>
                        <PG_DB_ROLE>${postgres.db.role}</PG_DB_ROLE>
                        <PG_DB_HOST>${postgres.db.host}</PG_DB_HOST>
                        <PG_DB_NAME>${postgres.db.name}</PG_DB_NAME>
                        <PG_DB_PASSWORD>${postgres.db.password}</PG_DB_PASSWORD>
                        <PG_DB_PORT>${postgres.db.port}</PG_DB_PORT>
                    </systemPropertyVariables>
                    <jvmArgs>${vertigo.flags}</jvmArgs>

                    <productVersion>${jira.version}</productVersion>

                    <applications>
                        <application>
                            <applicationKey>jira-software</applicationKey>
                            <version>${jira.software.application.version}</version>
                        </application>
                    </applications>

                    <pluginArtifacts>
                        <pluginArtifact>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>atlassian-connect-integration-testkit</artifactId>
                            <version>${project.version}</version>
                        </pluginArtifact>
                        <pluginArtifact>
                            <groupId>cloud.atlassian.plugins</groupId>
                            <artifactId>quickreload</artifactId>
                            <version>${quickreload.version}</version>
                        </pluginArtifact>
                        <pluginArtifact>
                            <groupId>com.atlassian.jira.plugins</groupId>
                            <artifactId>jira-software-plugin</artifactId>
                            <version>${jira.software.version}</version>
                        </pluginArtifact>
                        <pluginArtifact>
                            <groupId>com.atlassian.jira.plugins</groupId>
                            <artifactId>jira-greenhopper-plugin</artifactId>
                            <version>${agile.version}</version>
                        </pluginArtifact>
                        <pluginArtifact>
                            <groupId>com.atlassian.jira.tests</groupId>
                            <artifactId>jira-testkit-plugin</artifactId>
                            <version>${jira.testkit.version}</version>
                        </pluginArtifact>
                    </pluginArtifacts>

                    <libArtifacts>
                        <libArtifact>
                            <groupId>postgresql</groupId>
                            <artifactId>postgresql</artifactId>
                            <version>${jdbc.postgres.version}</version>
                        </libArtifact>
                    </libArtifacts>

                </configuration>
            </plugin>
            <plugin>
                <groupId>com.atlassian.plugin</groupId>
                <artifactId>atlassian-spring-scanner-maven-plugin</artifactId>
                <version>${atlassian.spring.scanner.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>atlassian-spring-scanner</goal>
                        </goals>
                        <phase>process-classes</phase>
                    </execution>
                </executions>
                <configuration>
                    <scannedDependencies>
                        <dependency>
                            <groupId>com.atlassian.plugin</groupId>
                            <artifactId>atlassian-spring-scanner-external-jar</artifactId>
                        </dependency>
                    </scannedDependencies>
                    <verbose>false</verbose>
                </configuration>
            </plugin>
            <!-- Build test JAR for AT/SLAT execution -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>test-jar</goal>
                        </goals>
                        <configuration>
                            <forceCreation>true</forceCreation>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <profiles>
        <profile>
            <id>runTestSuite</id>
            <activation>
                <property>
                    <name>testGroups</name>
                </property>
            </activation>
            <properties>
                <skipITs>false</skipITs>
                <skipDocker>false</skipDocker>
                <docker.restartPolicy/>
                <docker.start-phase>pre-integration-test</docker.start-phase>
                <docker.stop-phase>post-integration-test</docker.stop-phase>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.atlassian.maven.plugins</groupId>
                        <artifactId>maven-jira-plugin</artifactId>
                        <extensions>true</extensions>
                        <configuration>
                            <products>
                                <product>
                                    <id>jira</id>
                                    <instanceId>jira</instanceId>
                                    <version>${jira.version}</version>
                                    <dataVersion>${jira.version}</dataVersion>
                                    <jvmArgs>${vertigo.flags}</jvmArgs>
                                    <libArtifacts>
                                        <libArtifact>
                                            <groupId>postgresql</groupId>
                                            <artifactId>postgresql</artifactId>
                                            <version>${jdbc.postgres.version}</version>
                                        </libArtifact>
                                    </libArtifacts>
                                </product>
                            </products>
                            <testGroups>
                                <testGroup>
                                    <id>rest</id>
                                    <includes>
                                        <include>**it/com/atlassian/fusion/aci/rest/**/*Test.java</include>
                                        <include>**it/com/atlassian/fusion/aci/rest/**/Test*.java</include>
                                    </includes>
                                    <productIds>
                                        <productId>jira</productId>
                                    </productIds>
                                </testGroup>
                                <testGroup>
                                    <id>atslat</id>
                                    <includes>
                                        <include>**it/com/atlassian/fusion/aci/webdriver/atslat/**/*Test.java</include>
                                        <include>**it/com/atlassian/fusion/aci/webdriver/atslat/**/Test*.java</include>
                                    </includes>
                                    <productIds>
                                        <productId>jira</productId>
                                    </productIds>
                                </testGroup>
                                <testGroup>
                                    <id>all</id>
                                    <includes>
                                        <include>**it/com/atlassian/fusion/aci/**/*Test.java</include>
                                        <include>**it/com/atlassian/fusion/aci/**/Test*.java</include>
                                    </includes>
                                    <productIds>
                                        <productId>jira</productId>
                                    </productIds>
                                </testGroup>
                            </testGroups>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>ondemand-acceptance-tests</id>
            <properties>
                <skipITs>false</skipITs> <!-- enable integration tests -->
                <skip.javadoc>true</skip.javadoc> <!-- disable javadocs generation -->
                <rest.doc.generation.skip>true</rest.doc.generation.skip>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <!-- Skip unit tests during AT/SLAT execution -->
                        <!-- Once amps 6.x supports the skipUTs property we can change to using that instead -->
                        <configuration>
                            <skipTests>true</skipTests>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>vertigo</id>
            <properties>
                <vertigo.flags>
                    -Dscheduler.noop=true
                    -Ddev.mode.multitenanted=true
                    -Dvertigo.mode=true
                    -Dsql.schema.directory=${project.basedir}/src/test/resources/vertigo/dump
                    -Dsql.data.directory=${project.basedir}/src/test/resources/vertigo/dump
                    -Dtenant.dir=${project.build.testOutputDirectory}/vertigo/config
                    -Djira.dev.mode.tenantId=default
                    -Dtestkit.backdoor.skip.dataimport=true
                    -Datlassian.darkfeature.fusion.dvcs.use_amq_for_executors.enabled=true
                    -Datlassian.darkfeature.fusion.dvcs.use_amq_to_invoke_sync.enabled=true
                    -Datlassian.darkfeature.fusion.bitbucket.rebrand=true
                    -Datlassian.darkfeature.fusion.devstatus.devsummary.customfield.jql.enabled
                </vertigo.flags>
                <skipDocker>false</skipDocker>
                <postgres.image.name>docker.atlassian.io/jira-cloud/postgres-ci:9.5</postgres.image.name>
                <docker.postgres.wait.log>PostgreSQL init process complete; ready for start up.</docker.postgres.wait.log>
                <docker.start-phase>process-resources</docker.start-phase>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>sql-maven-plugin</artifactId>
                        <version>1.5</version>
                        <configuration>
                            <delimiterType>row</delimiterType>
                        </configuration>
                        <executions>
                            <!-- first invocation - drop the existing database if it's there and create new -->
                            <execution>
                                <id>create-vertigo-tenant-db</id>
                                <phase>${docker.start-phase}</phase>
                                <goals>
                                    <goal>execute</goal>
                                </goals>
                                <configuration>
                                    <driver>org.postgresql.Driver</driver>
                                    <url>
                                        jdbc:postgresql://${postgres.db.host}:${postgres.db.port}/${postgres.superuser.db}
                                    </url>
                                    <username>${postgres.superuser.name}</username>
                                    <password>${postgres.superuser.password}</password>
                                    <autocommit>true</autocommit>
                                    <sqlCommand>
                                    DROP DATABASE IF EXISTS ${postgres.db.name};
                                    DROP USER IF EXISTS ${postgres.db.role};
                                    CREATE USER ${postgres.db.role} WITH PASSWORD '${postgres.db.password}';
                                    ALTER USER ${postgres.db.role} WITH SUPERUSER;
                                    GRANT ${postgres.db.role} TO ${postgres.superuser.name};
                                    CREATE DATABASE ${postgres.db.name} WITH OWNER ${postgres.db.role};
                                </sqlCommand>
                                </configuration>
                            </execution>
                            <!-- second invocation - connect with the user just created and execute sql file -->
                            <execution>
                                <id>populate-vertigo-tenant-db</id>
                                <phase>${docker.start-phase}</phase>
                                <goals>
                                    <goal>execute</goal>
                                </goals>
                                <configuration>
                                    <driver>org.postgresql.Driver</driver>
                                    <url>jdbc:postgresql://${postgres.db.host}:${postgres.db.port}/${postgres.db.name}
                                    </url>
                                    <username>${postgres.db.role}</username>
                                    <password>${postgres.db.password}</password>
                                    <autocommit>true</autocommit>
                                    <srcFiles>
                                        <srcFile>
                                            ${project.basedir}/src/test/resources/vertigo/dump/schema-only-dump.sql
                                        </srcFile>
                                        <srcFile>
                                            ${project.basedir}/src/test/resources/vertigo/dump/empty.sql
                                        </srcFile>
                                    </srcFiles>
                                </configuration>
                            </execution>
                        </executions>
                        <dependencies>
                            <dependency>
                                <groupId>postgresql</groupId>
                                <artifactId>postgresql</artifactId>
                                <version>${jdbc.postgres.version}</version>
                            </dependency>
                        </dependencies>
                    </plugin>

                    <!-- Replace maven placeholder in vertigo yaml config files -->
                    <plugin>
                        <artifactId>maven-resources-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>prepare-vertigo-tenant-config</id>
                                <phase>${docker.start-phase}</phase>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${project.build.testOutputDirectory}/vertigo/config</outputDirectory>
                                    <resources>
                                        <resource>
                                            <directory>${basedir}/src/test/resources/vertigo/config</directory>
                                            <filtering>true</filtering>
                                        </resource>
                                    </resources>
                                    <escapeString>\</escapeString>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                </plugins>
            </build>
        </profile>

    </profiles>
</project>
