<?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/maven-v4_0_0.xsd">

  <parent>
    <groupId>com.sismics.docs</groupId>
    <artifactId>docs-parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>../docs-parent</relativePath>
  </parent>
  
  <modelVersion>4.0.0</modelVersion>
  <artifactId>docs-web</artifactId>
  <packaging>war</packaging>
  <name>Docs Web</name>

  <dependencies>
    <!-- Dependencies to Docs -->
    <dependency>
      <groupId>com.sismics.docs</groupId>
      <artifactId>docs-core</artifactId>
    </dependency>
    
    <dependency>
      <groupId>com.sismics.docs</groupId>
      <artifactId>docs-web-common</artifactId>
    </dependency>
    
    <!-- Dependencies to Jersey -->
    <dependency>
      <groupId>com.sun.jersey</groupId>
      <artifactId>jersey-server</artifactId>
    </dependency>
    
    <dependency>
      <groupId>com.sun.jersey</groupId>
      <artifactId>jersey-bundle</artifactId>
    </dependency>
    
    <dependency>
      <groupId>com.sun.jersey</groupId>
      <artifactId>jersey-json</artifactId>
    </dependency>
    
    <dependency>
      <groupId>com.sun.jersey.contribs</groupId>
      <artifactId>jersey-multipart</artifactId>
    </dependency>
      
    <!-- Other external dependencies -->
    <dependency>
      <groupId>commons-lang</groupId>
      <artifactId>commons-lang</artifactId>
    </dependency>
    
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
    </dependency>

    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
    </dependency>
    
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
    </dependency>
  
    <dependency>
      <groupId>commons-dbcp</groupId>
      <artifactId>commons-dbcp</artifactId>
    </dependency>

    <dependency>
      <groupId>org.mortbay.jetty</groupId>
      <artifactId>servlet-api</artifactId>
      <scope>provided</scope>
    </dependency>
  
    <dependency>
      <groupId>joda-time</groupId>
      <artifactId>joda-time</artifactId>
    </dependency>

    <dependency>
      <groupId>org.hsqldb</groupId>
      <artifactId>hsqldb</artifactId>
    </dependency>

    <!-- Test dependencies -->
    <dependency>
      <groupId>com.sismics.docs</groupId>
      <artifactId>docs-web-common</artifactId>
      <type>test-jar</type>
      <scope>test</scope>
    </dependency>
    
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>com.sun.grizzly</groupId>
      <artifactId>grizzly-servlet-webserver</artifactId>
      <scope>test</scope>
    </dependency>
    
    <dependency>
      <groupId>com.sun.jersey.jersey-test-framework</groupId>
      <artifactId>jersey-test-framework-grizzly2</artifactId>
      <scope>test</scope>
    </dependency>
    
    <dependency>
      <groupId>org.subethamail</groupId>
      <artifactId>subethasmtp-wiser</artifactId>
      <scope>test</scope>
    </dependency>
    
  </dependencies>

  <build>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <configuration>
          <systemProperties>
            <systemProperty>
              <name>webapp.root</name>
              <value>${basedir}/src/main/webapp</value>
            </systemProperty>
          </systemProperties>
          <scanIntervalSeconds>0</scanIntervalSeconds>
          <webAppConfig>
            <contextPath>/docs-web</contextPath>
            <extraClasspath>target/classes;../docs-core/target/classes</extraClasspath>
            <overrideDescriptor>src/dev/main/webapp/web-override.xml</overrideDescriptor>
          </webAppConfig>
          <stopKey>STOPKEY</stopKey>
          <stopPort>1099</stopPort>
        </configuration>
      </plugin>

    </plugins>
    <pluginManagement>
      <plugins>
        <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
        <plugin>
          <groupId>org.eclipse.m2e</groupId>
          <artifactId>lifecycle-mapping</artifactId>
          <version>1.0.0</version>
          <configuration>
            <lifecycleMappingMetadata>
              <pluginExecutions>
                <pluginExecution>
                  <pluginExecutionFilter>
                    <groupId>com.samaxes.maven</groupId>
                    <artifactId>
                      minify-maven-plugin
                    </artifactId>
                    <versionRange>[1.5,)</versionRange>
                    <goals>
                      <goal>minify</goal>
                    </goals>
                  </pluginExecutionFilter>
                  <action>
                    <ignore />
                  </action>
                </pluginExecution>
              </pluginExecutions>
            </lifecycleMappingMetadata>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

  <profiles>
    <!-- Development profile (active by default) -->
    <profile>
      <id>dev</id>
      <activation>
        <activeByDefault>true</activeByDefault>
        <property>
          <name>env</name>
          <value>dev</value>
        </property>
      </activation>
      
      <build>
        <resources>
          <resource>
            <directory>src/dev/resources</directory>
            <filtering>false</filtering>
            <excludes>
              <exclude>**/config.properties</exclude>
            </excludes>
          </resource>
          <resource>
            <directory>src/dev/resources</directory>
            <filtering>true</filtering>
            <includes>
              <include>**/config.properties</include>
            </includes>
          </resource>
        </resources>

        <plugins>
          <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <configuration>
              <scanIntervalSeconds>0</scanIntervalSeconds>
              <webAppConfig>
                <contextPath>/docs-web</contextPath>
                <extraClasspath>target/classes;../docs-core/target/classes</extraClasspath>
                <overrideDescriptor>src/dev/main/webapp/web-override.xml</overrideDescriptor>
              </webAppConfig>
              <stopKey>STOPKEY</stopKey>
              <stopPort>1099</stopPort>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    
    <!-- Production profile -->
    <profile>
      <id>prod</id>
      <activation>
        <property>
          <name>env</name>
          <value>prod</value>
        </property>
      </activation>
      
      <build>
        <resources>
          <resource>
            <directory>src/prod/resources</directory>
            <filtering>false</filtering>
            <excludes>
              <exclude>**/config.properties</exclude>
            </excludes>
          </resource>
          <resource>
            <directory>src/prod/resources</directory>
            <filtering>true</filtering>
            <includes>
              <include>**/config.properties</include>
            </includes>
          </resource>
        </resources>
        
        <plugins>
        
          <!-- Launch NPM & Grunt -->
          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
            <executions>
              <execution>
                <phase>generate-sources</phase>
                <configuration>
                  <target name="building">
                    <!-- npm install -->
                    <exec executable="cmd" dir="${project.basedir}/src/main/webapp" osfamily="windows" failonerror="true">
                      <arg line="/c npm install" />
                    </exec>
                    <exec executable="npm" dir="${project.basedir}/src/main/webapp" osfamily="unix" failonerror="true">
                      <arg line="install" />
                    </exec>
                    <!-- grunt -->
                    <exec executable="cmd" dir="${project.basedir}/src/main/webapp" osfamily="windows">
                      <arg line="/c grunt --apiurl=api" />
                    </exec>
                    <exec executable="grunt" dir="${project.basedir}/src/main/webapp" osfamily="unix">
                      <arg line="--apiurl=api" />
                    </exec>
                  </target>
                </configuration>
                <goals>
                  <goal>run</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        
          <!-- WAR generation -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
              <warSourceDirectory>${basedir}/src/main/webapp/dist</warSourceDirectory>
              <webXml>src\main\webapp\WEB-INF\web.xml</webXml>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    
    <!-- Hosted version profile -->
    <profile>
      <id>hosted</id>
      <activation>
        <property>
          <name>env</name>
          <value>hosted</value>
        </property>
      </activation>
      
      <build>
        <resources>
          <resource>
            <directory>src/hosted/resources</directory>
            <filtering>false</filtering>
          </resource>
        </resources>
      </build>
    </profile>
  </profiles>
</project>
