<?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.platform</groupId>
    <artifactId>exo.platform.packaging</artifactId>
    <version>3.0.10</version>
  </parent>
  <artifactId>exo.platform.packaging.jboss</artifactId>
  <packaging>pom</packaging>
  <name>eXo Platform - Packaging JBoss</name>

<profiles>
  <profile>
  <id>pkg-jboss</id>

  <dependencies>
    <dependency>
		<groupId>org.exoplatform.platform</groupId>
		<artifactId>exo.platform.packaging.jbosseap</artifactId>
		<version>${project.version}</version>
        <type>zip</type>
        <classifier>ears</classifier>
    </dependency>
  </dependencies>

  <build>
    <finalName>Platform-${project.version}-JBoss</finalName>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <executions>
          <execution>
            <id>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.jbosseap.version</property>
                  <message>You must define the property exo.projects.app.jbosseap.version to give
                           the name of the directory where is stored JBoss EAP</message>
                </requireProperty>
                <requireFilesExist>
                  <files>
                    <file>${exo.projects.directory.dependencies}/${exo.projects.app.jbosseap.version}/</file>
                  </files>
                  <message>The following JBoss EAP directory doesn't exist :
                           ${exo.projects.directory.dependencies}/${exo.projects.app.jbosseap.version}</message>
                </requireFilesExist>
              </rules>
              <fail>true</fail>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <!-- JBoss Packaging -->
      <!-- Copy the reference JBoss EAP to target -->
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.4.3</version>
        <executions>
          <execution>
            <id>01-copy-jbosseap-package</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.directory}/jbosseap</outputDirectory>
              <includeEmptyDirs>true</includeEmptyDirs>
              <resources>
                <resource>
                  <directory>${exo.projects.directory.dependencies}/${exo.projects.app.jbosseap.version}/</directory>
                  <filtering>false</filtering>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <!-- Extract the EARs package -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
             <id>02-unpack-jbosseap-ears</id>
             <phase>prepare-package</phase>
             <goals>
               <goal>unpack</goal>
             </goals>
             <configuration>
               <outputDirectory>${project.build.directory}/jbosseap</outputDirectory>
               <artifactItems>
				<artifactItem>
					<groupId>org.exoplatform.platform</groupId>
					<artifactId>exo.platform.packaging.jbosseap</artifactId>
					<version>${project.version}</version>
					<type>zip</type>
					<classifier>ears</classifier>
				</artifactItem>
               </artifactItems>
             </configuration>
           </execution>
        </executions>
      </plugin>
          <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
              <execution>
                <id>03-jbosseap-assembly</id>
                <phase>package</phase>
                <goals>
                  <goal>single</goal>
                </goals>
                <configuration>
                  <descriptors>
                    <descriptor>src/main/assembly/jboss-archive.xml</descriptor>
                  </descriptors>
                </configuration>
              </execution>
            </executions>
          </plugin>
    </plugins>
  </build>
    </profile>
  </profiles>
</project>
