<?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">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.exoplatform.ecms</groupId>
    <artifactId>exo-ecms-delivery-dms-wcm</artifactId>
    <version>2.3.5-SNAPSHOT</version>
  </parent>
  <artifactId>exo-ecms-delivery-dms-wcm-assembly</artifactId>
  <packaging>pom</packaging>
  <name>eXo DMS Assemblies</name>
  <properties>
    <gatein.working.dir>${basedir}/target</gatein.working.dir>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.exoplatform.tool</groupId>
      <artifactId>exopackage</artifactId>
      <version>${org.exoplatform.exopackage.version}</version>
      <type>zip</type>
    </dependency>
    <dependency>
      <groupId>org.exoplatform.kernel</groupId>
      <artifactId>kernel.packaging.module</artifactId>
      <version>${org.exoplatform.kernel.version}</version>
      <type>js</type>
    </dependency>
    <dependency>
      <groupId>org.exoplatform.core</groupId>
      <artifactId>core.packaging.module</artifactId>
      <version>${org.exoplatform.core.version}</version>
      <type>js</type>
    </dependency>
    <dependency>
      <groupId>org.exoplatform.ws</groupId>
      <artifactId>ws.packaging.module</artifactId>
      <version>${org.exoplatform.ws.version}</version>
      <type>js</type>
    </dependency>
    <dependency>
      <groupId>org.exoplatform.jcr</groupId>
      <artifactId>jcr.packaging.module</artifactId>
      <version>${org.exoplatform.jcr.version}</version>
      <type>js</type>
    </dependency>
    <dependency>
      <groupId>org.exoplatform.portal</groupId>
      <artifactId>portal.packaging.module</artifactId>
      <version>${org.exoplatform.portal.version}</version>
      <type>js</type>
    </dependency>
    <dependency>
      <groupId>org.exoplatform.ecms</groupId>
      <artifactId>dms.packaging.module</artifactId>
      <version>${project.version}</version>
      <type>js</type>
    </dependency>
    <dependency>
      <groupId>org.exoplatform.ecms</groupId>
      <artifactId>dms.packaging.product</artifactId>
      <version>${project.version}</version>
      <type>js</type>
    </dependency>
    <dependency>
      <groupId>org.exoplatform.ecms</groupId>
      <artifactId>exo-ecms-packaging-ecmdemo-webapp</artifactId>
      <version>${project.version}</version>
      <type>war</type>
    </dependency>
    <dependency>
      <groupId>org.exoplatform.ecms</groupId>
      <artifactId>exo-ecms-core-webapp</artifactId>
      <version>${project.version}</version>
      <type>war</type>
    </dependency>
    <dependency>
      <groupId>org.exoplatform.ecms</groupId>
      <artifactId>exo-ecms-packaging-ecmdemo-config</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.exoplatform.ecms</groupId>
      <artifactId>exo-ecms-packaging-ecmdemo-rest-webapp</artifactId>
      <version>${project.version}</version>
      <type>war</type>
    </dependency>
    <dependency>
      <groupId>org.exoplatform.ecms</groupId>
      <artifactId>exo-ecms-packaging-wcm-webapp</artifactId>
      <version>${project.version}</version>
      <type>war</type>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <!-- needed for exobuild to call maven dependency:get -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <configuration>
          <repositoryUrl>http://repository.exoplatform.org/all</repositoryUrl>
        </configuration>
      </plugin>
      <!-- check-out exobuild -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>unpack-dependencies</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <overWriteSnapshots>true</overWriteSnapshots>
              <artifactItems>
                <artifactItem>
                  <groupId>org.exoplatform.tool</groupId>
                  <artifactId>exopackage</artifactId>
                  <type>zip</type>
                  <outputDirectory>target/exopackage</outputDirectory>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
          <execution>
            <id>copy-dependencies</id>
            <phase>compile</phase>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
            <configuration>
              <includeTypes>js</includeTypes>
              <stripVersion>true</stripVersion>
              <outputDirectory>${project.build.directory}/exopackage-conf</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <id>pkg-tomcat</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <finalName>eXoDMS-${project.version}</finalName>
        <plugins>
          <!-- Ensure your environment is correctly setup -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-enforcer-plugin</artifactId>
            <executions>
              <execution>
                <id>tomcat-check-environment-ready</id>
                <goals>
                  <goal>enforce</goal>
                </goals>
                <configuration>
                  <rules>
                    <requireProperty>
                      <property>exo.projects.directory.dependencies</property>
                      <message>"You must define the property exo.projects.directory.dependencies to give the path to the directory where you store your applications servers"</message>
                    </requireProperty>
                    <requireProperty>
                      <property>exo.projects.app.tomcat.version</property>
                      <message>"You must define the property exo.projects.app.tomcat.version to give the name of the directory where is stored tomcat"</message>
                    </requireProperty>
                    <requireFilesExist>
                      <files>
                        <file>${exo.projects.directory.dependencies}/${exo.projects.app.tomcat.version}/</file>
                      </files>
                      <message>"The following Tomcat directory doesn't exist : ${exo.projects.directory.dependencies}/${exo.projects.app.tomcat.version}"</message>
                    </requireFilesExist>
                  </rules>
                  <fail>true</fail>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <!-- run exo build -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>tomcat-exopackage</id>
                <phase>package</phase>
                <configuration>
                  <executable>java</executable>
                  <workingDirectory>${basedir}</workingDirectory>
                  <arguments>
                    <argument>-Dexo.package.home=${basedir}/target/exopackage</argument>
                    <argument>-Dexo.current.dir=${basedir}</argument>
                    <argument>-Dexo.base.dir=${exo.projects.directory.base}</argument>
                    <argument>-Dexo.conf.dir=${basedir}/target/exopackage-conf</argument>
                    <argument>-Dexo.working.dir=${gatein.working.dir}</argument>
                    <!--argument>-Dexo.src.dir=NONE</argument-->
                    <argument>-Dexo.dep.dir=${exo.projects.directory.dependencies}</argument>
                    <!-- to get the server ref install -->
                    <argument>-Dexo.m2.repos=file:${settings.localRepository},http://repository.exoplatform.org/all</argument>
                    <argument>-Dclean.server=${exo.projects.app.tomcat.version}</argument>
                    <argument>-Dexo.m2.home=${maven.home}</argument>
                    <argument>-Dorg.exoplatform.portal.version=${org.exoplatform.portal.version}</argument>
                    <argument>-Xshare:auto</argument>
                    <argument>-Xms64m</argument>
                    <argument>-Xmx1024m</argument>
                    <argument>-XX:MaxPermSize=512m</argument>
                    <argument>-classpath</argument>
                    <argument>${basedir}/target/exopackage/lib/js.jar</argument>
                    <argument>org.mozilla.javascript.tools.shell.Main</argument>
                    <argument>${basedir}/target/exopackage/javascript/eXo/eXo.js</argument>
                    <argument>exobuild</argument>
                    <argument>--product=dms</argument>
                    <argument>--deploy=tomcat</argument>
                  </arguments>
                </configuration>
                <goals>
                  <goal>exec</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>arc-tomcat</id>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
              <execution>
                <id>tomcat-assembly</id>
                <phase>package</phase>
                <goals>
                  <goal>single</goal>
                </goals>
                <configuration>
                  <descriptors>
                    <descriptor>src/main/assembly/tomcat-zip.xml</descriptor>
                  </descriptors>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
