<?xml version="1.0"?>
<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>org.camunda.bpm.webapp</groupId>
    <artifactId>camunda-webapp-root</artifactId>
    <version>7.2.0-alpha2</version>
  </parent>

  <artifactId>camunda-webapp</artifactId>
  <groupId>org.camunda.bpm.webapp</groupId>
  <packaging>war</packaging>
  <name>camunda BPM - webapp - app</name>

  <properties>
    <web.resources.override>src/main/runtime/default/webapp</web.resources.override>
    <java.resources.override>src/main/runtime/default/resources</java.resources.override>
    <properties.override>src/main/runtime/default/config.properties</properties.override>

    <exec.shell>bash</exec.shell>
    <exec.arg>-c</exec.arg>

    <grunt.target>development</grunt.target>
  </properties>

  <dependencies>

    <dependency>
      <groupId>org.camunda.bpm.webapp</groupId>
      <artifactId>camunda-webapp-core</artifactId>
    </dependency>

    <!-- the tasklist UI -->
    <dependency>
      <groupId>org.camunda.bpm.webapp</groupId>
      <artifactId>camunda-tasklist-ui</artifactId>
      <version>${project.version}</version>
      <type>zip</type>
      <scope>provided</scope>
    </dependency>

    <!-- jee spec -->
    <dependency>
      <groupId>org.jboss.spec</groupId>
      <artifactId>jboss-javaee-6.0</artifactId>
      <type>pom</type>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.camunda.bpm</groupId>
      <artifactId>camunda-engine</artifactId>
      <scope>provided</scope>
    </dependency>

    <!-- rest api -->
    <dependency>
      <groupId>org.camunda.bpm</groupId>
      <artifactId>camunda-engine-rest</artifactId>
      <classifier>classes</classifier>
    </dependency>

    <!-- tests -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>com.fasterxml.uuid</groupId>
      <artifactId>java-uuid-generator</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.easytesting</groupId>
      <artifactId>fest-assert</artifactId>
      <version>1.4</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.camunda.bpm.webapp</groupId>
      <artifactId>camunda-webapp-test-utility</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.jboss.shrinkwrap.resolver</groupId>
      <artifactId>shrinkwrap-resolver-impl-maven</artifactId>
      <scope>test</scope>
    </dependency>

    <!-- arquillian tests -->
    <dependency>
      <groupId>org.jboss.arquillian.junit</groupId>
      <artifactId>arquillian-junit-container</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>com.sun.jersey</groupId>
      <artifactId>jersey-client</artifactId>
      <version>1.17</version>
      <scope>test</scope>
    </dependency>

  </dependencies>

  <build>
    <finalName>camunda-webapp</finalName>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
      </resource>
      <resource>
        <directory>${java.resources.override}</directory>
        <filtering>true</filtering>
      </resource>
    </resources>
    <plugins>
      <!-- using grunt to build front-end resources -->
      <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
        <version>0.0.12</version>

        <executions>
          <!-- install node automagically -->
          <execution>
            <id>front-end-setup</id>
            <goals>
              <goal>install-node-and-npm</goal>
            </goals>
            <configuration>
              <nodeVersion>v0.10.18</nodeVersion>
              <npmVersion>1.3.8</npmVersion>
            </configuration>
          </execution>
          
          <!-- install package dependencies -->
          <execution>
            <id>front-end-npm-install</id>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>install</arguments>
            </configuration>
          </execution>
          
          <!-- build front-end resources -->
          <execution>
            <id>front-end-grunt-build</id>
            <goals>
              <goal>grunt</goal>
            </goals>
            <phase>generate-resources</phase>
            <configuration>
              <arguments>build:dist</arguments>
            </configuration>
          </execution>

          <!-- test front-end resources -->
          <execution>
            <id>front-end-grunt-test</id>
            <goals>
              <goal>grunt</goal>
            </goals>
            <phase>test</phase>
            <configuration>
              <arguments>test</arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
          <webResources>
            <resource>
              <filtering>true</filtering>
              <directory>${web.resources.override}</directory>
            </resource>
            <resource>
              <filtering>true</filtering>
              <directory>target/webapp</directory>
              <!-- no filtering for favicon because linux destroys images through carriage return -->
              <excludes>
                <exclude>assets/img/favicon.ico</exclude>
              </excludes>
            </resource>
          </webResources>
          <archive>
            <manifest>
              <!-- Maven project version number -->
              <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
            </manifest>
          </archive>
          <!-- exclude development resources (task forms etc.) -->
          <packagingExcludes>
            develop/**
          </packagingExcludes>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <failIfNoTests>false</failIfNoTests>
          <trimStackTrace>false</trimStackTrace>
          <redirectTestOutputToFile>true</redirectTestOutputToFile>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>
          <execution>
            <id>create-jar</id>
            <goals>
              <goal>jar</goal>
            </goals>
            <phase>package</phase>
            <configuration>
              <classifier>classes</classifier>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>unpack</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.camunda.bpm.webapp</groupId>
                  <artifactId>camunda-tasklist-ui</artifactId>
                  <type>zip</type>
                  <overWrite>true</overWrite>
                  <outputDirectory>${project.build.directory}/webapp/app/tasklist</outputDirectory>
                </artifactItem>
              </artifactItems>
            </configuration>
           </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>distro</id>
      <properties>
        <grunt.target>production</grunt.target>
      </properties>
    </profile>
    <profile>
      <activation>
        <os>
          <family>Windows</family>
        </os>
      </activation>
      <properties>
        <exec.shell>cmd</exec.shell>
        <exec.arg>/c</exec.arg>
      </properties>
    </profile>
    <profile>
      <id>tomcat</id>
      <dependencies>
        <dependency>
          <groupId>org.jboss.resteasy</groupId>
          <artifactId>resteasy-jaxrs</artifactId>
          <scope>runtime</scope>
        </dependency>
      </dependencies>
      <properties>
        <web.resources.override>src/main/runtime/tomcat/webapp</web.resources.override>
        <java.resources.override>src/main/runtime/tomcat/resources</java.resources.override>
      </properties>
    </profile>

    <profile>
      <id>jboss</id>
      <dependencies>
        <dependency>
          <groupId>org.jboss.resteasy</groupId>
          <artifactId>resteasy-jaxrs</artifactId>
          <scope>provided</scope>
        </dependency>
      </dependencies>
      <properties>
        <web.resources.override>src/main/runtime/jboss/webapp</web.resources.override>
        <java.resources.override>src/main/runtime/jboss/resources</java.resources.override>
      </properties>

      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
              <archive>
                <manifest>
                  <!-- Maven project version number -->
                  <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                </manifest>
                <manifestEntries>
                  <!-- module dependencies for deployment on AS 7 -->
                  <Dependencies>org.camunda.bpm.camunda-engine</Dependencies>
                </manifestEntries>
              </archive>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>develop</id>
      <dependencies>
        <dependency>
          <groupId>org.jboss.resteasy</groupId>
          <artifactId>resteasy-jaxrs</artifactId>
          <scope>runtime</scope>
        </dependency>
        <dependency>
          <groupId>org.camunda.bpm</groupId>
          <artifactId>camunda-engine</artifactId>
        </dependency>
        <dependency>
          <groupId>org.camunda.bpm.identity</groupId>
          <artifactId>camunda-identity-ldap</artifactId>
          <version>${project.version}</version>
        </dependency>
        <dependency>
          <groupId>com.h2database</groupId>
          <artifactId>h2</artifactId>
        </dependency>
        <dependency>
          <groupId>com.fasterxml.uuid</groupId>
          <artifactId>java-uuid-generator</artifactId>
        </dependency>
        
        <dependency>
          <groupId>org.apache.tomcat</groupId>
          <artifactId>tomcat-jdbc</artifactId>
          <version>7.0.33</version>
        </dependency>
    
        <dependency>
          <groupId>org.apache.tomcat</groupId>
          <artifactId>tomcat-juli</artifactId>
          <version>7.0.33</version>
        </dependency>
      </dependencies>
      <build>
        <plugins>
          <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>8.1.14.v20131031</version>
            <configuration>
              <webAppSourceDirectory>${project.basedir}/target/webapp</webAppSourceDirectory>
              <webAppConfig>
                <contextPath>/camunda</contextPath>
                <defaultsDescriptor>${project.basedir}/src/main/runtime/develop/jetty/webdefault.xml</defaultsDescriptor>
              </webAppConfig>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>add-sources</id>
                <goals>
                  <goal>add-source</goal>
                </goals>
                <configuration>
                  <sources>
                    <source>src/main/runtime/develop/java</source>
                  </sources>
                </configuration>
              </execution>
              <execution>
                <id>add-resources</id>
                <goals>
                  <goal>add-resource</goal>
                </goals>
                <configuration>
                  <resources>
                    <resource>
                      <directory>src/main/runtime/develop/resources</directory>
                    </resource>
                  </resources>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
      <properties>
        <java.resources.override>src/main/runtime/develop/resources</java.resources.override>
      </properties>
    </profile>

    <!-- database QA profiles -->

    <profile>
      <id>database</id>

      <properties>
        <db.properties.file>${user.home}/.camunda/jdbc/cockpit.${database}.properties</db.properties.file>
      </properties>

      <activation>
        <property>
          <name>database</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <!--
              only worked with this version, there might be a bug with antrun
              see http://jira.codehaus.org/browse/MANTRUN-109
            -->
            <version>1.4</version>
            <executions>
              <execution>
                <id>database-test-create-schema</id>
                <phase>process-test-classes</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <tasks>
                    <echo message="updating activiti configuration to db ${database}" />
                    <copy file="target/test-classes/camunda.cfg.db.xml" tofile="target/test-classes/camunda.cfg.xml" overwrite="true">
                      <filterset filtersfile="${db.properties.file}" />
                    </copy>

                    <echo message="dropping schema in ${database}" />
                    <java classname="org.camunda.bpm.engine.impl.db.DbSchemaDrop" classpathref="maven.test.classpath" />
                  </tasks>
                </configuration>
              </execution>
              <execution>
                <id>database-test-drop-schema</id>
                <phase>prepare-package</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <tasks>
                    <echo message="dropping schema in ${database}" />
                    <java classname="org.camunda.bpm.engine.impl.db.DbSchemaDrop" classpathref="maven.test.classpath" />
                  </tasks>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>oracle</id>
      <activation>
        <property>
          <name>database</name>
          <value>oracle</value>
        </property>
      </activation>
      <dependencies>
        <dependency>
          <groupId>com.oracle.jdbc</groupId>
          <artifactId>ojdbc6</artifactId>
          <scope>test</scope>
        </dependency>
      </dependencies>
    </profile>

    <profile>
      <id>oracle10g</id>
      <activation>
        <property>
          <name>database</name>
          <value>oracle10g</value>
        </property>
      </activation>
      <dependencies>
        <dependency>
          <groupId>com.oracle.jdbc</groupId>
          <artifactId>ojdbc14</artifactId>
          <scope>test</scope>
        </dependency>
      </dependencies>
    </profile>

    <profile>
      <id>db2</id>
      <activation>
        <property>
          <name>database</name>
          <value>db2</value>
        </property>
      </activation>
      <dependencies>
        <dependency>
          <groupId>com.ibm.db2.jcc</groupId>
          <artifactId>db2jcc4</artifactId>
          <scope>test</scope>
        </dependency>
      </dependencies>
    </profile>

    <profile>
      <id>mssql</id>
        <activation>
          <property>
            <name>database</name>
            <value>mssql</value>
          </property>
        </activation>
        <dependencies>
          <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>sqljdbc4</artifactId>
            <scope>test</scope>
          </dependency>
       </dependencies>
    </profile>

    <profile>
      <id>mssql12</id>
        <activation>
          <property>
            <name>database</name>
            <value>mssql12</value>
          </property>
        </activation>
        <dependencies>
          <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>sqljdbc4</artifactId>
            <scope>test</scope>
          </dependency>
       </dependencies>
    </profile>

    <profile>
      <id>mysql</id>
        <activation>
          <property>
            <name>database</name>
            <value>mysql</value>
          </property>
        </activation>
        <dependencies>
          <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>test</scope>
          </dependency>
       </dependencies>
    </profile>

    <profile>
      <id>postgresql</id>
        <activation>
        <property>
          <name>database</name>
          <value>postgresql</value>
        </property>
      </activation>
      <dependencies>
        <dependency>
          <groupId>org.postgresql</groupId>
          <artifactId>postgresql</artifactId>
          <scope>test</scope>
        </dependency>
       </dependencies>
    </profile>

    <profile>
      <id>postgresql93</id>
        <activation>
        <property>
          <name>database</name>
          <value>postgresql93</value>
        </property>
      </activation>
      <dependencies>
        <dependency>
          <groupId>org.postgresql</groupId>
          <artifactId>postgresql</artifactId>
          <scope>test</scope>
        </dependency>
       </dependencies>
    </profile>

    <!-- profile for running cockpit testsuite with database table prefix -->
    <profile>
      <id>db-table-prefix</id>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <!--
              only worked with this version, there might be a bug with antrun
              see http://jira.codehaus.org/browse/MANTRUN-109
            -->
            <version>1.4</version>
            <executions>
              <execution>
                <id>database-test-create-schema</id>
                <phase>process-test-classes</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <tasks>
                    <copy file="target/test-classes/camunda.cfg.prefix.xml" tofile="target/test-classes/camunda.cfg.xml" overwrite="true" />
                  </tasks>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

  </profiles>
</project>
