<?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.jpo</groupId>
        <artifactId>common</artifactId>
        <version>2.1.4-OD-002-D20161108T014435</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <artifactId>common-plugin-parent-pom</artifactId>

    <packaging>pom</packaging>

    <name>Portfolio 2 / Common [Plugin Parent POM]</name>

    <properties>
        <!-- default properties for wiredtests and postgres stuff-->

        <!-- jira unicorn/vertigo compatible database initial data and postgres configuration for postgres database runs/wiredtests -->
        <amps.resources.postgres>${project.parent.basedir}/../../../builds/jira-resources/generated-postgres-empty-resources.zip</amps.resources.postgres>
        <!-- Maps the directory that will be mounted as volume in the docker image - contains database backup script which will be important on docker startup. -->
        <docker.postgres.init.folder>${project.parent.basedir}/../../../builds/databases/postgres/init-empty:/docker-entrypoint-initdb.d</docker.postgres.init.folder>

        <!-- default environment -->
        <wiredtests.env>jirastudio-dev</wiredtests.env>
        <wiredtests.script>wiredtests-manifesto</wiredtests.script>

    </properties>

    <build>

        <!-- overruled in vertigo / vertigo-internal profile -->
        <resources>

            <resource>
                <directory>src/main/resources</directory>
                <excludes>
                    <exclude>plugin-descriptors/atlassian-plugin-vertigo.xml</exclude>
                    <exclude>plugin-descriptors/atlassian-plugin-vertigo-internal.xml</exclude>
                </excludes>
            </resource>

        </resources>

        <testResources>

            <testResource>
                <directory>src/test/resources</directory>
            </testResource>

        </testResources>

        <pluginManagement>

            <plugins>

                <!-- configure amps plugin -->
                <plugin>

                    <groupId>com.atlassian.maven.plugins</groupId>
                    <artifactId>maven-amps-plugin</artifactId>

                    <configuration>

                        <compressResources>false</compressResources>

                        <enableFastdev>${enableFastdev}</enableFastdev>

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

                        <buildTestPlugin>true</buildTestPlugin>

                        <!--
							reg. LauncherContextListener:
							https://answers.atlassian.com/questions/36119444/answers/36121004
							otherwise the wired integration tests are executed too early, at a point where the test-runner endpoints are not yet available.
						-->
                        <jvmArgs>
                            -Datlassian.plugins.enable.wait=300
                            -Dcom.atlassian.jira.startup.LauncherContextListener.SYNCHRONOUS=true
                            -Xmx2048m
                            <!-- Uncomment to debug wired tests -->
                            <!--
                            -Xdebug
                            -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=n
                            -->
                        </jvmArgs>

                        <testGroups>
                            <testGroup>
                                <id>tg-jira-it</id>
                                <productIds>
                                    <productId>jira</productId>
                                </productIds>
                                <includes>
                                    <include>${jira.it.test.pattern}</include>
                                </includes>
                            </testGroup>
                        </testGroups>

                        <instructions>

                            <Atlassian-Scan-Folders>plugin-descriptors</Atlassian-Scan-Folders>

                        </instructions>

                        <testInstructions>

                            <!-- force osgi to search for stuff we have explicitly excluded via testBundleExcludes -->
                            <!-- this is slow (apparently), but used only in the test bundle, so no production code affected -->
                            <DynamicImport-Package>*</DynamicImport-Package>

                            <!-- we need to specify at least one, or an amps bug will screw up our manifest -->
                            <Export-Package>
                                com.atlassian.rm.na.*,
                                !*
                            </Export-Package>

                            <Atlassian-Scan-Folders>plugin-descriptors</Atlassian-Scan-Folders>

                        </testInstructions>

                        <testBundleExcludes>

                            <testBundleExclude>
                                <groupId>com.atlassian.jpo</groupId>
                                <artifactId>common-dev-utils</artifactId>
                            </testBundleExclude>

                        </testBundleExcludes>

                    </configuration>
                </plugin>

                <!-- configure spring scanner -->
                <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.pocketknife</groupId>
                                <artifactId>atlassian-pocketknife-querydsl</artifactId>
                            </dependency>
                            <dependency>
                                <groupId>com.atlassian.pocketknife</groupId>
                                <artifactId>jira-pocketknife-enablement</artifactId>
                            </dependency>
                            <dependency>
                                <groupId>com.atlassian.pocketknife</groupId>
                                <artifactId>jira-pocketknife-customfields</artifactId>
                            </dependency>

                        </scannedDependencies>

                        <verbose>false</verbose>

                    </configuration>

                </plugin>

            </plugins>

        </pluginManagement>

    </build>

    <profiles>

        <profile>

            <id>skip-vertigo</id>

            <activation>
                <property>
                    <name>skipVertigo</name>
                </property>
            </activation>

            <build>

                <testResources>

                    <testResource>
                        <directory>src/test/resources-skip-vertigo</directory>
                    </testResource>

                </testResources>

            </build>

        </profile>

        <profile>

            <id>vertigo</id>

            <activation>
                <property>
                    <name>!skipVertigo</name>
                </property>
            </activation>

            <build>

                <resources>

                    <resource>
                        <directory>src/main/resources</directory>
                        <includes>
                            <include>**/*.*</include>
                        </includes>
                    </resource>

                </resources>

                <testResources>

                    <testResource>
                        <directory>src/test/resources-vertigo</directory>
                    </testResource>

                </testResources>

            </build>

        </profile>

        <profile>

            <id>vertigo-internal</id>

            <activation>
                <property>
                    <name>vertigoInternal</name>
                </property>
            </activation>

            <build>

                <plugins>

                    <plugin>

                        <groupId>com.atlassian.maven.plugins</groupId>
                        <artifactId>maven-amps-plugin</artifactId>

                        <configuration>

                            <systemProperties combine.children="append">

                                <atlassian.darkfeature.com.atlassian.rm.portfolio.vertigo.AMQ>true</atlassian.darkfeature.com.atlassian.rm.portfolio.vertigo.AMQ>

                                <!-- auto-enable jira system-wide db only handling -->
                                <atlassian.darkfeature.jira.issue.search.jql.databaseonly.enabled>true</atlassian.darkfeature.jira.issue.search.jql.databaseonly.enabled>

                            </systemProperties>

                        </configuration>

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

        <profile>
            <!-- active by default whenever not -DskipVertigo flag is provided-->
            <id>cloud-dev</id>
            <activation>
                <property>
                    <name>cloudDev</name>
                </property>
            </activation>

            <build>

                <plugins>

                    <plugin>

                        <groupId>com.atlassian.maven.plugins</groupId>
                        <artifactId>maven-amps-plugin</artifactId>

                        <configuration>

                            <systemProperties combine.children="append">

                                <atlassian.darkfeature.com.atlassian.rm.portfolio.vertigo.issueloading.Database>true</atlassian.darkfeature.com.atlassian.rm.portfolio.vertigo.issueloading.Database>
                                <atlassian.darkfeature.com.atlassian.rm.portfolio.vertigo.AMQ>true</atlassian.darkfeature.com.atlassian.rm.portfolio.vertigo.AMQ>

                            </systemProperties>

                        </configuration>

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

        <!-- vertigo compatible data for usage with postgres. including sample data -->
        <profile>
            <id>pgVertigoData</id>
            <activation>
                <property><name>pgVertigoData</name></property>
                <activeByDefault>false</activeByDefault>
            </activation>
            <properties>
                <amps.resources.postgres>${basedir}/../../../builds/jira-resources/generated-postgres-resources.zip</amps.resources.postgres>
                <docker.postgres.init.folder>${basedir}/../../../builds/databases/postgres/init-vertigo:/docker-entrypoint-initdb.d</docker.postgres.init.folder>
            </properties>
        </profile>

        <!-- jiraRenaissance compatible data for usage with postgres -->
        <profile>
            <id>pgRenaissanceData</id>
            <activation>
                <property><name>pgRenaissanceData</name></property>
                <activeByDefault>false</activeByDefault>
            </activation>
            <properties>
                <amps.resources.postgres>${project.parent.basedir}/../../../builds/jira-resources/jira-7-renaissance-postgres.zip</amps.resources.postgres>
                <docker.postgres.init.folder>${project.parent.basedir}/../../../builds/databases/postgres/init-renaissance:/docker-entrypoint-initdb.d</docker.postgres.init.folder>
            </properties>
        </profile>

        <profile>
            <id>postgres</id>
            <activation>
                <activeByDefault>false</activeByDefault>
                <property><name>postgres</name></property>
            </activation>

            <dependencies>
                <dependency>
                    <groupId>org.postgresql</groupId>
                    <artifactId>postgresql</artifactId>
                    <version>9.4.1208</version>
                </dependency>
            </dependencies>

            <build>
                <plugins>
                    <plugin>
                        <groupId>com.atlassian.maven.plugins</groupId>
                        <artifactId>maven-amps-plugin</artifactId>
                        <configuration>
                            <products>
                                <product>
                                    <id>jira</id>
                                    <libArtifacts>
                                        <libArtifact>
                                            <groupId>org.postgresql</groupId>
                                            <artifactId>postgresql</artifactId>
                                            <version>9.4.1208</version>
                                        </libArtifact>
                                    </libArtifacts>
                                </product>
                            </products>
                            <productDataPath>${amps.resources.postgres}</productDataPath>
                        </configuration>
                    </plugin>

                    <!--
                        docker plugin to start and stop postgres docker container.
                        start with "mvn -Dpostgres docker:start"
                        stop with "mvn -Dpostgres docker:stop"
                    -->
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <version>0.15.7</version>

                        <configuration>
                            <removeVolumes>true</removeVolumes>
                            <images>
                                <image>
                                    <alias>postgres-db</alias>
                                    <name>postgres:9.5</name>
                                    <run>
                                        <env>
                                            <POSTGRES_USER>jirauser</POSTGRES_USER>
                                            <POSTGRES_PASSWORD>jirauser</POSTGRES_PASSWORD>
                                            <POSTGRES_DB>postgres</POSTGRES_DB>
                                        </env>
                                        <ports>
                                            <port>15432:5432</port>
                                        </ports>
                                        <volumes>
                                            <bind>
                                                <volume>${docker.postgres.init.folder}</volume>
                                            </bind>
                                        </volumes>
                                        <wait>
                                            <log>PostgreSQL init process complete; ready for start up</log>
                                            <time>100000</time>
                                            <kill>5000</kill>
                                            <shutdown>2000</shutdown>
                                        </wait>
                                    </run>
                                </image>
                            </images>
                        </configuration>

                        <executions>
                            <execution>
                                <id>start</id>
                                <phase>none</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>stop</id>
                                <phase>none</phase>
                                <goals>
                                    <goal>stop</goal>
                                    <goal>remove</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                </plugins>
            </build>

        </profile>



        <!-- ######################

            profiles for execution of wired tests

            e.g.

            mvn -Pwiredtests exec:exec -Dwiredtests.env=jirastudio-dev

            #######################
        -->

        <profile>
            <id>wiredtests</id>
            <activation>
                <activeByDefault>false</activeByDefault>
                <property><name>wiredtests</name></property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.5.0</version>
                        <executions>
                            <!-- Required: The following will ensure `npm install` is called
                                 before anything else during the 'Default Lifecycle' -->

                            <execution>
                                <id>wiredtests-run</id>
                                <phase>none</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                            </execution>

                        </executions>

                        <configuration>
                            <executable>npm</executable>
                            <workingDirectory>${basedir}</workingDirectory>
                            <arguments>
                                <argument>run</argument>
                                <argument>${wiredtests.script}</argument>
                                <argument>--</argument>
                                <argument>--env=${wiredtests.env}</argument>
                            </arguments>
                        </configuration>

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

        <profile>
            <id>wiredtests-postgres</id>
            <activation>
                <activeByDefault>false</activeByDefault>
                <property><name>wiredtestsPostgres</name></property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.5.0</version>
                        <executions>
                            <!-- Required: The following will ensure `npm install` is called
                                 before anything else during the 'Default Lifecycle' -->

                            <execution>
                                <id>wiredtests-run</id>
                                <phase>none</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                            </execution>

                        </executions>

                        <configuration>
                            <executable>npm</executable>
                            <workingDirectory>${basedir}</workingDirectory>
                            <arguments>
                                <argument>run</argument>
                                <argument>${wiredtests.script}</argument>
                                <argument>--</argument>
                                <argument>--env=${wiredtests.env}</argument>
                                <argument>-p</argument>
                                <argument>postgres</argument>
                            </arguments>
                        </configuration>

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

        <profile>
            <id>wiredtests-vertigo-postgres</id>
            <activation>
                <activeByDefault>false</activeByDefault>
                <property><name>wiredtestsVertigoPostgres</name></property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.5.0</version>
                        <executions>
                            <!-- Required: The following will ensure `npm install` is called
                                 before anything else during the 'Default Lifecycle' -->

                            <execution>
                                <id>wiredtests-run</id>
                                <phase>none</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                            </execution>

                        </executions>

                        <configuration>
                            <executable>npm</executable>
                            <workingDirectory>${basedir}</workingDirectory>
                            <arguments>
                                <argument>run</argument>
                                <argument>${wiredtests.script}</argument>
                                <argument>--</argument>
                                <argument>--env=${wiredtests.env}</argument>
                                <argument>-p</argument>
                                <argument>postgres</argument>
                                <argument>-p</argument>
                                <argument>vertigoInternal</argument>
                                <argument>-p</argument>
                                <argument>noClassicPortfolioDependencies</argument>
                            </arguments>
                        </configuration>

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



        <!-- coverage profile -->
        <profile>

            <id>clover</id>
            <activation>
                <property>
                    <name>coverage</name>
                </property>
            </activation>

            <build>

                <pluginManagement>

                    <plugins>

                        <plugin>

                            <groupId>com.atlassian.maven.plugins</groupId>
                            <artifactId>maven-clover2-plugin</artifactId>

                            <configuration>

                                <licenseLocation>${project.parent.basedir}/../../../builds/clover.license</licenseLocation>

                                <excludes>
                                    <exclude>it/**</exclude>
                                </excludes>

                            </configuration>

                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>


    </profiles>

</project>
