<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at
  
  http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
-->

<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>

  <groupId>org.apache.sling</groupId>
  <artifactId>microsling-core</artifactId>
  <packaging>war</packaging>
  <name>microsling</name>
  <!--
    WARNING: if changing this, change microsling.http.server.url below as well 
   -->
  <version>1.0-incubator-SNAPSHOT</version>
  
  <url>http://incubator.apache.org/sling</url>

  <properties>
    <!-- 
      Use the Jackrabbit trunk, mostly because JCR-955
      makes it easier to reuse the servlets from the
      jackrabbit-webapp module.
    -->
    <jackrabbit.version>1.4-SNAPSHOT</jackrabbit.version>
    
    <!-- 
      Defines which tests are for the "integration-testing" phase
     -->
    <integration.test.code.path>**/microsling/integration</integration.test.code.path>
    
    <!-- 
      Set this to true to stop mvn once the integration test Jetty instance is
      started. Useful to manually test the integration testing webapp.
     -->
     <integration.test.wait>false</integration.test.wait>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.jruby</groupId>
      <artifactId>jruby-complete</artifactId>
      <version>1.0RC3</version>
    </dependency>
    <dependency>
      <groupId>org.apache.sling</groupId>
      <artifactId>sling-api</artifactId>
      <version>2.0.0-incubator-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>org.apache.sling</groupId>
      <artifactId>sling-json</artifactId>
      <version>2.0.0-incubator-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.4</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.jackrabbit</groupId>
      <artifactId>jackrabbit-webapp</artifactId>
      <version>${jackrabbit.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.jackrabbit</groupId>
      <artifactId>jackrabbit-jcr-servlet</artifactId>
      <version>${jackrabbit.version}</version>
    </dependency>
    <dependency>
      <groupId>javax.jcr</groupId>
      <artifactId>jcr</artifactId>
      <version>1.0</version>
    </dependency>
    <dependency>
      <groupId>org.apache.velocity</groupId>
      <artifactId>velocity</artifactId>
      <version>1.5</version>
    </dependency>
    <dependency>
      <groupId>rhino</groupId>
      <artifactId>js</artifactId>
      <version>1.6R6</version>
    </dependency>
    <dependency>
        <groupId>freemarker</groupId>
        <artifactId>freemarker</artifactId>
        <version>2.3.6</version>
    </dependency>
    <dependency>
      <groupId>commons-httpclient</groupId>
      <artifactId>commons-httpclient</artifactId>
      <version>3.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
          <encoding>UTF-8</encoding>
        </configuration>
      </plugin>
      <plugin>
        <!-- SLING-66: create a jar in addition to our war, to make our servlets reusable -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>
          <execution>
            <id>attach-classes</id>
            <phase>package</phase>
            <goals>
              <goal>jar</goal>
            </goals>
            <configuration>
              <!-- using the classifier makes the jar an attachement -->
              <classifier>classes</classifier>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <version>6.1.5</version>
        <configuration>
          <contextPath>/</contextPath>
          <scanIntervalSeconds>10</scanIntervalSeconds>
          <connectors>
            <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
              <port>8080</port>
              <maxIdleTime>60000</maxIdleTime>
            </connector>
          </connectors>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <systemProperties>
            <!-- 
              WARNING: make sure these URLs are consistent with the
              cargo-maven2-plugin settings: AFAIK Maven does not
              expand variables in the <value> element.
              And WARNING: these properties are duplicated somewhere in this
              POM with slightly different values...there must be a better way. 
            -->
            <property>
              <name>microsling.http.server.url</name>
              <value>http://localhost:8080</value>
            </property>
            <property>
              <name>microsling.webdav.server.url</name>
              <value>http://localhost:8080/repository/default</value>
            </property>
          </systemProperties>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <!--
        Run the cargo-based integration tests.
        This profile is active by default, to deactivate it activate another
        one, for example " mvn -P nullProfile".
        
        TODO there must be a way to control this with "mvn.test.skip", but I haven't
        found it. 
       -->
      <id>cargoIntegrationTesting</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <executions>
              <execution>
                <id>surefire-integration-test</id>
                <phase>integration-test</phase>
                <goals>
                  <goal>test</goal>
                </goals>
                <configuration>
                  <excludes>
                    <exclude>none</exclude>
                  </excludes>
                  <includes>
                    <include>${integration.test.code.path}/**Test.java</include>
                  </includes>
                  <systemProperties>
                    <!-- 
                      WARNING: make sure these URLs are consistent with the
                      cargo-maven2-plugin settings: AFAIK Maven does not
                      expand variables in the <value> element.
                      And WARNING: these properties are duplicated somewhere in this
                      POM with slightly different values...there must be a better way. 
                    -->
                    <property>
                      <name>microsling.http.server.url</name>
                      <value>http://localhost:8080/microsling-core-1.0-incubator-SNAPSHOT</value>
                    </property>
                    <property>
                      <name>microsling.webdav.server.url</name>
                      <value>http://localhost:8080/microsling-core-1.0-incubator-SNAPSHOT/repository/default</value>
                    </property>
                  </systemProperties>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <version>0.3.1</version>
            <executions>
              <execution>
                <id>start-container</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>start</goal>
                </goals>
              </execution>
              <execution>
                <id>stop-container</id>
                <phase>post-integration-test</phase>
                <goals>
                  <goal>stop</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <wait>${integration.test.wait}</wait>
              <container>
                <containerId>jetty6x</containerId>
                <type>embedded</type>
              </container>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <!--
        By default, do not run the integration tests in the test phase, as they have
        no microsling to talk to.
        To debug the integration tests faster than with the normal build cycle,
        deactivate this profile (using -P nullProfile for example) and run a
        separate instance of microsling that the tests can talk to.
       -->
      <id>disableIntegrationTestsInTestPhase</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <excludes>
                <exclude>${integration.test.code.path}/**.java</exclude>
              </excludes>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <!-- 
        Useful to deactivate other profiles from the command-line
        Is there a better way? mvn doesn't have a "deactivate profile" option. 
       -->
      <id>nullMicroslingProfile</id>
    </profile>
  </profiles>

</project>
