<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>org.fcrepo</groupId>
    <artifactId>fcrepo</artifactId>
    <version>4.0.0-alpha-2</version>
  </parent>

  <artifactId>fcrepo-webapp</artifactId>
  <name>${project.artifactId}</name>
  <description>The Fedora web application</description>
  <packaging>war</packaging>

  <properties>
    <!-- integration test properties -->
    <test.context.path>/</test.context.path>
    
    <!-- jmeter -->
    <jmeter.loop_count>100</jmeter.loop_count>
    <jmeter.num_threads>10</jmeter.num_threads>
    <jmeter.exit.check.pause>2000</jmeter.exit.check.pause>
    <jmeter.fixtures.dir>${project.build.directory}${file.separator}jmeter${file.separator}fixtures</jmeter.fixtures.dir>
    <jmeter.log.dir>${project.build.directory}${file.separator}jmeter${file.separator}log</jmeter.log.dir>
  
    <!-- sonar -->
    <sonar.artifact.path>${project.build.directory}${file.separator}${project.artifactId}-${project.version}.war</sonar.artifact.path>

    <build.timestamp>${maven.build.timestamp}</build.timestamp>
    <maven.build.timestamp.format>yyyy-MM-dd</maven.build.timestamp.format>
  </properties>

  <dependencies>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
    </dependency>
    <dependency>
      <groupId>org.fcrepo</groupId>
      <artifactId>fcrepo-kernel</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.fcrepo</groupId>
      <artifactId>fcrepo-audit</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.fcrepo</groupId>
      <artifactId>fcrepo-jms</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.fcrepo</groupId>
      <artifactId>fcrepo-generator-dc</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.fcrepo</groupId>
      <artifactId>fcrepo-http-api</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.fcrepo</groupId>
      <artifactId>fcrepo-transform</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.fcrepo</groupId>
      <artifactId>fcrepo-auth-oauth</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.fcrepo</groupId>
      <artifactId>fcrepo-storage-policy</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>com.sun.jersey.contribs</groupId>
      <artifactId>jersey-spring</artifactId>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
    </dependency>

    <!-- test gear -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
    </dependency>

  </dependencies>

  <build>

    <plugins>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
          <attachClasses>true</attachClasses>
          <webResources>
            <resource>
              <directory>src/main/webapp</directory>
              <filtering>true</filtering>
              <includes>
                <include>index.html</include>
              </includes>
            </resource>
          </webResources>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-failsafe-plugin</artifactId>
        <configuration>
          <systemPropertyVariables>
            <test.port>${test.port}</test.port>
            <test.context.path>${test.context.path}</test.context.path>
          </systemPropertyVariables>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <configuration>
          <portNames>
            <portName>test.port</portName>
            <!-- reserves the stop port for jetty-maven-plugin -->
            <portName>jetty.port.stop</portName>
          </portNames>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <configuration>
          <loginServices>
            <loginService implementation="org.eclipse.jetty.security.HashLoginService">
              <name>fcrepo</name>
              <config>${project.build.directory}/test-classes/jetty-users.properties</config>
            </loginService>
          </loginServices>
          <scanIntervalSeconds>2</scanIntervalSeconds>
          <stopKey>STOP</stopKey>
          <webApp>
            <contextPath>${test.context.path}</contextPath>
          </webApp>

          <systemProperties>

            <systemProperty>
              <name>
                com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean.default.objectStoreDir
              </name>
              <value>${project.build.directory}/object-store-default</value>
            </systemProperty>

            <systemProperty>
              <name>com.arjuna.ats.arjuna.objectstore.objectStoreDir</name>
              <value>${project.build.directory}/object-store</value>
            </systemProperty>

            <systemProperty>
              <name>fcrepo.activemq.dir</name>
              <value>${project.build.directory}/active-mq</value>
            </systemProperty>

          </systemProperties>

        </configuration>
        <executions>
          <execution>
            <id>start-jetty</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>stop</goal>
              <goal>start</goal>
            </goals>
            <configuration>
              <connectors>
                <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                  <port>${test.port}</port>
                  <maxIdleTime>60000</maxIdleTime>
                </connector>
              </connectors>
              <daemon>true</daemon>
              <stopPort>${jetty.port.stop}</stopPort>
            </configuration>
          </execution>
          <execution>
            <id>stop-jetty</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>stop</goal>
            </goals>
            <configuration>
              <stopPort>${jetty.port.stop}</stopPort>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>buildnumber-maven-plugin</artifactId>
        <version>1.2</version>
        <executions>
          <execution>
            <phase>validate</phase>
            <goals>
              <goal>create</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <doCheck>false</doCheck>
          <doUpdate>false</doUpdate>
          <getRevisionOnlyOnce>true</getRevisionOnlyOnce>
          <shortRevisionLength>8</shortRevisionLength>
        </configuration>
      </plugin>

    </plugins>
  </build>

  <profiles>
    <profile>
      <id>jmeter</id>
      <build>
        <plugins>
          <plugin>
            <groupId>com.lazerycode.jmeter</groupId>
            <artifactId>jmeter-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>jmeter-tests</id>
                <phase>integration-test</phase>
                <goals>
                  <goal>jmeter</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <propertiesJMeter>
                <!-- Extend the period (in ms) JMeter waits for threads to close -->
                <!-- See: https://github.com/Ronnie76er/jmeter-maven-plugin/issues/56 -->
                <jmeter.exit.check.pause>${jmeter.exit.check.pause}</jmeter.exit.check.pause>
              </propertiesJMeter>
              <propertiesUser>
                <fedora_4_port>${test.port}</fedora_4_port>
                <fedora_4_context>rest</fedora_4_context>
                <loop_count>${jmeter.loop_count}</loop_count>
                <num_threads>${jmeter.num_threads}</num_threads>
                <fixtures>${jmeter.fixtures.dir}</fixtures>
                <log>${jmeter.log.dir}</log>
              </propertiesUser>
              <resultsFileNameDateFormat>'jmeter'</resultsFileNameDateFormat>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
