<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>
        <groupId>com.atlassian.jira.plugins</groupId>
        <artifactId>jira-development-status-parent</artifactId>
        <version>3.3.18</version>
    </parent>

    <artifactId>jira-development-status-soke-tests</artifactId>
    <name>Development Integration Plugin Soke Tests</name>
    <description>SOKE tests for the Development Integration Plugin</description>

    <properties>
        <scala.version>2.10.2</scala.version>
        <soke.version>3.2.0</soke.version>
        <!-- we cannot use snapshot to build against because the maven release plugin is picky about that -->
        <!-- execute with -Dsoke.jira.version=6.2-SNAPSHOT -->
        <soke.jira.version>${jira.version}</soke.jira.version>
        <soke.config>${project.build.outputDirectory}/soke-local.config</soke.config>
        <soke.jvmargs />
        <soke.jira.home>${project.build.directory}/jira/home</soke.jira.home>
        <soke.dbConfig>dbconfig-hsql.xml</soke.dbConfig>
    </properties>

    <dependencies>
        <!-- Scala compiler dependency -->
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${scala.version}</version>
            <scope>compile</scope>
        </dependency>
        <!-- this needs to come before jira-pageobjects because both artifacts transitively
           - depend on Netty but we need the Soak version to be used.
          -->
        <dependency>
            <groupId>com.atlassian.soke</groupId>
            <artifactId>soke-client</artifactId>
            <version>${soke.version}</version>
        </dependency>
        <dependency>
            <groupId>org.scalatest</groupId>
            <artifactId>scalatest_2.10.0</artifactId>
            <version>1.8</version>
        </dependency>
        <dependency>
            <groupId>com.atlassian.scalenium</groupId>
            <artifactId>atlassian-scalenium</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>com.atlassian.jira.plugins</groupId>
            <artifactId>jira-development-integration-plugin</artifactId>
            <version>${project.version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.jira.plugins</groupId>
            <artifactId>jira-development-integration-plugin</artifactId>
            <version>${project.version}</version>
            <type>test-jar</type>
        </dependency>
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>atlassian-jira-pageobjects</artifactId>
            <version>${soke.jira.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.federation</groupId>
            <artifactId>federated-api-ctk-test-utilities</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.plugins</groupId>
            <artifactId>atlassian-it-contract-plugin</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>ka-func-test-framework</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.jira.tests</groupId>
            <artifactId>jira-testkit-client</artifactId>
            <scope>compile</scope>
            <exclusions>
                <!-- we already bring in junit though JIRA. too many junits confuses the scala compiler -->
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit-dep</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <!-- used by SOKE -->
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.7</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-core</artifactId>
            <!-- We override the inherited test scope because code in src/main won't compile without Hamcrest -->
            <scope>compile</scope>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>${basedir}/src/main/resources</directory>
            </resource>
            <resource>
                <directory>${basedir}/src/main/config</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>${basedir}/src/test/resources</directory>
                <filtering>true</filtering>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>3.1.5</version>
                <executions>
                    <execution>
                        <id>scala-compile-first</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>scala-test-compile</id>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <!-- compiler args -->
                    <args>
                        <arg>-unchecked</arg>
                        <arg>-deprecation</arg>
                        <arg>-feature</arg>
                        <arg>-language:_</arg>
                    </args>
                    <!--
                        we don't want the scala compiler to go into GC catalepsy,
                        it's slow enough as it is. running in-process causes classpath problems.
                    -->
                    <jvmArgs>
                        <param>-server</param>
                        <param>-XX:+PrintGC</param>
                        <param>-XX:+PrintGCDetails</param>
                        <param>-XX:+PrintGCTimeStamps</param>
                        <param>-XX:+DisableExplicitGC</param>
                        <param>-XX:+UseParallelOldGC</param>
                    </jvmArgs>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>run-soke</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>2.4</version>

                        <executions>
                            <execution>
                                <id>copy-jira</id>
                                <phase>pre-integration-test</phase>

                                <goals>
                                    <goal>unpack</goal>
                                </goals>

                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>com.atlassian.jira</groupId>
                                            <artifactId>jira-standalone-distribution</artifactId>
                                            <version>${soke.jira.version}</version>
                                            <type>tar.gz</type>
                                            <classifier>standalone</classifier>
                                        </artifactItem>
                                    </artifactItems>

                                    <outputDirectory>${project.build.directory}/jira</outputDirectory>
                                </configuration>
                            </execution>

                            <execution>
                                <id>copy-plugins</id>
                                <phase>initialize</phase>

                                <goals>
                                    <goal>copy</goal>
                                </goals>

                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>com.atlassian.jira.plugins</groupId>
                                            <artifactId>jira-development-integration-plugin</artifactId>
                                            <version>${project.version}</version>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>com.atlassian.jira.plugins</groupId>
                                            <artifactId>jira-dvcs-connector-plugin</artifactId>
                                            <version>${dvcs.version}</version>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>com.atlassian.jira.plugins</groupId>
                                            <artifactId>jira-transition-triggers-plugin</artifactId>
                                            <version>${triggers.version}</version>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>com.atlassian.plugins</groupId>
                                            <artifactId>atlassian-remote-event-common-plugin</artifactId>
                                            <version>${remote.events.version}</version>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>com.atlassian.plugins</groupId>
                                            <artifactId>atlassian-remote-event-consumer-plugin</artifactId>
                                            <version>${remote.events.version}</version>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>com.atlassian.jira</groupId>
                                            <artifactId>jira-func-test-plugin</artifactId>
                                            <version>${soke.jira.version}</version>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>com.atlassian.jira.tests</groupId>
                                            <artifactId>jira-testkit-plugin</artifactId>
                                            <version>${testkit.version}</version>
                                        </artifactItem>
                                    </artifactItems>
                                    <outputDirectory>${soke.jira.home}/plugins/installed-plugins/</outputDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.gmaven</groupId>
                        <artifactId>gmaven-plugin</artifactId>
                        <version>1.4</version>
                        <dependencies>
                            <dependency>
                                <groupId>com.atlassian.federation</groupId>
                                <artifactId>federated-api-ctk-server</artifactId>
                                <version>${ctk.version}</version>
                                <scope>compile</scope>
                            </dependency>
                        </dependencies>
                        <executions>
                            <execution>
                                <id>start-jira</id>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>execute</goal>
                                </goals>
                                <configuration>
                                    <scriptpath>
                                        <element>${pom.basedir}/src/main/gmaven</element>
                                    </scriptpath>
                                    <source>
                                        // create a new SokeRunner and pass in all the magical GMaven things
                                        def soke = new SokeRunner(session: session, project: project, log: log, ant: ant, fail: fail)
                                        soke.start()
                                    </source>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>soke-remote</id>
            <properties>
                <soke.remote.config>${project.build.outputDirectory}/soke-remote.config</soke.remote.config>
                <soke.config>${soke.remote.config}</soke.config>
                <soke.usePostgres>true</soke.usePostgres>
                <soke.dbConfig>dbconfig-postgres.xml</soke.dbConfig>
                <soke.dataset>http://datasets.perfeng.atlassian.com/jira/jira-fusion-od-medium-1.0.pgdump</soke.dataset>
                <soke.postgresHome>/usr/lib/postgresql/9.1</soke.postgresHome>
            </properties>
            <build>
                <plugins>
                    <!-- Compile things into a JAR that we can run. In order to get the manifest-based classpath to
                     work on Windows (having whitespaces in directory names), we're copying all dependencies into
                     target/lib and reference that from the JAR. -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>copy-dependencies</id>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>copy-dependencies</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${project.build.directory}/lib</outputDirectory>
                                    <overWriteReleases>false</overWriteReleases>
                                    <overWriteSnapshots>true</overWriteSnapshots>
                                    <overWriteIfNewer>true</overWriteIfNewer>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <artifactId>maven-jar-plugin</artifactId>
                        <configuration>
                            <archive>
                                <manifest>
                                    <addClasspath>true</addClasspath>
                                    <classpathPrefix>lib/</classpathPrefix>
                                </manifest>
                            </archive>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <!-- Download and attach JProfiler -->
            <id>profile</id>
            <properties>
                <jprofiler.home>${project.build.directory}/jprofiler7</jprofiler.home>
                <jprofiler.version>7.2.3</jprofiler.version>
                <!-- Profile 108 uses Dynamic Instrumentation of method calls - VERY slow, but highly accurate
                     Profile 109 uses Call Strack inspection to work out cpu sampling - fast and reasonably accurate -->
                <jprofiler.profileid>109</jprofiler.profileid>
                <jprofiler.configfile>${project.build.directory}/test-classes/jprofiler.xml</jprofiler.configfile>
                <jprofiler.agentpath>${jprofiler.home}/bin/linux-x64/libjprofilerti.so</jprofiler.agentpath>
                <jprofiler.jvmargs>-agentpath:${jprofiler.agentpath}=offline,id=${jprofiler.profileid},config=${jprofiler.configfile}</jprofiler.jvmargs>

                <!-- start profiling after this number of seconds -->
                <start.profile.secs>60</start.profile.secs>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>31_unpack-jprofiler</id>
                                <phase>process-test-classes</phase>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>com.ej-technologies</groupId>
                                            <artifactId>jprofiler</artifactId>
                                            <type>tar.gz</type>
                                            <version>${jprofiler.version}</version>
                                        </artifactItem>
                                    </artifactItems>
                                    <outputDirectory>${project.build.directory}</outputDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
