<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.bamboo</groupId>
    <artifactId>atlassian-bamboo</artifactId>
    <version>5.6.0</version>
  </parent>

  <artifactId>atlassian-bamboo-soke-test</artifactId>

  <name>Bamboo Soke Test</name>
  <description>Bamboo performance tests based on Soke platform</description>

  <properties>
    <soke.version>3.1.2</soke.version>
    <license.scope>test</license.scope>
  </properties>

  <dependencies>
    <dependency>
      <groupId>com.atlassian.soke</groupId>
      <artifactId>soke-client</artifactId>
      <version>3.1.2</version>
      <exclusions>
        <exclusion>
          <groupId>stax</groupId>
          <artifactId>stax-api</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.apache.commons</groupId>
          <artifactId>commons-io</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>com.atlassian.bamboo</groupId>
      <artifactId>atlassian-bamboo-pageobjects</artifactId>
      <version>${project.version}</version>
    </dependency>

    <!-- c.a.b.testutils.TestBuildDetails needed during plan creation: -->
    <dependency>
      <groupId>com.atlassian.bamboo</groupId>
      <artifactId>atlassian-bamboo-test-utils</artifactId>
      <version>${project.version}</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>

  <profiles>
    <profile>
      <id>soke-ci-test</id>
      <properties>
        <!-- Non-soke properties - You can change these -->
        <artifactToDeploy>atlassian-bamboo-web-app</artifactToDeploy>
        <brokerUri>tcp://localhost:61620</brokerUri>

        <jdbc.artifactGroup>hsqldb</jdbc.artifactGroup>
        <jdbc.artifactId>hsqldb</jdbc.artifactId>

        <appServer.host>localhost</appServer.host>
        <appServer.port>6990</appServer.port>
        <appServer.contextRoot>bamboo</appServer.contextRoot>
        <baseURL>http://${appServer.host}:${appServer.port}/${appServer.contextRoot}</baseURL>

        <tomcat.url>https://maven.atlassian.com/public/org/apache/tomcat/apache-tomcat/6.0.20/apache-tomcat-6.0.20.zip</tomcat.url>
        <target.cargo>${project.build.directory}/cargo</target.cargo>

        <jvm.gcverbose>-XX:+PrintGCTimeStamps -verbosegc -XX:+PrintGCDetails -XX:+UseParallelOldGC</jvm.gcverbose>
        <jvm.initialHeap>64</jvm.initialHeap>
        <jvm.maxHeap>2048</jvm.maxHeap>
        <jvm.permGen>512</jvm.permGen>
        <jvm.heapsize>-Xms${jvm.initialHeap}m -Xmx${jvm.maxHeap}m -XX:MaxPermSize=${jvm.permGen}m</jvm.heapsize>

        <!-- Soke properties - You should leave these -->
        <soke.client.main>com.atlassian.soak.client.Main</soke.client.main>
        <soke.config>soke-master</soke.config>
      </properties>

      <dependencies>
        <dependency>
          <groupId>com.atlassian.selenium</groupId>
          <artifactId>atlassian-webdriver-core</artifactId>
          <version>${atlassian.selenium.version}</version>
          <exclusions>
            <!-- due to https://studio.atlassian.com/browse/SELENIUM-190, remove when fixed -->
            <exclusion>
              <groupId>com.google.collections</groupId>
              <artifactId>google-collections</artifactId>
            </exclusion>

            <!-- we banned stax-api in the Bamboo parent pom.xml with maven-enforcer-plugin - we must exclude it here too -->
            <exclusion>
              <groupId>stax</groupId>
              <artifactId>stax-api</artifactId>
            </exclusion>
          </exclusions>
        </dependency>

        <dependency>
          <groupId>com.atlassian.testtools</groupId>
          <artifactId>atlassian-testtools</artifactId>
          <version>1.8</version>
        </dependency>

        <!-- test dependencies for cargo -->
        <dependency>
          <groupId>com.atlassian.bamboo</groupId>
          <artifactId>atlassian-bamboo-web-app</artifactId>
          <version>${project.version}</version>
          <type>war</type>
        </dependency>

        <!-- Scala compiler dependency -->
        <dependency>
          <groupId>org.scala-lang</groupId>
          <artifactId>scala-library</artifactId>
          <version>2.10.3</version>
          <scope>compile</scope>
        </dependency>

        <dependency>
          <groupId>commons-codec</groupId>
          <artifactId>commons-codec</artifactId>
          <version>1.6</version>
        </dependency>
      </dependencies>

      <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>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>-->
            <!--<groupId>org.apache.maven.plugins</groupId>-->
            <!--<artifactId>maven-antrun-plugin</artifactId>-->
            <!--<executions>-->
              <!--<execution>-->
                <!--<phase>pre-integration-test</phase>-->
                <!--<goals>-->
                  <!--<goal>run</goal>-->
                <!--</goals>-->
                <!--<configuration>-->
                  <!--<tasks>-->
                    <!--<unzip src="src/main/resources/bigdata.zip" dest="${project.build.directory}/bamboo-home" overwrite="true" />-->
                  <!--</tasks>-->
                <!--</configuration>-->
              <!--</execution>-->
            <!--</executions>-->
          <!--</plugin>-->
          <plugin>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
              <archive>
                <manifest>
                  <addClasspath>true</addClasspath>
                  <classpathPrefix>lib/</classpathPrefix>
                  <mainClass>${soke.client.main}</mainClass>
                </manifest>
              </archive>
            </configuration>
          </plugin>

          <!-- Now, spin up Tomcat via cargo. -->
          <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <version>1.1.4</version>
            <configuration>
              <container>
                <containerId>tomcat6x</containerId>
                <zipUrlInstaller>
                  <url>${tomcat.url}</url>
                  <installDir>${java.io.tmpdir}/cargo/installs</installDir>
                </zipUrlInstaller>

                <output>${target.cargo}/output.log</output>
                <log>${target.cargo}/cargo-log.log</log>

                <systemProperties>
                  <bamboo.home>${project.build.directory}/bamboo-home</bamboo.home>
                  <bamboo.jms.broker.uri>${brokerUri}</bamboo.jms.broker.uri>
                </systemProperties>

                <timeout>240000</timeout>

              </container>
              <configuration>
                <home>${target.cargo}/container</home>

                <properties>
                  <cargo.servlet.port>${appServer.port}</cargo.servlet.port>
                  <cargo.jvmargs>${jvm.gcverbose} ${jvm.heapsize}</cargo.jvmargs>
                </properties>

                <deployables>
                  <deployable>
                    <groupId>com.atlassian.bamboo</groupId>
                    <artifactId>${artifactToDeploy}</artifactId>
                    <type>war</type>

                    <properties>
                      <context>${appServer.contextRoot}</context>
                    </properties>

                    <pingURL>${baseURL}</pingURL>
                    <pingTimeout>240000</pingTimeout>
                  </deployable>
                </deployables>
              </configuration>
            </configuration>
            <executions>
              <execution>
                <id>start-container</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>start</goal>
                  <goal>deploy</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <!-- Run the Soke Client -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2</version>
            <executions>
              <execution>
                <id>snapshots-in-manifest-classpath-hack</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration>
                  <executable>bash</executable>
                  <arguments>
                    <argument>-c</argument>
                    <argument>for file in `find target/lib -name '*-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9]-*'`; do mv -v $file `echo $file | sed -e 's/[0-9]\{8\}\.[0-9]\{6\}-[0-9]\{1,\}/SNAPSHOT/'`; done</argument>
                  </arguments>
                </configuration>
              </execution>
              <!-- lets populate the instance with some plans, todo: use different, real mechanism for setting up Bamboo instance ready for performance tests  -->
              <execution>
                <id>run-soak-tests</id>
                <phase>integration-test</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration>
                  <executable>java</executable>
                  <workingDirectory>target</workingDirectory>
                  <arguments>
                    <argument>-Dsoke.config=classes/${soke.config}.conf</argument>
                    <argument>-jar</argument>
                    <argument>${project.artifactId}-${project.version}.jar</argument>
                  </arguments>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <!-- Scala compilation plugins -->
          <plugin>
            <!--<groupId>net.alchim31.maven</groupId>-->
            <!--<artifactId>scala-maven-plugin</artifactId>-->
            <!--<version>3.1.0</version>-->
            <groupId>org.scala-tools</groupId>
            <artifactId>maven-scala-plugin</artifactId>
            <version>2.13.1</version>
            <executions>
              <execution>
                <id>scala-compile-first</id>
                <phase>process-resources</phase>
                <goals>
                  <goal>add-source</goal>
                  <goal>compile</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <jvmArgs>
                <param>-server</param>
              </jvmArgs>
            </configuration>
          </plugin>
          <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <source>1.6</source>
              <target>1.6</target>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>


</project>
